Class: RottenParty::Client
- Inherits:
-
Object
- Object
- RottenParty::Client
- Includes:
- HTTParty, HTTParty::Icebox
- Defined in:
- lib/rotten-party/client.rb
Instance Method Summary collapse
-
#find_film_by_id(id, options = {}) ⇒ Object
Find a specific film by it’s identifier.
-
#find_film_by_title(title, options = {}) ⇒ Object
Find a film by it’s title.
-
#find_movies_in_list(list, directory, options = {}) ⇒ Object
list => ‘box_office’ => ‘in_theaters’ => ‘opening’ => ‘upcoming’.
-
#initialize(api_key, api_version = '1.0', options = {:query => { :country => 'uk' }}) ⇒ Client
constructor
Initialize the client Options: - :api_version (default: 1.0) - :locale (default: en_UK).
- #recurse_merge(a, b) ⇒ Object
Methods included from HTTParty::Icebox
Constructor Details
#initialize(api_key, api_version = '1.0', options = {:query => { :country => 'uk' }}) ⇒ Client
Initialize the client Options:
- :api_version (default: 1.0)
- :locale (default: en_UK)
19 20 21 22 23 24 |
# File 'lib/rotten-party/client.rb', line 19 def initialize(api_key, api_version='1.0', ={:query => { :country => 'uk' }}) self.class.base_uri "api.rottentomatoes.com/api/public/v#{api_version}" .merge!({:query => {:apikey => api_key}}) @global_options = end |
Instance Method Details
#find_film_by_id(id, options = {}) ⇒ Object
Find a specific film by it’s identifier
27 28 29 30 31 |
# File 'lib/rotten-party/client.rb', line 27 def find_film_by_id(id, ={}) = recurse_merge(, @global_options) response = self.class.get("/movies/#{id}.json", ).parsed_response Hashie::Mash.new(response) end |
#find_film_by_title(title, options = {}) ⇒ Object
Find a film by it’s title
34 35 36 37 38 39 |
# File 'lib/rotten-party/client.rb', line 34 def find_film_by_title(title, ={}) = recurse_merge(, @global_options) = recurse_merge(, {:query => {:q => u(title)}}) response = self.class.get("/movies.json", ).parsed_response Hashie::Mash.new(response["movies"].first) end |
#find_movies_in_list(list, directory, options = {}) ⇒ Object
list
> ‘box_office’
> ‘in_theaters’
> ‘opening’
> ‘upcoming’
directory
> ‘dvds’
> ‘movies’
50 51 52 53 54 |
# File 'lib/rotten-party/client.rb', line 50 def find_movies_in_list(list, directory, ={}) = recurse_merge(, @global_options) response = self.class.get("/lists/#{directory}/#{list}.json", ).parsed_response response["movies"].collect{ |movie| Hashie::Mash.new(movie) } end |
#recurse_merge(a, b) ⇒ Object
56 57 58 59 60 |
# File 'lib/rotten-party/client.rb', line 56 def recurse_merge(a,b) a.merge(b) do |_,x,y| (x.is_a?(Hash) && y.is_a?(Hash)) ? recurse_merge(x,y) : [*x,*y] end end |