module MovieDB::Relation::QueryMethods
Public Instance Methods
fetch(*ids, expire: 1800)
click to toggle source
Fetch data from IMDb. Default expiration time for stored object in redis is 1800 seconds. You can set this value to what ever you like.
Example:
m = MovieDB::Movie.new m.fetch("0369324", "0369662", expire: 84600)
# File lib/movieDB/relation/query_methods.rb, line 22 def fetch(*ids, expire: 1800) store_data(ids_to_array(ids), expire) # Collect all fetched data and assign to global variable arr = [] ids.each do |id| arr << (hgetall(id)) end $movie_data = arr end
fetch_data(method, ids = nil)
click to toggle source
# File lib/movieDB/relation/query_methods.rb, line 109 def fetch_data(method, ids = nil) if ids.nil? MovieDB::DataStore.get_data(method) else ids.each do |id| MovieDB::DataStore.get_data(method, id) end end end
movie_exists?(id)
click to toggle source
# File lib/movieDB/relation/query_methods.rb, line 74 def movie_exists?(id) !hgetall(id).empty? end
mset(record, id, expire)
click to toggle source
# File lib/movieDB/relation/query_methods.rb, line 70 def mset(record, id, expire) MovieDB::DataStore.write_data(imdb_tmdb: record, id: id, expire: expire) end
store_data(ids, expire)
click to toggle source
# File lib/movieDB/relation/query_methods.rb, line 35 def store_data(ids, expire) check_rate_limit(ids) ids.each do |id| movie_exists?(id) ? true : imdb_tmdb_lookup(id, expire) end end
Private Instance Methods
check_rate_limit(ids)
click to toggle source
IMDb current limits are 40 requests every 10 seconds and are limited by IP address, not API key.
# File lib/movieDB/relation/query_methods.rb, line 129 def check_rate_limit(ids) if ids.length >= 40 MovieDB::Support::Reporting.warn(<<-MSG.strip!) Reduce the amount of IMDb ids. \nYou have exceeded the rate limit. MSG else MovieDB::Support::Reporting.silenced end end