my_john_deere_api 2.5.0 → 3.0.0
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.rb +1 -1
- data/lib/my_john_deere_api/authorize.rb +36 -27
- data/lib/my_john_deere_api/client.rb +38 -29
- data/lib/my_john_deere_api/consumer.rb +46 -35
- data/lib/my_john_deere_api/helpers/case_conversion.rb +5 -2
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +1 -1
- data/lib/my_john_deere_api/model/contribution_definition.rb +1 -1
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +10 -11
- data/lib/my_john_deere_api/net_http_retry/invalid_response_error.rb +2 -2
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +1 -1
- data/lib/my_john_deere_api/request/collection/assets.rb +1 -1
- data/lib/my_john_deere_api/request/collection/base.rb +2 -14
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +1 -1
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +1 -1
- data/lib/my_john_deere_api/request/collection/fields.rb +1 -1
- data/lib/my_john_deere_api/request/collection/flags.rb +1 -1
- data/lib/my_john_deere_api/request/collection/organizations.rb +1 -1
- data/lib/my_john_deere_api/request/create/asset.rb +8 -11
- data/lib/my_john_deere_api/request/create/asset_location.rb +24 -25
- data/lib/my_john_deere_api/request/create/base.rb +2 -20
- data/lib/my_john_deere_api/request/individual/asset.rb +2 -2
- data/lib/my_john_deere_api/request/individual/base.rb +6 -24
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +1 -1
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +1 -1
- data/lib/my_john_deere_api/request/individual/field.rb +1 -1
- data/lib/my_john_deere_api/request/individual/organization.rb +1 -1
- data/lib/my_john_deere_api/request/update/asset.rb +2 -2
- data/lib/my_john_deere_api/request/update/base.rb +1 -19
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/authorize_test.rb +37 -25
- data/test/lib/my_john_deere_api/client_test.rb +22 -56
- data/test/lib/my_john_deere_api/consumer_test.rb +16 -28
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +0 -10
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +0 -4
- data/test/lib/my_john_deere_api/model/asset_test.rb +9 -8
- data/test/lib/my_john_deere_api/model/base_test.rb +4 -8
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +3 -7
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +4 -7
- data/test/lib/my_john_deere_api/model/field_test.rb +4 -6
- data/test/lib/my_john_deere_api/model/flag_test.rb +6 -7
- data/test/lib/my_john_deere_api/model/organization_test.rb +3 -5
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +14 -14
- data/test/lib/my_john_deere_api/net_http_retry/invalid_response_error_test.rb +22 -2
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +2 -2
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +3 -2
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +5 -4
- data/test/lib/my_john_deere_api/request/create/base_test.rb +0 -14
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +0 -1
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +2 -3
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +5 -17
- data/test/lib/my_john_deere_api/request/update/base_test.rb +0 -14
- data/test/support/helper.rb +14 -5
- data/test/support/link_helpers.rb +14 -0
- data/test/support/response_helpers.rb +18 -0
- data/test/support/vcr/catalog.yml +44 -37
- data/test/support/vcr/get_access_token.yml +90 -17
- data/test/support/vcr/get_refresh_token.yml +159 -0
- data/test/support/vcr/get_request_url.yml +51 -0
- data/test/support/vcr_setup.rb +80 -19
- metadata +11 -8
- data/test/support/vcr/get_request_token.yml +0 -83
@@ -0,0 +1,159 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://sandboxapi.deere.com/platform
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v1.3.0
|
12
|
+
Accept:
|
13
|
+
- application/vnd.deere.axiom.v3+json
|
14
|
+
Authorization:
|
15
|
+
- Bearer AccessToken0123456789abcdefghijklmnopqrstuvwxyz
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Wed, 17 Mar 2021 21:38:22 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/vnd.deere.axiom.v3+json;charset=UTF-8
|
27
|
+
X-Frame-Options:
|
28
|
+
- DENY
|
29
|
+
Cache-Control:
|
30
|
+
- no-store
|
31
|
+
Strict-Transport-Security:
|
32
|
+
- max-age=31536000 ; includeSubDomains
|
33
|
+
X-Xss-Protection:
|
34
|
+
- 1; mode=block
|
35
|
+
X-Content-Type-Options:
|
36
|
+
- nosniff
|
37
|
+
Content-Language:
|
38
|
+
- en
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: ASCII-8BIT
|
43
|
+
string: '{"@type":"ApiCatalog","links":[{"@type":"Link","rel":"oauthRequestToken","uri":"https://sandboxapi.deere.com/platform/oauth/request_token"},{"@type":"Link","rel":"oauthAuthorizeRequestToken","uri":"https://operationscenter.deere.com/consentToUseOfData?oauth_token={token}"},{"@type":"Link","rel":"oauthAccessToken","uri":"https://sandboxapi.deere.com/platform/oauth/access_token"},{"@type":"Link","rel":"currentUser","uri":"https://sandboxapi.deere.com/platform/users/@currentUser"},{"@type":"Link","rel":"organizations","uri":"https://sandboxapi.deere.com/platform/organizations"},{"@type":"Link","rel":"currentToken","uri":"https://sandboxapi.deere.com/platform/oauthTokens/@currentToken"},{"@type":"Link","rel":"contributionProducts","uri":"https://sandboxapi.deere.com/platform/contributionProducts"},{"@type":"Link","rel":"contributionDefinitions","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions"},{"@type":"Link","rel":"assetCatalog","uri":"https://sandboxapi.deere.com/platform/assetCatalog"},{"@type":"Link","rel":"agencies","uri":"https://sandboxapi.deere.com/platform/agencies"}]}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Wed, 17 Mar 2021 21:38:22 GMT
|
46
|
+
- request:
|
47
|
+
method: get
|
48
|
+
uri: https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/.well-known/oauth-authorization-server
|
49
|
+
body:
|
50
|
+
encoding: US-ASCII
|
51
|
+
string: ''
|
52
|
+
headers:
|
53
|
+
User-Agent:
|
54
|
+
- Faraday v1.3.0
|
55
|
+
Accept:
|
56
|
+
- application/vnd.deere.axiom.v3+json
|
57
|
+
Authorization:
|
58
|
+
- Bearer AccessToken0123456789abcdefghijklmnopqrstuvwxyz
|
59
|
+
Accept-Encoding:
|
60
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
61
|
+
response:
|
62
|
+
status:
|
63
|
+
code: 200
|
64
|
+
message: OK
|
65
|
+
headers:
|
66
|
+
Date:
|
67
|
+
- Wed, 17 Mar 2021 21:38:22 GMT
|
68
|
+
Server:
|
69
|
+
- nginx
|
70
|
+
Content-Type:
|
71
|
+
- application/json
|
72
|
+
X-Xss-Protection:
|
73
|
+
- '0'
|
74
|
+
P3p:
|
75
|
+
- CP="HONK"
|
76
|
+
Expect-Ct:
|
77
|
+
- report-uri="https://oktaexpectct.report-uri.com/r/t/ct/reportOnly", max-age=0
|
78
|
+
Cache-Control:
|
79
|
+
- max-age=86400, must-revalidate
|
80
|
+
Expires:
|
81
|
+
- Thu, 18 Mar 2021 21:37:54 GMT
|
82
|
+
X-Content-Type-Options:
|
83
|
+
- nosniff
|
84
|
+
Strict-Transport-Security:
|
85
|
+
- max-age=315360000; includeSubDomains
|
86
|
+
X-Okta-Request-Id:
|
87
|
+
- YFJ2zq-5EtNqLxyo29u@LgAABaM
|
88
|
+
Transfer-Encoding:
|
89
|
+
- chunked
|
90
|
+
body:
|
91
|
+
encoding: UTF-8
|
92
|
+
string: '{"issuer":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7","authorization_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/authorize","token_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/token","registration_endpoint":"https://signin.johndeere.com/oauth2/v1/clients","jwks_uri":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/keys","response_types_supported":["code","token","id_token","code
|
93
|
+
id_token","code token","id_token token","code id_token token"],"response_modes_supported":["query","fragment","form_post","okta_post_message"],"grant_types_supported":["authorization_code","implicit","refresh_token","password","client_credentials"],"subject_types_supported":["public"],"scopes_supported":["ag1","ag2","ag3","eq1","eq2","files","jobs","org1","org2","openid","profile","email","address","phone","offline_access"],"token_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"claims_supported":["ver","jti","iss","aud","iat","exp","cid","uid","scp","sub"],"code_challenge_methods_supported":["S256"],"introspection_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/introspect","introspection_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"revocation_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/revoke","revocation_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"end_session_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/logout","request_parameter_supported":true,"request_object_signing_alg_values_supported":["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"]}'
|
94
|
+
http_version:
|
95
|
+
recorded_at: Wed, 17 Mar 2021 21:38:22 GMT
|
96
|
+
- request:
|
97
|
+
method: post
|
98
|
+
uri: https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/token
|
99
|
+
body:
|
100
|
+
encoding: UTF-8
|
101
|
+
string: client_id=johndeere-0000000000000000000000000000000000000000&client_secret=0000000000000000000000000000000000000000000000000000000000000000&grant_type=refresh_token&refresh_token=RefreshToken0123456789abcdefghijklmnopqrstuvwxyz
|
102
|
+
headers:
|
103
|
+
User-Agent:
|
104
|
+
- Faraday v1.3.0
|
105
|
+
Content-Type:
|
106
|
+
- application/x-www-form-urlencoded
|
107
|
+
Accept-Encoding:
|
108
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
109
|
+
Accept:
|
110
|
+
- "*/*"
|
111
|
+
response:
|
112
|
+
status:
|
113
|
+
code: 200
|
114
|
+
message: OK
|
115
|
+
headers:
|
116
|
+
Date:
|
117
|
+
- Thu, 18 Mar 2021 01:58:10 GMT
|
118
|
+
Server:
|
119
|
+
- nginx
|
120
|
+
Content-Type:
|
121
|
+
- application/json
|
122
|
+
X-Okta-Request-Id:
|
123
|
+
- YFKzsvsT9HdRXpnes1ay1gAAAkw
|
124
|
+
X-Xss-Protection:
|
125
|
+
- '0'
|
126
|
+
P3p:
|
127
|
+
- CP="HONK"
|
128
|
+
X-Rate-Limit-Limit:
|
129
|
+
- '2000'
|
130
|
+
X-Rate-Limit-Remaining:
|
131
|
+
- '1525'
|
132
|
+
X-Rate-Limit-Reset:
|
133
|
+
- '1581334172'
|
134
|
+
Cache-Control:
|
135
|
+
- no-cache, no-store
|
136
|
+
Pragma:
|
137
|
+
- no-cache
|
138
|
+
Expires:
|
139
|
+
- '0'
|
140
|
+
Expect-Ct:
|
141
|
+
- report-uri="https://oktaexpectct.report-uri.com/r/t/ct/reportOnly", max-age=0
|
142
|
+
X-Content-Type-Options:
|
143
|
+
- nosniff
|
144
|
+
Strict-Transport-Security:
|
145
|
+
- max-age=315360000; includeSubDomains
|
146
|
+
X-Robots-Tag:
|
147
|
+
- none
|
148
|
+
Set-Cookie:
|
149
|
+
- JSESSIONID=89716561F6888C4A6EA6D6BD268E0BE7; Path=/; Secure; HttpOnly
|
150
|
+
- sid=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
|
151
|
+
Transfer-Encoding:
|
152
|
+
- chunked
|
153
|
+
body:
|
154
|
+
encoding: UTF-8
|
155
|
+
string: '{"token_type":"Bearer","expires_in":43200,"access_token":"NewAccessToken0123456789abcdefghijklmnopqrstuvwxyz","scope":"ag2
|
156
|
+
ag1 offline_access ag3","refresh_token":"RefreshToken0123456789abcdefghijklmnopqrstuvwxyz"}'
|
157
|
+
http_version:
|
158
|
+
recorded_at: Thu, 18 Mar 2021 01:58:10 GMT
|
159
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/.well-known/oauth-authorization-server
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v1.3.0
|
12
|
+
Accept:
|
13
|
+
- application/vnd.deere.axiom.v3+json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 16 Mar 2021 21:12:20 GMT
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
X-Xss-Protection:
|
28
|
+
- '0'
|
29
|
+
P3p:
|
30
|
+
- CP="HONK"
|
31
|
+
Expect-Ct:
|
32
|
+
- report-uri="https://oktaexpectct.report-uri.com/r/t/ct/reportOnly", max-age=0
|
33
|
+
Cache-Control:
|
34
|
+
- max-age=86400, must-revalidate
|
35
|
+
Expires:
|
36
|
+
- Wed, 17 Mar 2021 21:12:08 GMT
|
37
|
+
X-Content-Type-Options:
|
38
|
+
- nosniff
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=315360000; includeSubDomains
|
41
|
+
X-Okta-Request-Id:
|
42
|
+
- YFEfNKAOG6XT8F4E1py7RwAACrM
|
43
|
+
Transfer-Encoding:
|
44
|
+
- chunked
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"issuer":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7","authorization_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/authorize","token_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/token","registration_endpoint":"https://signin.johndeere.com/oauth2/v1/clients","jwks_uri":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/keys","response_types_supported":["code","token","id_token","code
|
48
|
+
id_token","code token","id_token token","code id_token token"],"response_modes_supported":["query","fragment","form_post","okta_post_message"],"grant_types_supported":["authorization_code","implicit","refresh_token","password","client_credentials"],"subject_types_supported":["public"],"scopes_supported":["ag1","ag2","ag3","eq1","eq2","files","jobs","org1","org2","openid","profile","email","address","phone","offline_access"],"token_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"claims_supported":["ver","jti","iss","aud","iat","exp","cid","uid","scp","sub"],"code_challenge_methods_supported":["S256"],"introspection_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/introspect","introspection_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"revocation_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/revoke","revocation_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post","client_secret_jwt","private_key_jwt","none"],"end_session_endpoint":"https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/logout","request_parameter_supported":true,"request_object_signing_alg_values_supported":["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"]}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Tue, 16 Mar 2021 21:12:21 GMT
|
51
|
+
recorded_with: VCR 5.0.0
|
data/test/support/vcr_setup.rb
CHANGED
@@ -12,14 +12,14 @@ require 'date'
|
|
12
12
|
##########################################################################
|
13
13
|
|
14
14
|
class VcrSetup
|
15
|
-
attr_reader :api_key, :api_secret, :access_token, :
|
16
|
-
:contribution_product_id, :contribution_definition_id,
|
15
|
+
attr_reader :api_key, :api_secret, :access_token, :new_access_token, :refresh_token,
|
16
|
+
:verify_code, :contribution_product_id, :contribution_definition_id,
|
17
17
|
:placeholders, :organization_id, :asset_id, :field_id, :flag_id
|
18
18
|
|
19
|
-
AUTH_CASSETTES = [:catalog, :
|
19
|
+
AUTH_CASSETTES = [:catalog, :get_request_url, :get_access_token, :get_refresh_token]
|
20
20
|
|
21
21
|
GENERATED_CASSETTES = [
|
22
|
-
:catalog, :
|
22
|
+
:catalog, :get_request_url, :get_access_token, :get_refresh_token,
|
23
23
|
:get_contribution_products, :get_contribution_product,
|
24
24
|
:get_contribution_definitions, :get_contribution_definition,
|
25
25
|
:get_organizations, :get_organization,
|
@@ -39,8 +39,9 @@ class VcrSetup
|
|
39
39
|
@uuid = '00000000-0000-0000-0000-000000000000'
|
40
40
|
@api_key = 'johndeere-0000000000000000000000000000000000000000'
|
41
41
|
@api_secret = '0' * 64
|
42
|
-
@access_token =
|
43
|
-
@
|
42
|
+
@access_token = 'AccessToken0123456789abcdefghijklmnopqrstuvwxyz'
|
43
|
+
@new_access_token = 'NewAccessToken0123456789abcdefghijklmnopqrstuvwxyz'
|
44
|
+
@refresh_token = 'RefreshToken0123456789abcdefghijklmnopqrstuvwxyz'
|
44
45
|
@contribution_product_id = @uuid
|
45
46
|
@contribution_definition_id = @uuid
|
46
47
|
@organization_id = '000000'
|
@@ -60,15 +61,16 @@ class VcrSetup
|
|
60
61
|
unless all_cassettes_generated?
|
61
62
|
puts "\ngenerating:"
|
62
63
|
|
63
|
-
unless
|
64
|
+
unless File.exist?(token_file)
|
64
65
|
generate_cassettes(AUTH_CASSETTES)
|
65
66
|
end
|
66
67
|
|
67
68
|
@placeholders.merge!(
|
68
69
|
ENV['API_KEY'] => @api_key,
|
69
70
|
ENV['API_SECRET'] => @api_secret,
|
70
|
-
|
71
|
-
|
71
|
+
current_access_token => @access_token,
|
72
|
+
new_access_token => @new_access_token,
|
73
|
+
current_refresh_token => @refresh_token
|
72
74
|
)
|
73
75
|
|
74
76
|
VCR.use_cassette('temp') do
|
@@ -77,7 +79,7 @@ class VcrSetup
|
|
77
79
|
set_organization_id
|
78
80
|
end
|
79
81
|
|
80
|
-
File.unlink("#{@vcr_dir}/temp.yml")
|
82
|
+
File.unlink("#{@vcr_dir}/temp.yml") if File.exist?("#{@vcr_dir}/temp.yml")
|
81
83
|
|
82
84
|
generate_cassettes(GENERATED_CASSETTES)
|
83
85
|
end
|
@@ -92,7 +94,8 @@ class VcrSetup
|
|
92
94
|
api_secret,
|
93
95
|
contribution_definition_id: contribution_definition_id,
|
94
96
|
environment: :sandbox,
|
95
|
-
|
97
|
+
token_hash: token_hash,
|
98
|
+
raise_errors: false,
|
96
99
|
)
|
97
100
|
end
|
98
101
|
|
@@ -164,6 +167,21 @@ class VcrSetup
|
|
164
167
|
@url = JD::Consumer::URLS[:sandbox]
|
165
168
|
end
|
166
169
|
|
170
|
+
def token_hash
|
171
|
+
return @token_hash if defined?(@token_hash)
|
172
|
+
|
173
|
+
@token_hash = JSON.parse(File.read(token_file))
|
174
|
+
|
175
|
+
token = OAuth2::AccessToken.from_hash(auth_client, @token_hash)
|
176
|
+
|
177
|
+
if token.expired?
|
178
|
+
new_token = token.refresh!
|
179
|
+
set_token_hash(new_token)
|
180
|
+
end
|
181
|
+
|
182
|
+
@token_hash
|
183
|
+
end
|
184
|
+
|
167
185
|
private
|
168
186
|
|
169
187
|
def generate_cassettes(list)
|
@@ -191,25 +209,61 @@ class VcrSetup
|
|
191
209
|
ENV['API_SECRET'],
|
192
210
|
environment: :sandbox,
|
193
211
|
contribution_definition_id: ENV['CONTRIBUTION_DEFINITION_ID'],
|
194
|
-
|
212
|
+
token_hash: token_hash,
|
213
|
+
raise_errors: false,
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
def token_file
|
218
|
+
'./tmp/token_hash.json'
|
219
|
+
end
|
220
|
+
|
221
|
+
def current_access_token
|
222
|
+
token_hash['access_token']
|
223
|
+
end
|
224
|
+
|
225
|
+
def current_refresh_token
|
226
|
+
token_hash['refresh_token']
|
227
|
+
end
|
228
|
+
|
229
|
+
def set_token_hash(token)
|
230
|
+
@token_hash = token.is_a?(Hash) ? token : token.to_hash
|
231
|
+
File.write(token_file, @token_hash.to_json)
|
232
|
+
end
|
233
|
+
|
234
|
+
def auth_client
|
235
|
+
OAuth2::Client.new(
|
236
|
+
ENV['API_KEY'],
|
237
|
+
ENV['API_SECRET'],
|
238
|
+
site: 'https://sandboxapi.deere.com',
|
239
|
+
authorize_url: 'https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/authorize',
|
240
|
+
token_url: 'https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/v1/token',
|
241
|
+
raise_errors: false,
|
195
242
|
)
|
196
243
|
end
|
197
244
|
|
198
245
|
def catalog
|
199
|
-
new_client.get('/')
|
246
|
+
new_client.get('/platform')
|
247
|
+
new_client.get('https://signin.johndeere.com/oauth2/aus78tnlaysMraFhC1t7/.well-known/oauth-authorization-server')
|
200
248
|
end
|
201
249
|
|
202
|
-
def
|
250
|
+
def get_request_url
|
203
251
|
@temporary_authorize = JD::Authorize.new(
|
204
252
|
ENV['API_KEY'],
|
205
253
|
ENV['API_SECRET'],
|
206
|
-
environment: :sandbox
|
254
|
+
environment: :sandbox,
|
255
|
+
scopes: ['ag1', 'ag2', 'ag3'],
|
256
|
+
redirect_uri: 'http://localhost'
|
207
257
|
)
|
208
258
|
|
209
259
|
@temporary_authorize_url = @temporary_authorize.authorize_url
|
210
260
|
end
|
211
261
|
|
212
262
|
def get_access_token
|
263
|
+
unless defined?(@temporary_authorize_url)
|
264
|
+
VCR.use_cassette(:get_request_url) { get_request_url }
|
265
|
+
end
|
266
|
+
|
213
267
|
puts "\n\n----\nFOLLOW THIS LINK, AND ENTER THE VERIFICATION CODE:\n#{@temporary_authorize_url}\n----\n\n"
|
214
268
|
$stdout.print 'Verification Code: '; $stdout.flush
|
215
269
|
code = $stdin.gets.chomp
|
@@ -217,12 +271,19 @@ class VcrSetup
|
|
217
271
|
|
218
272
|
placeholders[code] = verify_code
|
219
273
|
|
220
|
-
@temporary_authorize.verify(code)
|
274
|
+
token = @temporary_authorize.verify(code)
|
275
|
+
set_token_hash(token)
|
276
|
+
end
|
221
277
|
|
222
|
-
|
223
|
-
|
224
|
-
|
278
|
+
def get_refresh_token
|
279
|
+
unless defined?(@temporary_authorize_url)
|
280
|
+
VCR.use_cassette(:get_request_url) { get_request_url }
|
225
281
|
end
|
282
|
+
|
283
|
+
old_hash = @temporary_authorize.token_hash || token_hash
|
284
|
+
new_hash = @temporary_authorize.refresh_from_hash(old_hash)
|
285
|
+
|
286
|
+
set_token_hash(new_hash)
|
226
287
|
end
|
227
288
|
|
228
289
|
def get_contribution_products
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime Bellmyer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vcr
|
@@ -54,19 +54,19 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 3.7.6
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: oauth2
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 1.4.4
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 1.4.4
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: json
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +89,7 @@ dependencies:
|
|
89
89
|
version: '2.1'
|
90
90
|
description: |
|
91
91
|
This gem interacts with the My John Deere API. It handles the hard work of
|
92
|
-
John Deere's oAuth
|
92
|
+
John Deere's oAuth 2.0 authentication. It provides REST request methods for
|
93
93
|
GET, POST, PUT, and DELETE that abstract away the John Deere-specific headers
|
94
94
|
and protocols. It provides convenience methods similar to ActiveRecord so
|
95
95
|
you can write things like: `client.organizations.find(123).assets` or
|
@@ -216,6 +216,8 @@ files:
|
|
216
216
|
- test/lib/my_john_deere_api/version_test.rb
|
217
217
|
- test/my_john_deere_api_test.rb
|
218
218
|
- test/support/helper.rb
|
219
|
+
- test/support/link_helpers.rb
|
220
|
+
- test/support/response_helpers.rb
|
219
221
|
- test/support/vcr/accessor/delete_failed.yml
|
220
222
|
- test/support/vcr/accessor/delete_invalid.yml
|
221
223
|
- test/support/vcr/accessor/delete_max_failed.yml
|
@@ -251,7 +253,8 @@ files:
|
|
251
253
|
- test/support/vcr/get_flags.yml
|
252
254
|
- test/support/vcr/get_organization.yml
|
253
255
|
- test/support/vcr/get_organizations.yml
|
254
|
-
- test/support/vcr/
|
256
|
+
- test/support/vcr/get_refresh_token.yml
|
257
|
+
- test/support/vcr/get_request_url.yml
|
255
258
|
- test/support/vcr/post_asset_locations.yml
|
256
259
|
- test/support/vcr/post_assets.yml
|
257
260
|
- test/support/vcr/put_asset.yml
|
@@ -276,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
279
|
- !ruby/object:Gem::Version
|
277
280
|
version: '0'
|
278
281
|
requirements: []
|
279
|
-
rubygems_version: 3.0.
|
282
|
+
rubygems_version: 3.0.3
|
280
283
|
signing_key:
|
281
284
|
specification_version: 4
|
282
285
|
summary: Interact with John Deere's Developer API
|