Class: MyJohnDeereApi::Consumer
- Inherits:
-
Object
- Object
- MyJohnDeereApi::Consumer
- Defined in:
- lib/my_john_deere_api/consumer.rb
Constant Summary collapse
- URLS =
valid API urls
{ sandbox: 'https://sandboxapi.deere.com', live: 'https://partnerapi.deere.com', }
- DEFAULTS =
{ environment: :live }
Instance Attribute Summary collapse
-
#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.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#auth_client ⇒ Object
oAuth client for user authentication.
-
#initialize(api_key, api_secret, options = {}) ⇒ Consumer
constructor
A new instance of Consumer.
-
#platform_client ⇒ Object
oAuth client for platform requests.
Constructor Details
#initialize(api_key, api_secret, options = {}) ⇒ Consumer
Returns a new instance of Consumer.
18 19 20 21 22 23 24 25 26 |
# File 'lib/my_john_deere_api/consumer.rb', line 18 def initialize(api_key, api_secret, ={}) = DEFAULTS.merge() @api_key = api_key @api_secret = api_secret self.environment = [:environment] @site = [:site] || URLS[@environment] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/my_john_deere_api/consumer.rb', line 6 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
6 7 8 |
# File 'lib/my_john_deere_api/consumer.rb', line 6 def api_secret @api_secret end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/my_john_deere_api/consumer.rb', line 6 def environment @environment end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
6 7 8 |
# File 'lib/my_john_deere_api/consumer.rb', line 6 def site @site end |
Instance Method Details
#auth_client ⇒ Object
oAuth client for user authentication
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/my_john_deere_api/consumer.rb', line 46 def auth_client return @auth_client if defined?(@auth_client) # We build this without the `client` method because the authorization links # require an extra API call to JD that is only needed for authorization. @auth_client = OAuth2::Client.new( api_key, api_secret, site: site, authorize_url: [:authorization], token_url: [:token], raise_errors: false, ) end |
#platform_client ⇒ Object
oAuth client for platform requests
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/my_john_deere_api/consumer.rb', line 31 def platform_client return @platform_client if defined?(@platform_client) @platform_client = OAuth2::Client.new( api_key, api_secret, site: site, headers: headers, raise_errors: false, ) end |