Class: Tmdb::Search
- Inherits:
-
Object
- Object
- Tmdb::Search
- Defined in:
- lib/themoviedb/search.rb
Instance Method Summary collapse
-
#fetch ⇒ Object
Sends back main data.
-
#fetch_response(conditions = {}) ⇒ Object
Send back whole response.
- #filter(conditions) ⇒ Object
-
#initialize(resource = nil) ⇒ Search
constructor
A new instance of Search.
- #primary_release_year(year) ⇒ Object
- #query(query) ⇒ Object
- #resource(resource) ⇒ Object
- #year(year) ⇒ Object
Constructor Details
#initialize(resource = nil) ⇒ Search
Returns a new instance of Search.
3 4 5 6 7 |
# File 'lib/themoviedb/search.rb', line 3 def initialize(resource = nil) @params = {} @resource = resource.nil? ? "/search/movie" : resource self end |
Instance Method Details
#fetch ⇒ Object
Sends back main data
61 62 63 |
# File 'lib/themoviedb/search.rb', line 61 def fetch fetch_response["results"] end |
#fetch_response(conditions = {}) ⇒ Object
Send back whole response
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/themoviedb/search.rb', line 66 def fetch_response(conditions = {}) if conditions[:external_source] = @params.merge(Api.config.merge({ external_source: conditions[:external_source] })) else = @params.merge(Api.config) end response = Api.get(@resource, query: ) original_etag = response.headers.fetch("etag", "") etag = original_etag.delete('"') Api.set_response("code" => response.code, "etag" => etag) response.to_hash end |
#filter(conditions) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/themoviedb/search.rb', line 48 def filter(conditions) if conditions conditions.each do |key, value| if respond_to?(key) send(key, value) else @params[key] = value end end end end |
#primary_release_year(year) ⇒ Object
19 20 21 22 |
# File 'lib/themoviedb/search.rb', line 19 def primary_release_year(year) @params[:primary_release_year] = year.to_s self end |
#query(query) ⇒ Object
9 10 11 12 |
# File 'lib/themoviedb/search.rb', line 9 def query(query) @params[:query] = query.to_s self end |
#resource(resource) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/themoviedb/search.rb', line 24 def resource(resource) @resource = case resource when "movie" "/search/movie" when "collection" "/search/collection" when "tv" "/search/tv" when "person" "/search/person" when "list" "/search/list" when "company" "/search/company" when "keyword" "/search/keyword" when "multi" "/search/multi" when "find" "/find" end self end |
#year(year) ⇒ Object
14 15 16 17 |
# File 'lib/themoviedb/search.rb', line 14 def year(year) @params[:year] = year.to_s self end |