my_john_deere_api 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +813 -0
- data/Rakefile +9 -0
- data/lib/my_john_deere_api.rb +17 -0
- data/lib/my_john_deere_api/authorize.rb +69 -0
- data/lib/my_john_deere_api/client.rb +151 -0
- data/lib/my_john_deere_api/consumer.rb +90 -0
- data/lib/my_john_deere_api/errors.rb +7 -0
- data/lib/my_john_deere_api/errors/invalid_record_error.rb +29 -0
- data/lib/my_john_deere_api/errors/missing_contribution_definition_id_error.rb +12 -0
- data/lib/my_john_deere_api/errors/not_yet_implemented_error.rb +12 -0
- data/lib/my_john_deere_api/errors/type_mismatch_error.rb +12 -0
- data/lib/my_john_deere_api/errors/unsupported_environment_error.rb +18 -0
- data/lib/my_john_deere_api/helpers.rb +6 -0
- data/lib/my_john_deere_api/helpers/case_conversion.rb +37 -0
- data/lib/my_john_deere_api/helpers/environment_helper.rb +25 -0
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +19 -0
- data/lib/my_john_deere_api/helpers/validate_contribution_definition.rb +18 -0
- data/lib/my_john_deere_api/model.rb +10 -0
- data/lib/my_john_deere_api/model/asset.rb +69 -0
- data/lib/my_john_deere_api/model/asset_location.rb +19 -0
- data/lib/my_john_deere_api/model/base.rb +97 -0
- data/lib/my_john_deere_api/model/contribution_definition.rb +15 -0
- data/lib/my_john_deere_api/model/contribution_product.rb +33 -0
- data/lib/my_john_deere_api/model/field.rb +40 -0
- data/lib/my_john_deere_api/model/flag.rb +36 -0
- data/lib/my_john_deere_api/model/organization.rb +43 -0
- data/lib/my_john_deere_api/net_http_retry.rb +2 -0
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +53 -0
- data/lib/my_john_deere_api/net_http_retry/max_retries_exceeded_error.rb +20 -0
- data/lib/my_john_deere_api/request.rb +6 -0
- data/lib/my_john_deere_api/request/collection.rb +10 -0
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +27 -0
- data/lib/my_john_deere_api/request/collection/assets.rb +34 -0
- data/lib/my_john_deere_api/request/collection/base.rb +91 -0
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +26 -0
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +26 -0
- data/lib/my_john_deere_api/request/collection/fields.rb +26 -0
- data/lib/my_john_deere_api/request/collection/flags.rb +33 -0
- data/lib/my_john_deere_api/request/collection/organizations.rb +26 -0
- data/lib/my_john_deere_api/request/create.rb +5 -0
- data/lib/my_john_deere_api/request/create/asset.rb +57 -0
- data/lib/my_john_deere_api/request/create/asset_location.rb +110 -0
- data/lib/my_john_deere_api/request/create/base.rb +67 -0
- data/lib/my_john_deere_api/request/individual.rb +8 -0
- data/lib/my_john_deere_api/request/individual/asset.rb +19 -0
- data/lib/my_john_deere_api/request/individual/base.rb +52 -0
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +19 -0
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +19 -0
- data/lib/my_john_deere_api/request/individual/field.rb +19 -0
- data/lib/my_john_deere_api/request/individual/organization.rb +19 -0
- data/lib/my_john_deere_api/request/update.rb +4 -0
- data/lib/my_john_deere_api/request/update/asset.rb +40 -0
- data/lib/my_john_deere_api/request/update/base.rb +67 -0
- data/lib/my_john_deere_api/validators.rb +5 -0
- data/lib/my_john_deere_api/validators/asset.rb +35 -0
- data/lib/my_john_deere_api/validators/asset_location.rb +34 -0
- data/lib/my_john_deere_api/validators/base.rb +67 -0
- data/lib/my_john_deere_api/version.rb +3 -0
- data/test/lib/my_john_deere_api/authorize_test.rb +81 -0
- data/test/lib/my_john_deere_api/client_test.rb +225 -0
- data/test/lib/my_john_deere_api/consumer_test.rb +58 -0
- data/test/lib/my_john_deere_api/errors/invalid_record_error_test.rb +26 -0
- data/test/lib/my_john_deere_api/errors/max_retries_exceeded_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/missing_contribution_definition_id_error_test.rb +14 -0
- data/test/lib/my_john_deere_api/errors/not_yet_implemented_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb +13 -0
- 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 +25 -0
- data/test/lib/my_john_deere_api/helpers/case_conversion_test.rb +100 -0
- data/test/lib/my_john_deere_api/helpers/environment_helper_test.rb +67 -0
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +58 -0
- data/test/lib/my_john_deere_api/helpers/validate_contribution_definition_test.rb +74 -0
- data/test/lib/my_john_deere_api/helpers_test.rb +21 -0
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +38 -0
- data/test/lib/my_john_deere_api/model/asset_test.rb +133 -0
- data/test/lib/my_john_deere_api/model/base_test.rb +76 -0
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +52 -0
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +82 -0
- data/test/lib/my_john_deere_api/model/field_test.rb +65 -0
- data/test/lib/my_john_deere_api/model/flag_test.rb +48 -0
- data/test/lib/my_john_deere_api/model/organization_test.rb +84 -0
- data/test/lib/my_john_deere_api/model_test.rb +37 -0
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +102 -0
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +27 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +86 -0
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +92 -0
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +87 -0
- data/test/lib/my_john_deere_api/request/collection_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +182 -0
- data/test/lib/my_john_deere_api/request/create/base_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/create_test.rb +17 -0
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +18 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/update/base_test.rb +60 -0
- data/test/lib/my_john_deere_api/request/update_test.rb +13 -0
- data/test/lib/my_john_deere_api/request_test.rb +21 -0
- data/test/lib/my_john_deere_api/validators/asset_location_test.rb +61 -0
- data/test/lib/my_john_deere_api/validators/asset_test.rb +93 -0
- data/test/lib/my_john_deere_api/validators/base_test.rb +92 -0
- data/test/lib/my_john_deere_api/validators_test.rb +17 -0
- data/test/lib/my_john_deere_api/version_test.rb +9 -0
- data/test/my_john_deere_api_test.rb +37 -0
- data/test/support/helper.rb +97 -0
- data/test/support/vcr/accessor/delete_failed.yml +327 -0
- data/test/support/vcr/accessor/delete_max_failed.yml +615 -0
- data/test/support/vcr/accessor/delete_retry.yml +191 -0
- data/test/support/vcr/accessor/delete_retry_too_soon.yml +191 -0
- data/test/support/vcr/accessor/get_failed.yml +390 -0
- data/test/support/vcr/accessor/get_max_failed.yml +734 -0
- data/test/support/vcr/accessor/get_retry.yml +226 -0
- data/test/support/vcr/accessor/get_retry_too_soon.yml +226 -0
- data/test/support/vcr/accessor/post_failed.yml +417 -0
- data/test/support/vcr/accessor/post_max_failed.yml +785 -0
- data/test/support/vcr/accessor/post_retry.yml +241 -0
- data/test/support/vcr/accessor/post_retry_too_soon.yml +241 -0
- data/test/support/vcr/accessor/put_failed.yml +372 -0
- data/test/support/vcr/accessor/put_max_failed.yml +700 -0
- data/test/support/vcr/accessor/put_retry.yml +216 -0
- data/test/support/vcr/accessor/put_retry_too_soon.yml +216 -0
- data/test/support/vcr/catalog.yml +89 -0
- data/test/support/vcr/delete_asset.yml +82 -0
- data/test/support/vcr/get_access_token.yml +41 -0
- data/test/support/vcr/get_asset.yml +144 -0
- data/test/support/vcr/get_asset_locations.yml +196 -0
- data/test/support/vcr/get_assets.yml +152 -0
- data/test/support/vcr/get_contribution_definition.yml +90 -0
- data/test/support/vcr/get_contribution_definitions.yml +91 -0
- data/test/support/vcr/get_contribution_product.yml +91 -0
- data/test/support/vcr/get_contribution_products.yml +91 -0
- data/test/support/vcr/get_field.yml +144 -0
- data/test/support/vcr/get_fields.yml +146 -0
- data/test/support/vcr/get_flags.yml +47 -0
- data/test/support/vcr/get_organization.yml +90 -0
- data/test/support/vcr/get_organizations.yml +149 -0
- data/test/support/vcr/get_request_token.yml +83 -0
- data/test/support/vcr/post_asset_locations.yml +244 -0
- data/test/support/vcr/post_assets.yml +192 -0
- data/test/support/vcr/put_asset.yml +87 -0
- data/test/support/vcr/warning.txt +28 -0
- data/test/support/vcr_setup.rb +488 -0
- metadata +277 -0
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module MyJohnDeereApi
|
6
|
+
autoload :VERSION, 'my_john_deere_api/version'
|
7
|
+
autoload :Authorize, 'my_john_deere_api/authorize'
|
8
|
+
autoload :Client, 'my_john_deere_api/client'
|
9
|
+
autoload :Consumer, 'my_john_deere_api/consumer'
|
10
|
+
autoload :Request, 'my_john_deere_api/request'
|
11
|
+
autoload :Model, 'my_john_deere_api/model'
|
12
|
+
autoload :Helpers, 'my_john_deere_api/helpers'
|
13
|
+
autoload :Validators, 'my_john_deere_api/validators'
|
14
|
+
|
15
|
+
require 'my_john_deere_api/errors'
|
16
|
+
require 'my_john_deere_api/net_http_retry'
|
17
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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
|
+
# 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
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Client
|
3
|
+
include Helpers::EnvironmentHelper
|
4
|
+
include Helpers::CaseConversion
|
5
|
+
|
6
|
+
attr_accessor :contribution_definition_id
|
7
|
+
attr_reader :api_key, :api_secret, :access_token, :access_secret, :http_retry_options
|
8
|
+
|
9
|
+
DEFAULTS = {
|
10
|
+
environment: :live,
|
11
|
+
http_retry: {}
|
12
|
+
}
|
13
|
+
|
14
|
+
##
|
15
|
+
# Creates the client with everything it needs to perform API requests.
|
16
|
+
# User-specific credentials are optional, but user-specific API
|
17
|
+
# requests are only possible if they are supplied.
|
18
|
+
#
|
19
|
+
# options:
|
20
|
+
#
|
21
|
+
# [:environment] :sandbox or :live
|
22
|
+
#
|
23
|
+
# [:contribution_definition_id] optional, but needed for some requests
|
24
|
+
# like asset create/update.
|
25
|
+
#
|
26
|
+
# [:access] an array with two elements, the access_token
|
27
|
+
# and the access_secret of the given user
|
28
|
+
|
29
|
+
def initialize(api_key, api_secret, options = {})
|
30
|
+
options = DEFAULTS.merge(options)
|
31
|
+
|
32
|
+
@api_key = api_key
|
33
|
+
@api_secret = api_secret
|
34
|
+
|
35
|
+
if options.has_key?(:access) && options[:access].is_a?(Array)
|
36
|
+
@access_token, @access_secret = options[:access]
|
37
|
+
end
|
38
|
+
|
39
|
+
self.environment = options[:environment]
|
40
|
+
@contribution_definition_id = options[:contribution_definition_id]
|
41
|
+
@http_retry_options = options[:http_retry]
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Returns an oAuth AccessToken object which can be used to make
|
46
|
+
# user-specific API requests
|
47
|
+
|
48
|
+
def accessor
|
49
|
+
return @accessor if defined?(@accessor)
|
50
|
+
|
51
|
+
@accessor = NetHttpRetry::Decorator.new(
|
52
|
+
OAuth::AccessToken.new(
|
53
|
+
consumer.user_get,
|
54
|
+
access_token,
|
55
|
+
access_secret
|
56
|
+
),
|
57
|
+
http_retry_options
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# generic user-specific GET request method that returns JSON
|
63
|
+
|
64
|
+
def get resource
|
65
|
+
resource = resource.to_s
|
66
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
67
|
+
response = accessor.get(resource, headers)
|
68
|
+
|
69
|
+
JSON.parse(response.body)
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# generic user-specific POST request method that returns JSON or response
|
74
|
+
|
75
|
+
def post resource, body
|
76
|
+
resource = resource.to_s
|
77
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
78
|
+
response = accessor.post(resource, camelize(body).to_json, post_headers)
|
79
|
+
|
80
|
+
if response.body && response.body.size > 0
|
81
|
+
JSON.parse(response.body)
|
82
|
+
else
|
83
|
+
response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# generic user-specific PUT request method that returns JSON or response
|
89
|
+
|
90
|
+
def put resource, body
|
91
|
+
resource = resource.to_s
|
92
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
93
|
+
response = accessor.put(resource, camelize(body).to_json, post_headers)
|
94
|
+
|
95
|
+
if response.body && response.body.size > 0
|
96
|
+
JSON.parse(response.body)
|
97
|
+
else
|
98
|
+
response
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# generic user-specific DELETE request method that returns JSON or response
|
104
|
+
|
105
|
+
def delete resource
|
106
|
+
resource = resource.to_s
|
107
|
+
resource = "/#{resource}" unless resource =~ /^\//
|
108
|
+
response = accessor.delete(resource, headers)
|
109
|
+
|
110
|
+
if response.body && response.body.size > 0
|
111
|
+
JSON.parse(response.body)
|
112
|
+
else
|
113
|
+
response
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# organizations associated with this access
|
119
|
+
|
120
|
+
def organizations
|
121
|
+
return @organizations if defined?(@organizations)
|
122
|
+
@organizations = MyJohnDeereApi::Request::Collection::Organizations.new(self)
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# contribution products associated with this app (not user-specific)
|
127
|
+
|
128
|
+
def contribution_products
|
129
|
+
return @contribution_products if defined?(@contribution_products)
|
130
|
+
@contribution_products = MyJohnDeereApi::Request::Collection::ContributionProducts.new(self)
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
##
|
136
|
+
# Returns an oAuth consumer which can be used to build requests
|
137
|
+
|
138
|
+
def consumer
|
139
|
+
return @consumer if defined?(@consumer)
|
140
|
+
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment)
|
141
|
+
end
|
142
|
+
|
143
|
+
def headers
|
144
|
+
@headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
|
145
|
+
end
|
146
|
+
|
147
|
+
def post_headers
|
148
|
+
@post_headers ||= headers.merge({'Content-Type' => 'application/vnd.deere.axiom.v3+json'})
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Consumer
|
3
|
+
include Helpers::CaseConversion
|
4
|
+
include Helpers::EnvironmentHelper
|
5
|
+
|
6
|
+
attr_reader :api_key, :api_secret, :environment, :base_url
|
7
|
+
|
8
|
+
# valid API urls
|
9
|
+
URLS = {
|
10
|
+
sandbox: 'https://sandboxapi.deere.com',
|
11
|
+
live: 'https://api.soa-proxy.deere.com',
|
12
|
+
}
|
13
|
+
|
14
|
+
DEFAULTS = {
|
15
|
+
environment: :live
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(api_key, api_secret, options={})
|
19
|
+
options = DEFAULTS.merge(options)
|
20
|
+
|
21
|
+
@api_key = api_key
|
22
|
+
@api_secret = api_secret
|
23
|
+
|
24
|
+
self.environment = options[:environment]
|
25
|
+
@base_url = options[:base_url] || URLS[@environment]
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# oAuth Consumer which uses just the base url, for
|
30
|
+
# app-wide, non user-specific GET requests.
|
31
|
+
|
32
|
+
def app_get
|
33
|
+
@app_get ||= consumer(base_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# oAuth Consumer which uses the proper url for user-specific GET requests.
|
38
|
+
|
39
|
+
def user_get
|
40
|
+
@user_get ||= consumer("#{base_url}/platform")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def consumer(site)
|
46
|
+
OAuth::Consumer.new(
|
47
|
+
api_key,
|
48
|
+
api_secret,
|
49
|
+
site: site,
|
50
|
+
header: header,
|
51
|
+
http_method: :get,
|
52
|
+
request_token_url: links[:request_token],
|
53
|
+
access_token_url: links[:access_token],
|
54
|
+
authorize_url: links[:authorize_request_token]
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def links
|
59
|
+
return @links if defined?(@links)
|
60
|
+
|
61
|
+
catalog = OAuth::Consumer.new(api_key, api_secret)
|
62
|
+
.request(
|
63
|
+
:get,
|
64
|
+
"#{base_url}/platform/",
|
65
|
+
nil,
|
66
|
+
{},
|
67
|
+
header
|
68
|
+
).body
|
69
|
+
|
70
|
+
@links = {}
|
71
|
+
|
72
|
+
JSON.parse(catalog)['links'].each do |link|
|
73
|
+
uri = URI.parse(link['uri'])
|
74
|
+
uri.query = nil
|
75
|
+
|
76
|
+
@links[keyify(link['rel'])] = uri.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
@links
|
80
|
+
end
|
81
|
+
|
82
|
+
def header
|
83
|
+
@header ||= {accept: 'application/vnd.deere.axiom.v3+json'}
|
84
|
+
end
|
85
|
+
|
86
|
+
def keyify key_name
|
87
|
+
underscore(key_name.gsub(/^oauth/, '')).to_sym
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module MyJohnDeereApi::Errors
|
2
|
+
require 'my_john_deere_api/errors/invalid_record_error'
|
3
|
+
require 'my_john_deere_api/errors/missing_contribution_definition_id_error'
|
4
|
+
require 'my_john_deere_api/errors/not_yet_implemented_error'
|
5
|
+
require 'my_john_deere_api/errors/type_mismatch_error'
|
6
|
+
require 'my_john_deere_api/errors/unsupported_environment_error'
|
7
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
##
|
3
|
+
# This error is used in a context that will fail in the absence of
|
4
|
+
# a valid oAuth access token. We have classes that may only need
|
5
|
+
# access tokens for some use cases.
|
6
|
+
|
7
|
+
class InvalidRecordError < StandardError
|
8
|
+
|
9
|
+
##
|
10
|
+
# argument is a hash of attributes and their error messages,
|
11
|
+
# which will be built into the raised message.
|
12
|
+
|
13
|
+
def initialize(errors = {})
|
14
|
+
message = 'Record is invalid'
|
15
|
+
|
16
|
+
unless errors.empty?
|
17
|
+
attribute_messages = []
|
18
|
+
|
19
|
+
errors.each do |attribute, message|
|
20
|
+
attribute_messages << "#{attribute} #{message}"
|
21
|
+
end
|
22
|
+
|
23
|
+
message = "#{message}: #{attribute_messages.join('; ')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
super(message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
##
|
3
|
+
# This error is used in a context that will fail in the absence of
|
4
|
+
# a valid oAuth access token. We have classes that may only need
|
5
|
+
# access tokens for some use cases.
|
6
|
+
|
7
|
+
class MissingContributionDefinitionIdError < StandardError
|
8
|
+
def initialize(message = "Contribution Definition ID must be set in the client to use this feature.")
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
##
|
3
|
+
# This error is used in a context that will fail in the absence of
|
4
|
+
# a valid oAuth access token. We have classes that may only need
|
5
|
+
# access tokens for some use cases.
|
6
|
+
|
7
|
+
class NotYetImplementedError < StandardError
|
8
|
+
def initialize(message = 'This is not yet implemented. View README to help make this gem better!')
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
##
|
3
|
+
# This error is used in a context that will fail in the absence of
|
4
|
+
# a valid oAuth access token. We have classes that may only need
|
5
|
+
# access tokens for some use cases.
|
6
|
+
|
7
|
+
class TypeMismatchError < StandardError
|
8
|
+
def initialize(message = "Record type does not match what was expected")
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -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,6 @@
|
|
1
|
+
module MyJohnDeereApi::Helpers
|
2
|
+
autoload :UriHelpers, 'my_john_deere_api/helpers/uri_helpers'
|
3
|
+
autoload :CaseConversion, 'my_john_deere_api/helpers/case_conversion'
|
4
|
+
autoload :EnvironmentHelper, 'my_john_deere_api/helpers/environment_helper'
|
5
|
+
autoload :ValidateContributionDefinition, 'my_john_deere_api/helpers/validate_contribution_definition'
|
6
|
+
end
|