class MyJohnDeereApi::Consumer
Constants
- DEFAULTS
- URLS
valid API urls
Attributes
api_key[R]
api_secret[R]
environment[R]
site[R]
Public Class Methods
new(api_key, api_secret, options={})
click to toggle source
# File lib/my_john_deere_api/consumer.rb, line 18 def initialize(api_key, api_secret, options={}) options = DEFAULTS.merge(options) @api_key = api_key @api_secret = api_secret self.environment = options[:environment] @site = options[:site] || URLS[@environment] end
Public Instance Methods
auth_client()
click to toggle source
oAuth client for user authentication
# 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_links[:authorization], token_url: authorization_links[:token], raise_errors: false, ) end
platform_client()
click to toggle source
oAuth client for platform requests
# 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
Private Instance Methods
headers()
click to toggle source
# File lib/my_john_deere_api/consumer.rb, line 93 def headers @headers ||= {accept: 'application/vnd.deere.axiom.v3+json'} end
keyify(key_name)
click to toggle source
# File lib/my_john_deere_api/consumer.rb, line 97 def keyify key_name underscore(key_name.gsub(/^oauth/, '')).to_sym end
scopes()
click to toggle source
# File lib/my_john_deere_api/consumer.rb, line 88 def scopes return @scopes if defined?(@scopes) @scopes = authorization['scopes_supported'] end