class RottenParty::Client

Public Class Methods

new(api_key, api_version='1.0', options={:query => { :country => 'uk' }}) click to toggle source

Initialize the client Options:

- :api_version (default: 1.0)
- :locale (default: en_UK)
# 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

Public Instance Methods

find_film_by_id(id, options={}) click to toggle source

Find a specific film by it’s identifier

# 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={}) click to toggle source

Find a film by it’s title

# 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={}) click to toggle source

list

> ‘box_office’

> ‘in_theaters’

> ‘opening’

> ‘upcoming’

directory

> ‘dvds’

> ‘movies’

# 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) click to toggle source
# 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