Class: MyJohnDeereApi::Authorize
- Inherits:
-
Object
- Object
- MyJohnDeereApi::Authorize
- Includes:
- Helpers::EnvironmentHelper
- Defined in:
- lib/my_john_deere_api/authorize.rb
Constant Summary collapse
- DEFAULTS =
{ environment: :live }
Instance Attribute Summary collapse
-
#access_secret ⇒ Object
readonly
Returns the value of attribute access_secret.
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request_secret ⇒ Object
readonly
Returns the value of attribute request_secret.
-
#request_token ⇒ Object
readonly
Returns the value of attribute request_token.
Instance Method Summary collapse
-
#authorize_url ⇒ Object
Url which may be used to obtain a verification code from the oauth server.
-
#consumer ⇒ Object
API consumer that makes non-user-specific GET requests.
-
#initialize(api_key, api_secret, options = {}) ⇒ Authorize
constructor
Create an Authorize object.
-
#verify(code, token = nil, secret = nil) ⇒ Object
Turn a verification code into access tokens.
Constructor Details
#initialize(api_key, api_secret, options = {}) ⇒ Authorize
Create an Authorize object.
This is used to obtain authentication an access key/secret on behalf of a user.
20 21 22 23 24 25 26 |
# File 'lib/my_john_deere_api/authorize.rb', line 20 def initialize(api_key, api_secret, = {}) @options = DEFAULTS.merge() @api_key = api_key @api_secret = api_secret self.environment = @options[:environment] end |
Instance Attribute Details
#access_secret ⇒ Object (readonly)
Returns the value of attribute access_secret.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def access_secret @access_secret end |
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def access_token @access_token end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def api_secret @api_secret end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def environment @environment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def @options end |
#request_secret ⇒ Object (readonly)
Returns the value of attribute request_secret.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def request_secret @request_secret end |
#request_token ⇒ Object (readonly)
Returns the value of attribute request_token.
5 6 7 |
# File 'lib/my_john_deere_api/authorize.rb', line 5 def request_token @request_token end |
Instance Method Details
#authorize_url ⇒ Object
Url which may be used to obtain a verification code from the oauth server.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/my_john_deere_api/authorize.rb', line 32 def return @authorize_url if defined?(@authorize_url) = .slice(:oauth_callback) requester = consumer.get_request_token() @request_token = requester.token @request_secret = requester.secret @authorize_url = requester.() end |
#consumer ⇒ Object
API consumer that makes non-user-specific GET requests
47 48 49 50 |
# File 'lib/my_john_deere_api/authorize.rb', line 47 def consumer return @consumer if defined?(@consumer) @consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment).app_get end |
#verify(code, token = nil, secret = nil) ⇒ Object
Turn a verification code into access tokens. If this is run from a separate process than the one that created the initial RequestToken, the request token/secret can be passed in.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/my_john_deere_api/authorize.rb', line 58 def verify(code, token=nil, secret=nil) token ||= request_token secret ||= request_secret requester = OAuth::RequestToken.new(consumer, token, secret) access_object = requester.get_access_token(oauth_verifier: code) @access_token = access_object.token @access_secret = access_object.secret nil end |