Class: Tmdb::Search
- Inherits:
-
Object
- Object
- Tmdb::Search
- Defined in:
- lib/themoviedb-jzg/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_realease_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-jzg/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
59 60 61 |
# File 'lib/themoviedb-jzg/search.rb', line 59 def fetch fetch_response.results end |
#fetch_response(conditions = {}) ⇒ Object
Send back whole response
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/themoviedb-jzg/search.rb', line 64 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.gsub(/"/, '') Api.set_response({'code' => response.code, 'etag' => etag}) return response.to_hash.to_hashugar end |
#filter(conditions) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/themoviedb-jzg/search.rb', line 46 def filter(conditions) if conditions conditions.each do |key, value| if self.respond_to?(key) self.send(key, value) else @params[key] = value end end end end |
#primary_realease_year(year) ⇒ Object
19 20 21 22 |
# File 'lib/themoviedb-jzg/search.rb', line 19 def primary_realease_year(year) @params[:primary_release_year] = "#{year}" self end |
#query(query) ⇒ Object
9 10 11 12 |
# File 'lib/themoviedb-jzg/search.rb', line 9 def query(query) @params[:query] = "#{query}" 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 |
# File 'lib/themoviedb-jzg/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 'find' '/find' end self end |
#year(year) ⇒ Object
14 15 16 17 |
# File 'lib/themoviedb-jzg/search.rb', line 14 def year(year) @params[:year] = "#{year}" self end |