my_john_deere_api 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my_john_deere_api/authorize.rb +67 -73
- data/lib/my_john_deere_api/client.rb +89 -92
- data/lib/my_john_deere_api/consumer.rb +1 -8
- data/lib/my_john_deere_api/errors/unsupported_environment_error.rb +18 -0
- data/lib/my_john_deere_api/errors.rb +1 -0
- data/lib/my_john_deere_api/helpers/environment_helper.rb +25 -0
- data/lib/my_john_deere_api/helpers.rb +1 -0
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/authorize_test.rb +1 -29
- data/test/lib/my_john_deere_api/client_test.rb +1 -22
- data/test/lib/my_john_deere_api/consumer_test.rb +1 -33
- data/test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb +18 -0
- data/test/lib/my_john_deere_api/errors_test.rb +4 -0
- data/test/lib/my_john_deere_api/helpers/environment_helper_test.rb +67 -0
- data/test/lib/my_john_deere_api/helpers_test.rb +4 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b47734d5e6b4ad385e8ab7a23f2335da7a55cd615e9b893e7a01d32594cedf
|
4
|
+
data.tar.gz: 409d9106defce29a80ef99b98bb958cada379df66c4e01a1c81d44d47b2e96fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d0133e30516d2a70e9fbd466ed74b2a6aefc8dbcbf69cd84cf935742e682d4077571db4839bcfd49ee2a707f901bfa87012b3c49e07f5d3176a36f7277de490
|
7
|
+
data.tar.gz: e3e87c29522b6e70fca48b612ac13a19d78abcfc9c27f2f755f8a601630f336092dc325f932b98db7985755f931a6d1041fb9df6a437e58c6aba6c0bb7c67183
|
@@ -1,75 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
##
|
69
|
-
# intelligently sets the environment
|
70
|
-
|
71
|
-
def environment=(value)
|
72
|
-
value = value.to_sym
|
73
|
-
@environment = value == :production ? :live : value
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Authorize
|
3
|
+
include Helpers::EnvironmentHelper
|
4
|
+
|
5
|
+
attr_reader :api_key, :api_secret,
|
6
|
+
:request_token, :request_secret,
|
7
|
+
:access_token, :access_secret,
|
8
|
+
:environment, :options
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
environment: :live
|
12
|
+
}
|
13
|
+
|
14
|
+
##
|
15
|
+
# Create an Authorize object.
|
16
|
+
#
|
17
|
+
# This is used to obtain authentication an access key/secret
|
18
|
+
# on behalf of a user.
|
19
|
+
|
20
|
+
def initialize(api_key, api_secret, options = {})
|
21
|
+
@options = DEFAULTS.merge(options)
|
22
|
+
|
23
|
+
@api_key = api_key
|
24
|
+
@api_secret = api_secret
|
25
|
+
self.environment = @options[:environment]
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Option a url which may be used to obtain a verification
|
30
|
+
# code from the oauth server.
|
31
|
+
|
32
|
+
def authorize_url
|
33
|
+
return @authorize_url if defined?(@authorize_url)
|
34
|
+
|
35
|
+
request_options = options.slice(:oauth_callback)
|
36
|
+
|
37
|
+
requester = consumer.get_request_token(request_options)
|
38
|
+
@request_token = requester.token
|
39
|
+
@request_secret = requester.secret
|
40
|
+
|
41
|
+
@authorize_url = requester.authorize_url(request_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# API consumer that makes non-user-specific GET requests
|
46
|
+
|
47
|
+
def consumer
|
48
|
+
return @consumer if defined?(@consumer)
|
49
|
+
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment).app_get
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Turn a verification code into access tokens. If this is
|
54
|
+
# run from a separate process than the one that created
|
55
|
+
# the initial RequestToken, the request token/secret
|
56
|
+
# can be passed in.
|
57
|
+
|
58
|
+
def verify(code, token=nil, secret=nil)
|
59
|
+
token ||= request_token
|
60
|
+
secret ||= request_secret
|
61
|
+
|
62
|
+
requester = OAuth::RequestToken.new(consumer, token, secret)
|
63
|
+
access_object = requester.get_access_token(oauth_verifier: code)
|
64
|
+
@access_token = access_object.token
|
65
|
+
@access_secret = access_object.secret
|
66
|
+
nil
|
67
|
+
end
|
74
68
|
end
|
75
69
|
end
|
@@ -1,115 +1,112 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Client
|
3
|
+
include Helpers::EnvironmentHelper
|
4
|
+
|
5
|
+
attr_reader :api_key, :api_secret, :access_token, :access_secret, :environment
|
6
|
+
|
7
|
+
DEFAULTS = {
|
8
|
+
environment: :live
|
9
|
+
}
|
10
|
+
|
11
|
+
##
|
12
|
+
# Creates the client with everthing it needs to perform API requests.
|
13
|
+
# User-specific credentials are optional, but user-specific API
|
14
|
+
# requests are only possible if they are supplied.
|
15
|
+
#
|
16
|
+
# options:
|
17
|
+
#
|
18
|
+
# [:environment] :sandbox or :live
|
19
|
+
#
|
20
|
+
# [:access] an array with two elements, the access_token
|
21
|
+
# and the access_secret of the given user
|
22
|
+
|
23
|
+
def initialize(api_key, api_secret, options = {})
|
24
|
+
options = DEFAULTS.merge(options)
|
25
|
+
|
26
|
+
@api_key = api_key
|
27
|
+
@api_secret = api_secret
|
28
|
+
|
29
|
+
if options.has_key?(:access) && options[:access].is_a?(Array)
|
30
|
+
@access_token, @access_secret = options[:access]
|
31
|
+
end
|
32
|
+
|
33
|
+
self.environment = options[:environment]
|
28
34
|
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
##
|
34
|
-
# generic user-specific GET request method that returns JSON
|
35
|
-
|
36
|
-
def get resource
|
37
|
-
resource = resource.to_s
|
38
|
-
resource = "/#{resource}" unless resource =~ /^\//
|
39
|
-
response = accessor.get(resource, headers)
|
40
|
-
|
41
|
-
JSON.parse(response.body)
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# generic user-specific POST request method that returns JSON
|
36
|
+
##
|
37
|
+
# generic user-specific GET request method that returns JSON
|
46
38
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
def get resource
|
40
|
+
resource = resource.to_s
|
41
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
42
|
+
response = accessor.get(resource, headers)
|
51
43
|
|
52
|
-
if response.body.size > 0
|
53
44
|
JSON.parse(response.body)
|
54
|
-
else
|
55
|
-
{}
|
56
45
|
end
|
57
|
-
end
|
58
46
|
|
59
|
-
|
60
|
-
|
47
|
+
##
|
48
|
+
# generic user-specific POST request method that returns JSON
|
61
49
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
def post resource, body
|
51
|
+
resource = resource.to_s
|
52
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
53
|
+
response = accessor.post(resource, body.to_json, post_headers)
|
66
54
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
if response.body.size > 0
|
56
|
+
JSON.parse(response.body)
|
57
|
+
else
|
58
|
+
{}
|
59
|
+
end
|
71
60
|
end
|
72
|
-
end
|
73
61
|
|
74
|
-
|
75
|
-
|
62
|
+
##
|
63
|
+
# generic user-specific DELETE request method
|
76
64
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
def delete resource
|
66
|
+
resource = resource.to_s
|
67
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
68
|
+
response = accessor.delete(resource, headers)
|
81
69
|
|
82
|
-
|
70
|
+
if response.body && response.body.size > 0
|
71
|
+
JSON.parse(response.body)
|
72
|
+
else
|
73
|
+
{}
|
74
|
+
end
|
75
|
+
end
|
83
76
|
|
84
|
-
|
85
|
-
|
77
|
+
##
|
78
|
+
# organizations associated with this access
|
86
79
|
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
def organizations
|
81
|
+
return @organizations if defined?(@organizations)
|
82
|
+
@organizations = MyJohnDeereApi::Request::Collection::Organizations.new(accessor).all
|
83
|
+
end
|
90
84
|
|
91
|
-
|
92
|
-
# Returns an oAuth consumer which can be used to build requests
|
85
|
+
private
|
93
86
|
|
94
|
-
|
95
|
-
|
96
|
-
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment)
|
97
|
-
end
|
87
|
+
##
|
88
|
+
# Returns an oAuth consumer which can be used to build requests
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
90
|
+
def consumer
|
91
|
+
return @consumer if defined?(@consumer)
|
92
|
+
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment)
|
93
|
+
end
|
102
94
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
95
|
+
##
|
96
|
+
# Returns an oAuth AccessToken object which can be used to make
|
97
|
+
# user-specific API requests
|
107
98
|
|
108
|
-
|
109
|
-
|
110
|
-
|
99
|
+
def accessor
|
100
|
+
return @accessor if defined?(@accessor)
|
101
|
+
@accessor = OAuth::AccessToken.new(consumer.user_get, access_token, access_secret)
|
102
|
+
end
|
111
103
|
|
112
|
-
|
113
|
-
|
104
|
+
def headers
|
105
|
+
@headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
|
106
|
+
end
|
107
|
+
|
108
|
+
def post_headers
|
109
|
+
@post_headers ||= headers.merge({'Content-Type' => 'application/vnd.deere.axiom.v3+json'})
|
110
|
+
end
|
114
111
|
end
|
115
112
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module MyJohnDeereApi
|
2
2
|
class Consumer
|
3
3
|
include Helpers::CaseConversion
|
4
|
+
include Helpers::EnvironmentHelper
|
4
5
|
|
5
6
|
attr_reader :api_key, :api_secret, :environment, :base_url
|
6
7
|
|
@@ -41,14 +42,6 @@ module MyJohnDeereApi
|
|
41
42
|
|
42
43
|
private
|
43
44
|
|
44
|
-
##
|
45
|
-
# intelligently sets the environment
|
46
|
-
|
47
|
-
def environment=(value)
|
48
|
-
value = value.to_sym
|
49
|
-
@environment = value == :production ? :live : value
|
50
|
-
end
|
51
|
-
|
52
45
|
def consumer(site)
|
53
46
|
OAuth::Consumer.new(
|
54
47
|
api_key,
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
##
|
3
|
+
# This error is used when an unsupported environment has been requested.
|
4
|
+
# Supported environments currently include :sandbox, :live, and :production
|
5
|
+
# as a synonym for :live.
|
6
|
+
|
7
|
+
class UnsupportedEnvironmentError < StandardError
|
8
|
+
def initialize(environment = nil)
|
9
|
+
message = if environment
|
10
|
+
"The #{environment.inspect} environment is not supported."
|
11
|
+
else
|
12
|
+
'This environment is not supported.'
|
13
|
+
end
|
14
|
+
|
15
|
+
super(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
module Helpers::EnvironmentHelper
|
5
|
+
attr_reader :environment
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
##
|
10
|
+
# Intelligently set the environment
|
11
|
+
|
12
|
+
def environment=(value)
|
13
|
+
value = (value || :live).to_sym
|
14
|
+
|
15
|
+
@environment = case value
|
16
|
+
when :sandbox, :live
|
17
|
+
value
|
18
|
+
when :production
|
19
|
+
:live
|
20
|
+
else
|
21
|
+
raise UnsupportedEnvironmentError, value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -23,40 +23,12 @@ describe 'MyJohnDeereApi::Authorize' do
|
|
23
23
|
assert_equal API_SECRET, authorize.api_secret
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'accepts the environment' do
|
27
27
|
environment = :sandbox
|
28
28
|
|
29
29
|
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET, environment: environment) }
|
30
30
|
assert_equal environment, authorize.environment
|
31
31
|
end
|
32
|
-
|
33
|
-
it 'sets the live environment' do
|
34
|
-
environment = :live
|
35
|
-
|
36
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET, environment: environment) }
|
37
|
-
assert_equal environment, authorize.environment
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'accepts production as a synonym for live environment' do
|
41
|
-
environment = :production
|
42
|
-
|
43
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET, environment: environment) }
|
44
|
-
assert_equal :live, authorize.environment
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'converts environment to symbol' do
|
48
|
-
environment = 'sandbox'
|
49
|
-
|
50
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET, environment: environment) }
|
51
|
-
assert_equal environment.to_sym, authorize.environment
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'defaults to live environment' do
|
55
|
-
environment = :live
|
56
|
-
|
57
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET) }
|
58
|
-
assert_equal environment, authorize.environment
|
59
|
-
end
|
60
32
|
end
|
61
33
|
|
62
34
|
describe '#consumer' do
|
@@ -19,33 +19,12 @@ describe 'MyJohnDeereApi::Client' do
|
|
19
19
|
assert_equal access_secret, client.access_secret
|
20
20
|
end
|
21
21
|
|
22
|
-
it 'accepts
|
22
|
+
it 'accepts the environment' do
|
23
23
|
environment = :sandbox
|
24
24
|
|
25
25
|
client = JD::Client.new(API_KEY, API_SECRET, environment: environment)
|
26
26
|
assert_equal environment, client.environment
|
27
27
|
end
|
28
|
-
|
29
|
-
it 'accepts live environment' do
|
30
|
-
environment = :live
|
31
|
-
|
32
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: environment)
|
33
|
-
assert_equal environment, client.environment
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'accepts production as a synonym for live' do
|
37
|
-
environment = :production
|
38
|
-
|
39
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: environment)
|
40
|
-
assert_equal :live, client.environment
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'defaults to live environment' do
|
44
|
-
environment = :live
|
45
|
-
|
46
|
-
client = JD::Client.new(API_KEY, API_SECRET)
|
47
|
-
assert_equal environment, client.environment
|
48
|
-
end
|
49
28
|
end
|
50
29
|
|
51
30
|
describe '#get' do
|
@@ -9,7 +9,7 @@ describe 'JD::Consumer' do
|
|
9
9
|
assert_equal API_SECRET, consumer.api_secret
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'accepts
|
12
|
+
it 'accepts the environment' do
|
13
13
|
environment = :sandbox
|
14
14
|
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
15
15
|
|
@@ -17,38 +17,6 @@ describe 'JD::Consumer' do
|
|
17
17
|
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'accepts live environment' do
|
21
|
-
environment = :live
|
22
|
-
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
23
|
-
|
24
|
-
assert_equal environment, consumer.environment
|
25
|
-
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'accepts production as a synonym for live environment' do
|
29
|
-
environment = :production
|
30
|
-
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
31
|
-
|
32
|
-
assert_equal :live, consumer.environment
|
33
|
-
assert_equal JD::Consumer::URLS[:live], consumer.base_url
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'defaults to live environment' do
|
37
|
-
default_environment = :live
|
38
|
-
consumer = JD::Consumer.new(API_KEY, API_SECRET)
|
39
|
-
|
40
|
-
assert_equal default_environment, consumer.environment
|
41
|
-
assert_equal JD::Consumer::URLS[default_environment], consumer.base_url
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'converts environment string to symbol' do
|
45
|
-
environment = 'sandbox'
|
46
|
-
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
47
|
-
|
48
|
-
assert_equal environment.to_sym, consumer.environment
|
49
|
-
assert_equal JD::Consumer::URLS[environment.to_sym], consumer.base_url
|
50
|
-
end
|
51
|
-
|
52
20
|
it 'accepts an arbitrary base_url' do
|
53
21
|
base_url = 'https://example.com'
|
54
22
|
consumer = JD::Consumer.new(API_KEY, API_SECRET, base_url: base_url)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::UnsupportedEnvironmentError' do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new
|
6
|
+
assert_kind_of StandardError, error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a default message' do
|
10
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new
|
11
|
+
assert_includes error.message, 'This environment is not supported.'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'specifies the failing environment if supplied' do
|
15
|
+
error = MyJohnDeereApi::UnsupportedEnvironmentError.new(:turtles)
|
16
|
+
assert_includes error.message, "The :turtles environment is not supported."
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class EnvironmentHelperSample
|
4
|
+
include JD::Helpers::EnvironmentHelper
|
5
|
+
|
6
|
+
def initialize(environment = nil)
|
7
|
+
self.environment = environment
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'EnvironmentHelper' do
|
12
|
+
let(:object) { EnvironmentHelperSample.new(environment) }
|
13
|
+
let(:environment) { :sandbox }
|
14
|
+
|
15
|
+
it 'provides an attr_reader for :environment' do
|
16
|
+
assert object.environment
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'when no specific environment requested' do
|
20
|
+
let(:environment) { nil }
|
21
|
+
|
22
|
+
it 'sets the environment to :live' do
|
23
|
+
assert_equal :live, object.environment
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'when :sandbox environment requested' do
|
28
|
+
let(:environment) { :sandbox }
|
29
|
+
|
30
|
+
it 'sets the environment to :sandbox' do
|
31
|
+
assert_equal environment, object.environment
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'when :live environment requested' do
|
36
|
+
let(:environment) { :live }
|
37
|
+
|
38
|
+
it 'sets the environment to :live' do
|
39
|
+
assert_equal environment, object.environment
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when :production synonym requested' do
|
44
|
+
let(:environment) { :production }
|
45
|
+
|
46
|
+
it 'sets the environment to :live' do
|
47
|
+
assert_equal :live, object.environment
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'when environment is passed as a string' do
|
52
|
+
let(:environment) { 'sandbox' }
|
53
|
+
|
54
|
+
it 'converts the environment to a symbol' do
|
55
|
+
assert_equal :sandbox, object.environment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'when an unrecognized environment is requested' do
|
60
|
+
let(:environment) { :turtles }
|
61
|
+
|
62
|
+
it 'raises an error' do
|
63
|
+
exception = assert_raises(JD::UnsupportedEnvironmentError) { object }
|
64
|
+
assert_equal "The :turtles environment is not supported.", exception.message
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_john_deere_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime Bellmyer
|
@@ -110,8 +110,10 @@ files:
|
|
110
110
|
- lib/my_john_deere_api/errors/access_token_error.rb
|
111
111
|
- lib/my_john_deere_api/errors/invalid_record_error.rb
|
112
112
|
- lib/my_john_deere_api/errors/type_mismatch_error.rb
|
113
|
+
- lib/my_john_deere_api/errors/unsupported_environment_error.rb
|
113
114
|
- lib/my_john_deere_api/helpers.rb
|
114
115
|
- lib/my_john_deere_api/helpers/case_conversion.rb
|
116
|
+
- lib/my_john_deere_api/helpers/environment_helper.rb
|
115
117
|
- lib/my_john_deere_api/helpers/uri_helpers.rb
|
116
118
|
- lib/my_john_deere_api/model.rb
|
117
119
|
- lib/my_john_deere_api/model/asset.rb
|
@@ -142,8 +144,10 @@ files:
|
|
142
144
|
- test/lib/my_john_deere_api/errors/access_token_error_test.rb
|
143
145
|
- test/lib/my_john_deere_api/errors/invalid_record_error_test.rb
|
144
146
|
- test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb
|
147
|
+
- test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb
|
145
148
|
- test/lib/my_john_deere_api/errors_test.rb
|
146
149
|
- test/lib/my_john_deere_api/helpers/case_conversion_test.rb
|
150
|
+
- test/lib/my_john_deere_api/helpers/environment_helper_test.rb
|
147
151
|
- test/lib/my_john_deere_api/helpers/uri_helpers_test.rb
|
148
152
|
- test/lib/my_john_deere_api/helpers_test.rb
|
149
153
|
- test/lib/my_john_deere_api/model/asset_location_test.rb
|