Class: RottenParty::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/rotten-party/client.rb

Instance Method Summary collapse

Methods included from HTTParty::Icebox

included

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', options={:query => { :country => 'uk' }})
  self.class.base_uri "api.rottentomatoes.com/api/public/v#{api_version}"

  options.merge!({:query => {:apikey => api_key}})
  @global_options = 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, options={})
  options = recurse_merge(options, @global_options)
  response = self.class.get("/movies/#{id}.json", options).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, options={})
  options = recurse_merge(options, @global_options)
  options = recurse_merge(options, {:query => {:q => u(title)}})
  response = self.class.get("/movies.json", options).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, options={})
  options = recurse_merge(options, @global_options)
  response = self.class.get("/lists/#{directory}/#{list}.json", options).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