Class: MyJohnDeereApi::Consumer

Inherits:
Object
  • Object
show all
Includes:
Helpers::CaseConversion, Helpers::EnvironmentHelper
Defined in:
lib/my_john_deere_api/consumer.rb

Constant Summary collapse

URLS =

valid API urls

{
  sandbox: 'https://sandboxapi.deere.com',
  live: 'https://api.soa-proxy.deere.com',
}
DEFAULTS =
{
  environment: :live
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  options = DEFAULTS.merge(options)

  @api_key = api_key
  @api_secret = api_secret

  self.environment = options[:environment]
  @base_url = options[:base_url] || URLS[@environment]
end

Instance Attribute Details

#api_keyObject (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_secretObject (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

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/my_john_deere_api/consumer.rb', line 6

def base_url
  @base_url
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/my_john_deere_api/consumer.rb', line 6

def environment
  @environment
end

Instance Method Details

#app_getObject

oAuth Consumer which uses just the base url, for app-wide, non user-specific GET requests.



32
33
34
# File 'lib/my_john_deere_api/consumer.rb', line 32

def app_get
  @app_get ||= consumer(base_url)
end

#user_getObject

oAuth Consumer which uses the proper url for user-specific GET requests.



39
40
41
# File 'lib/my_john_deere_api/consumer.rb', line 39

def user_get
  @user_get ||= consumer("#{base_url}/platform")
end