Class: NetFlix::Authenticator

Inherits:
Valuable
  • Object
show all
Defined in:
lib/net_flix/authenticator.rb

Instance Method Summary collapse

Methods inherited from Valuable

#attributes, attributes, create_accessor_for, create_setter_for, #deep_duplicate_of, defaults, has_collection, has_value, #initialize

Constructor Details

This class inherits a constructor from Valuable

Instance Method Details

#access_tokenObject



8
9
10
# File 'lib/net_flix/authenticator.rb', line 8

def access_token
  credentials.access_token
end

#add_authentication_parameters!Object



55
56
57
# File 'lib/net_flix/authenticator.rb', line 55

def add_authentication_parameters!
  request.parameters.merge!(authentication_parameters)
end

#add_signature!Object



59
60
61
62
# File 'lib/net_flix/authenticator.rb', line 59

def add_signature!
  sign = {'oauth_signature' => Request.encode(signature)}
  request.parameters.merge!( sign  )
end

#authentication_parametersObject



45
46
47
48
49
50
51
52
53
# File 'lib/net_flix/authenticator.rb', line 45

def authentication_parameters
  {
  'oauth_consumer_key' => key,
  'oauth_signature_method' => 'HMAC-SHA1',
  'oauth_timestamp' => timestamp,
  'oauth_nonce' => nonce,
  'oauth_version' => '1.0'
  }
end

#encoded_parametersObject



70
71
72
# File 'lib/net_flix/authenticator.rb', line 70

def encoded_parameters
  Request.encode request.parameter_string
end

#encoded_urlObject



74
75
76
# File 'lib/net_flix/authenticator.rb', line 74

def encoded_url
  Request.encode request.url
end

#keyObject



20
21
22
# File 'lib/net_flix/authenticator.rb', line 20

def key
  credentials.key
end

#require_credentialsObject

Raises:

  • (ArgumentError)


28
29
30
# File 'lib/net_flix/authenticator.rb', line 28

def require_credentials
  raise( ArgumentError, "You must configure your NetFlix API key and secret before using flix4r.") unless credentials.valid?
end

#secretObject



24
25
26
# File 'lib/net_flix/authenticator.rb', line 24

def secret
  credentials.secret
end

#sign!Object



64
65
66
67
68
# File 'lib/net_flix/authenticator.rb', line 64

def sign!
  require_credentials
  add_authentication_parameters!
  add_signature!
end

#signatureObject



41
42
43
# File 'lib/net_flix/authenticator.rb', line 41

def signature
  Base64.encode64(HMAC::SHA1.digest(signature_key,signature_base_string)).chomp.gsub(/\n/,'')
end

#signature_base_stringObject



32
33
34
35
# File 'lib/net_flix/authenticator.rb', line 32

def signature_base_string
  add_authentication_parameters!
  [request.http_method, encoded_url, encoded_parameters].join('&') 
end

#signature_keyObject



37
38
39
# File 'lib/net_flix/authenticator.rb', line 37

def signature_key
  "#{Request.encode(secret)}&#{Request.encode(access_token)}"
end

#timestampObject



16
17
18
# File 'lib/net_flix/authenticator.rb', line 16

def timestamp 
  @timestamp ||= Time.now.to_i
end

#timestamp=(stamp) ⇒ Object



12
13
14
# File 'lib/net_flix/authenticator.rb', line 12

def timestamp=stamp
  @timestamp=stamp
end