Class: Kubrick::Authenticator
- Inherits:
-
Object
- Object
- Kubrick::Authenticator
- Defined in:
- lib/kubrick/authenticator.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #get_access_token(oauth_values = {}) ⇒ Object
- #get_request_token ⇒ Object
-
#initialize(key, secret) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #login_url(oauth_values = {}, callback_url) ⇒ Object
Constructor Details
#initialize(key, secret) ⇒ Authenticator
Returns a new instance of Authenticator.
5 6 7 8 9 10 11 |
# File 'lib/kubrick/authenticator.rb', line 5 def initialize(key, secret) @key = key @secret = secret @conn = Faraday.new(:url => "http://#{NETFLIX_API_ROOT}") do |builder| builder.adapter :net_http end end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/kubrick/authenticator.rb', line 3 def key @key end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
3 4 5 |
# File 'lib/kubrick/authenticator.rb', line 3 def secret @secret end |
Instance Method Details
#get_access_token(oauth_values = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kubrick/authenticator.rb', line 42 def get_access_token(oauth_values = {}) headers_g = SimpleOAuth::Header.new(:get, "http://#{NETFLIX_API_ROOT}/oauth/access_token", nil, {:consumer_key => @key, :token => oauth_values[:oauth_token], :consumer_secret => @secret, :token_secret => oauth_values[:oauth_token_secret]}) headers = headers_g.signed_attributes request = @conn.get do |req| req.url '/oauth/access_token' 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['oauth_signature'] = headers[:oauth_signature] end if request.status == 200 step1 = request.body.split("&") processed_response = {} for item in step1 q = item.split("=") processed_response[:"#{q[0]}"] = CGI::unescape(q[1]) end processed_response else raise Kubrick::Errors::AuthenticatorError.new "get_access_token: #{request.body}" end end |
#get_request_token ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kubrick/authenticator.rb', line 13 def get_request_token headers_g = SimpleOAuth::Header.new(:get, "http://#{NETFLIX_API_ROOT}/oauth/request_token", nil, {:consumer_key => @key, :consumer_secret => @secret}) headers = headers_g.signed_attributes request = @conn.get do |req| req.url '/oauth/request_token' 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_version'] = headers[:oauth_version] req.params['oauth_signature'] = headers[:oauth_signature] end if request.status == 200 step1 = request.body.split("&") processed_response = {} for item in step1 q = item.split("=") processed_response[:"#{q[0]}"] = CGI::unescape(q[1]) end processed_response else raise Kubrick::Errors::AuthenticatorError.new "get_request_token: #{request.body}" end end |
#login_url(oauth_values = {}, callback_url) ⇒ Object
38 39 40 |
# File 'lib/kubrick/authenticator.rb', line 38 def login_url(oauth_values = {}, callback_url) "https://api-user.netflix.com/oauth/login?oauth_token=#{oauth_values[:oauth_token]}&oauth_consumer_key=#{@key}&application_name=#{oauth_values[:application_name]}&oauth_callback=#{CGI::escape(callback_url)}" end |