Class: Kubrick::Movie

Inherits:
NetflixAPI show all
Defined in:
lib/kubrick/movie.rb

Instance Method Summary collapse

Methods inherited from NetflixAPI

#initialize, #say_hello, #wheres_johnny

Constructor Details

This class inherits a constructor from Kubrick::NetflixAPI

Instance Method Details

#find_by_title(title) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kubrick/movie.rb', line 3

def find_by_title(title)
  headers_g = SimpleOAuth::Header.new(:get, "http://#{NETFLIX_API_ROOT}/catalog/titles", {'term' => CGI::escape(title)}, {:consumer_key => @oauth_consumer_key, :consumer_secret => @oauth_consumer_secret, :token => @oauth_token, :token_secret => @oauth_token_secret})
  headers = headers_g.signed_attributes
  request = @conn.get do |req|
    req.url '/catalog/titles'
    req.params['oauth_consumer_key'] = headers[:oauth_consumer_key]
    req.params['oauth_nonce'] = headers[:oauth_nonce]
    req.params['oauth_signature_method'] = headers[:oauth_signature_method]
    req.params['oauth_timestamp'] = headers[:oauth_timestamp]
    req.params['oauth_token'] = headers[:oauth_token]
    req.params['oauth_version'] = headers[:oauth_version]
    req.params['term'] = CGI::escape(title)
    req.params['oauth_signature'] = headers[:oauth_signature]
  end
  if request.status == 200
    response = Crack::XML.parse(request.body)
    response["catalog_titles"]["catalog_title"]
  else
    raise Kubrick::Errors::APIError.new "Movie.find_by_title: #{request.body}"
  end
end