my_john_deere_api 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,22 +16,22 @@ http_interactions:
16
16
  Authorization:
17
17
  - OAuth oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
18
18
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
19
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_version="1.0"
19
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_version="1.0"
20
20
  response:
21
21
  status:
22
22
  code: 200
23
23
  message: OK
24
24
  headers:
25
25
  Date:
26
- - Fri, 07 Feb 2020 16:22:20 GMT
26
+ - Mon, 10 Feb 2020 17:29:24 GMT
27
27
  Content-Type:
28
28
  - application/vnd.deere.axiom.v3+json;charset=UTF-8
29
29
  X-Deere-Handling-Server:
30
- - ip-10-214-45-137
30
+ - ip-10-214-44-215
31
31
  X-Frame-Options:
32
32
  - SAMEORIGIN
33
33
  X-Deere-Elapsed-Ms:
34
- - '18'
34
+ - '10'
35
35
  Cache-Control:
36
36
  - no-store
37
37
  Content-Language:
@@ -42,7 +42,7 @@ http_interactions:
42
42
  encoding: ASCII-8BIT
43
43
  string: '{"@type":"ApiCatalog","links":[{"@type":"Link","rel":"oauthRequestToken","uri":"https://sandboxapi.deere.com/platform/oauth/request_token"},{"@type":"Link","rel":"oauthAuthorizeRequestToken","uri":"https://my.deere.com/consentToUseOfData?oauth_token={token}"},{"@type":"Link","rel":"oauthAccessToken","uri":"https://sandboxapi.deere.com/platform/oauth/access_token"},{"@type":"Link","rel":"agencies","uri":"https://sandboxapi.deere.com/platform/agencies"}]}'
44
44
  http_version:
45
- recorded_at: Fri, 07 Feb 2020 16:22:20 GMT
45
+ recorded_at: Mon, 10 Feb 2020 17:29:25 GMT
46
46
  - request:
47
47
  method: get
48
48
  uri: https://sandboxapi.deere.com/platform/organizations
@@ -59,7 +59,7 @@ http_interactions:
59
59
  Authorization:
60
60
  - OAuth oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
61
61
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
62
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_token="00000000-0000-0000-0000-000000000000",
62
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_token="00000000-0000-0000-0000-000000000000",
63
63
  oauth_version="1.0"
64
64
  response:
65
65
  status:
@@ -67,15 +67,15 @@ http_interactions:
67
67
  message: OK
68
68
  headers:
69
69
  Date:
70
- - Fri, 07 Feb 2020 16:22:20 GMT
70
+ - Mon, 10 Feb 2020 17:29:25 GMT
71
71
  Content-Type:
72
72
  - application/vnd.deere.axiom.v3+json;charset=UTF-8
73
73
  X-Deere-Handling-Server:
74
- - ip-10-214-45-139
74
+ - ip-10-214-45-104
75
75
  X-Frame-Options:
76
76
  - SAMEORIGIN
77
77
  X-Deere-Elapsed-Ms:
78
- - '336'
78
+ - '40'
79
79
  Cache-Control:
80
80
  - no-store
81
81
  Content-Language:
@@ -96,7 +96,7 @@ http_interactions:
96
96
  Name","type":"customer","member":true,"id":"000000","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/organizations/000000"},{"@type":"Link","rel":"machines","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines"},{"@type":"Link","rel":"wdtCapableMachines","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines?capability=wdt"},{"@type":"Link","rel":"files","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files"},{"@type":"Link","rel":"transferableFiles","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files?transferable=true"},{"@type":"Link","rel":"uploadFile","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files"},{"@type":"Link","rel":"sendFileToMachine","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fileTransfers"},{"@type":"Link","rel":"addMachine","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines"},{"@type":"Link","rel":"addField","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fields"},{"@type":"Link","rel":"assets","uri":"https://sandboxapi.deere.com/platform/organizations/000000/assets"},{"@type":"Link","rel":"fields","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fields"},{"@type":"Link","rel":"farms","uri":"https://sandboxapi.deere.com/platform/organizations/000000/farms"},{"@type":"Link","rel":"boundaries","uri":"https://sandboxapi.deere.com/platform/organizations/000000/boundaries"},{"@type":"Link","rel":"clients","uri":"https://sandboxapi.deere.com/platform/organizations/000000/clients"},{"@type":"Link","rel":"flags","uri":"https://sandboxapi.deere.com/platform/organizations/000000/flags"},{"@type":"Link","rel":"flagCategory","uri":"https://sandboxapi.deere.com/platform/organizations/000000/flagCategories"},{"@type":"Link","rel":"controllers","uri":"https://sandboxapi.deere.com/platform/organizations/000000/orgController"}]},{"@type":"Organization","name":"Organization
97
97
  Name","type":"customer","member":true,"id":"000000","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/organizations/000000"},{"@type":"Link","rel":"machines","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines"},{"@type":"Link","rel":"wdtCapableMachines","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines?capability=wdt"},{"@type":"Link","rel":"files","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files"},{"@type":"Link","rel":"transferableFiles","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files?transferable=true"},{"@type":"Link","rel":"uploadFile","uri":"https://sandboxapi.deere.com/platform/organizations/000000/files"},{"@type":"Link","rel":"sendFileToMachine","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fileTransfers"},{"@type":"Link","rel":"addMachine","uri":"https://sandboxapi.deere.com/platform/organizations/000000/machines"},{"@type":"Link","rel":"addField","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fields"},{"@type":"Link","rel":"assets","uri":"https://sandboxapi.deere.com/platform/organizations/000000/assets"},{"@type":"Link","rel":"fields","uri":"https://sandboxapi.deere.com/platform/organizations/000000/fields"},{"@type":"Link","rel":"farms","uri":"https://sandboxapi.deere.com/platform/organizations/000000/farms"},{"@type":"Link","rel":"boundaries","uri":"https://sandboxapi.deere.com/platform/organizations/000000/boundaries"},{"@type":"Link","rel":"clients","uri":"https://sandboxapi.deere.com/platform/organizations/000000/clients"},{"@type":"Link","rel":"flags","uri":"https://sandboxapi.deere.com/platform/organizations/000000/flags"},{"@type":"Link","rel":"flagCategory","uri":"https://sandboxapi.deere.com/platform/organizations/000000/flagCategories"},{"@type":"Link","rel":"controllers","uri":"https://sandboxapi.deere.com/platform/organizations/000000/orgController"}]}]}'
98
98
  http_version:
99
- recorded_at: Fri, 07 Feb 2020 16:22:21 GMT
99
+ recorded_at: Mon, 10 Feb 2020 17:29:25 GMT
100
100
  - request:
101
101
  method: post
102
102
  uri: https://sandboxapi.deere.com/platform/organizations/000000/assets
@@ -117,7 +117,7 @@ http_interactions:
117
117
  Authorization:
118
118
  - OAuth oauth_body_hash="hObY6LROUn9S1WS8S28eTTfqmWk%3D", oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
119
119
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
120
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_token="00000000-0000-0000-0000-000000000000",
120
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_token="00000000-0000-0000-0000-000000000000",
121
121
  oauth_version="1.0"
122
122
  response:
123
123
  status:
@@ -125,24 +125,24 @@ http_interactions:
125
125
  message: Created
126
126
  headers:
127
127
  Date:
128
- - Fri, 07 Feb 2020 16:22:22 GMT
128
+ - Mon, 10 Feb 2020 17:29:25 GMT
129
129
  Content-Type:
130
130
  - application/vnd.deere.axiom.v3+json
131
131
  X-Deere-Handling-Server:
132
- - ip-10-214-45-139
132
+ - ip-10-214-45-213
133
133
  X-Frame-Options:
134
134
  - SAMEORIGIN
135
135
  Location:
136
136
  - https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000
137
137
  X-Deere-Elapsed-Ms:
138
- - '51'
138
+ - '121'
139
139
  Transfer-Encoding:
140
140
  - chunked
141
141
  body:
142
142
  encoding: ASCII-8BIT
143
143
  string: ''
144
144
  http_version:
145
- recorded_at: Fri, 07 Feb 2020 16:22:22 GMT
145
+ recorded_at: Mon, 10 Feb 2020 17:29:26 GMT
146
146
  - request:
147
147
  method: get
148
148
  uri: https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000
@@ -161,7 +161,7 @@ http_interactions:
161
161
  Authorization:
162
162
  - OAuth oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
163
163
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
164
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_token="00000000-0000-0000-0000-000000000000",
164
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_token="00000000-0000-0000-0000-000000000000",
165
165
  oauth_version="1.0"
166
166
  response:
167
167
  status:
@@ -169,15 +169,15 @@ http_interactions:
169
169
  message: OK
170
170
  headers:
171
171
  Date:
172
- - Fri, 07 Feb 2020 16:22:22 GMT
172
+ - Mon, 10 Feb 2020 17:29:26 GMT
173
173
  Content-Type:
174
174
  - application/vnd.deere.axiom.v3+json;charset=UTF-8
175
175
  X-Deere-Handling-Server:
176
- - ip-10-214-45-97
176
+ - ip-10-214-44-36
177
177
  X-Frame-Options:
178
178
  - SAMEORIGIN
179
179
  X-Deere-Elapsed-Ms:
180
- - '42'
180
+ - '69'
181
181
  Cache-Control:
182
182
  - no-store
183
183
  Content-Language:
@@ -186,7 +186,7 @@ http_interactions:
186
186
  - chunked
187
187
  body:
188
188
  encoding: ASCII-8BIT
189
- string: '{"@type":"ContributedAsset","title":"Asset Title","assetCategory":"DEVICE","assetType":"SENSOR","assetSubType":"ENVIRONMENTAL","lastModifiedDate":"2020-02-06T22:30:14.000Z","id":"00000000-0000-0000-0000-000000000000","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000"},{"@type":"Link","rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions/00000000-0000-0000-0000-000000000000"},{"@type":"Link","rel":"organization","uri":"https://sandboxapi.deere.com/platform/organizations/000000"},{"@type":"Link","rel":"locations","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000/locations"},{"@type":"Link","rel":"lastKnownLocation","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000/locations?lastKnown=true"}]}'
189
+ string: '{"@type":"ContributedAsset","title":"Asset Title","assetCategory":"DEVICE","assetType":"SENSOR","assetSubType":"ENVIRONMENTAL","lastModifiedDate":"2020-02-10T11:29:32.000Z","id":"00000000-0000-0000-0000-000000000000","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000"},{"@type":"Link","rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions/00000000-0000-0000-0000-000000000000"},{"@type":"Link","rel":"organization","uri":"https://sandboxapi.deere.com/platform/organizations/000000"},{"@type":"Link","rel":"locations","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000/locations"},{"@type":"Link","rel":"lastKnownLocation","uri":"https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000/locations?lastKnown=true"}]}'
190
190
  http_version:
191
- recorded_at: Fri, 07 Feb 2020 16:22:22 GMT
191
+ recorded_at: Mon, 10 Feb 2020 17:29:26 GMT
192
192
  recorded_with: VCR 5.0.0
@@ -16,22 +16,22 @@ http_interactions:
16
16
  Authorization:
17
17
  - OAuth oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
18
18
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
19
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_version="1.0"
19
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_version="1.0"
20
20
  response:
21
21
  status:
22
22
  code: 200
23
23
  message: OK
24
24
  headers:
25
25
  Date:
26
- - Fri, 07 Feb 2020 16:22:26 GMT
26
+ - Mon, 10 Feb 2020 17:29:29 GMT
27
27
  Content-Type:
28
28
  - application/vnd.deere.axiom.v3+json;charset=UTF-8
29
29
  X-Deere-Handling-Server:
30
- - ip-10-214-45-97
30
+ - ip-10-214-45-99
31
31
  X-Frame-Options:
32
32
  - SAMEORIGIN
33
33
  X-Deere-Elapsed-Ms:
34
- - '8'
34
+ - '10'
35
35
  Cache-Control:
36
36
  - no-store
37
37
  Content-Language:
@@ -42,14 +42,14 @@ http_interactions:
42
42
  encoding: ASCII-8BIT
43
43
  string: '{"@type":"ApiCatalog","links":[{"@type":"Link","rel":"oauthRequestToken","uri":"https://sandboxapi.deere.com/platform/oauth/request_token"},{"@type":"Link","rel":"oauthAuthorizeRequestToken","uri":"https://my.deere.com/consentToUseOfData?oauth_token={token}"},{"@type":"Link","rel":"oauthAccessToken","uri":"https://sandboxapi.deere.com/platform/oauth/access_token"},{"@type":"Link","rel":"agencies","uri":"https://sandboxapi.deere.com/platform/agencies"}]}'
44
44
  http_version:
45
- recorded_at: Fri, 07 Feb 2020 16:22:26 GMT
45
+ recorded_at: Mon, 10 Feb 2020 17:29:29 GMT
46
46
  - request:
47
47
  method: put
48
48
  uri: https://sandboxapi.deere.com/platform/assets/00000000-0000-0000-0000-000000000000
49
49
  body:
50
50
  encoding: UTF-8
51
- string: '{"assetCategory":"DEVICE","assetType":"SENSOR","assetSubType":"ENVIRONMENTAL","links":[{"@type":"Link","rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions/00000000-0000-0000-0000-000000000000"}],"title":"i
52
- REALLY like turtles!"}'
51
+ string: '{"assetCategory":"DEVICE","assetType":"SENSOR","assetSubType":"ENVIRONMENTAL","title":"i
52
+ REALLY like turtles!","links":[{"@type":"Link","rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/contributionDefinitions/00000000-0000-0000-0000-000000000000"}]}'
53
53
  headers:
54
54
  Accept:
55
55
  - application/vnd.deere.axiom.v3+json
@@ -60,11 +60,11 @@ http_interactions:
60
60
  User-Agent:
61
61
  - OAuth gem v0.5.4
62
62
  Content-Length:
63
- - '276'
63
+ - '267'
64
64
  Authorization:
65
- - OAuth oauth_body_hash="2cYRiTc%2BBr3sgGXkMJr4suLgHUc%3D", oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
65
+ - OAuth oauth_body_hash="JXqhMr0ayK5gfHyej3M1xuUfSbw%3D", oauth_consumer_key="johndeere-0000000000000000000000000000000000000000",
66
66
  oauth_nonce="000000000000000000000000000000000000000000", oauth_signature="0000000000000000000000000000",
67
- oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581028214", oauth_token="00000000-0000-0000-0000-000000000000",
67
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1581334172", oauth_token="00000000-0000-0000-0000-000000000000",
68
68
  oauth_version="1.0"
69
69
  response:
70
70
  status:
@@ -72,16 +72,16 @@ http_interactions:
72
72
  message: No Content
73
73
  headers:
74
74
  Date:
75
- - Fri, 07 Feb 2020 16:22:26 GMT
75
+ - Mon, 10 Feb 2020 17:29:30 GMT
76
76
  X-Deere-Handling-Server:
77
- - ip-10-214-44-197
77
+ - ip-10-214-44-33
78
78
  X-Frame-Options:
79
79
  - SAMEORIGIN
80
80
  X-Deere-Elapsed-Ms:
81
- - '77'
81
+ - '185'
82
82
  body:
83
83
  encoding: UTF-8
84
84
  string: ''
85
85
  http_version:
86
- recorded_at: Fri, 07 Feb 2020 16:22:27 GMT
86
+ recorded_at: Mon, 10 Feb 2020 17:29:30 GMT
87
87
  recorded_with: VCR 5.0.0
@@ -2,10 +2,14 @@
2
2
  WARNING: Generating VCR cassettes requires the following in your John Deere
3
3
  API sandbox account:
4
4
 
5
- - You must have asset creation/deletion enabled in your account.
6
- - You must have at least one organization created.
7
- - The organization must have at least one field.
8
- - The field must have at least one flag.
5
+ - Environment variables:
6
+ - API_KEY
7
+ - API_SECRET
8
+ - A valid John Deere user account with which you can authenticate.
9
+ - Asset creation/deletion enabled in your JD account.
10
+ - At least one organization created in your JD account.
11
+ - The organization must have at least one field.
12
+ - The field must have at least one flag.
9
13
 
10
14
  By default, this setup will use the first organization returned from the API.
11
15
  If this is not the organization you wish to use, you can create an environment
@@ -16,6 +16,8 @@ class VcrSetup
16
16
  :contribution_product_id, :contribution_definition_id,
17
17
  :placeholders, :organization_id, :asset_id, :field_id, :flag_id
18
18
 
19
+ AUTH_CASSETTES = [:catalog, :get_request_token, :get_access_token]
20
+
19
21
  GENERATED_CASSETTES = [
20
22
  :catalog, :get_request_token, :get_access_token,
21
23
  :get_contribution_products, :get_contribution_product,
@@ -46,40 +48,38 @@ class VcrSetup
46
48
  @field_id = @uuid
47
49
  @flag_id = @uuid
48
50
  @verify_code = 'VERIFY'
49
-
50
- @placeholders = {
51
- API_KEY => @api_key,
52
- API_SECRET => @api_secret,
53
- ACCESS_TOKEN => @access_token,
54
- ACCESS_SECRET => @access_secret
55
- }
51
+ @placeholders = {}
56
52
 
57
53
  unless all_cassettes_generated? || meets_vcr_requirements?
58
54
  raise "Cannot continue until VCR cassettes can be generated."
59
55
  end
60
56
 
61
- set_contribution_product_id
62
- set_contribution_definition_id
63
- set_organization_id
64
-
65
57
  configure_vcr
66
58
 
67
- url
68
-
69
59
  # create and retrieve things
70
60
  unless all_cassettes_generated?
71
61
  puts "\ngenerating:"
72
62
 
73
- GENERATED_CASSETTES.each do |method_name|
74
- filename = "#{method_name}.yml"
63
+ unless ENV['ACCESS_TOKEN'] && ENV['ACCESS_SECRET']
64
+ generate_cassettes(AUTH_CASSETTES)
65
+ end
75
66
 
76
- if File.exist?("#{@vcr_dir}/#{filename}")
77
- puts " - using #{filename}"
78
- else
79
- puts " - generating #{filename}"
80
- VCR.use_cassette(method_name) { send(method_name) }
81
- end
67
+ @placeholders.merge!(
68
+ ENV['API_KEY'] => @api_key,
69
+ ENV['API_SECRET'] => @api_secret,
70
+ ENV['ACCESS_TOKEN'] => @access_token,
71
+ ENV['ACCESS_SECRET'] => @access_secret
72
+ )
73
+
74
+ VCR.use_cassette('temp') do
75
+ set_contribution_product_id
76
+ set_contribution_definition_id
77
+ set_organization_id
82
78
  end
79
+
80
+ File.unlink("#{@vcr_dir}/temp.yml")
81
+
82
+ generate_cassettes(GENERATED_CASSETTES)
83
83
  end
84
84
 
85
85
  sanitize_files
@@ -146,6 +146,16 @@ class VcrSetup
146
146
  }.freeze
147
147
  end
148
148
 
149
+ def sanitized_asset_attributes
150
+ @sanitized_asset_attributes ||= {
151
+ contribution_definition_id: contribution_definition_id,
152
+ title: 'Asset Title',
153
+ asset_category: 'DEVICE',
154
+ asset_type: 'SENSOR',
155
+ asset_sub_type: 'ENVIRONMENTAL'
156
+ }.freeze
157
+ end
158
+
149
159
  def asset_location_attributes
150
160
  @asset_location_attributes ||= {
151
161
  timestamp: timestamp,
@@ -154,8 +164,26 @@ class VcrSetup
154
164
  }.freeze
155
165
  end
156
166
 
167
+ def url
168
+ return @url if defined?(@url)
169
+ @url = JD::Consumer::URLS[:sandbox]
170
+ end
171
+
157
172
  private
158
173
 
174
+ def generate_cassettes(list)
175
+ list.each do |method_name|
176
+ filename = "#{method_name}.yml"
177
+
178
+ if File.exist?("#{@vcr_dir}/#{filename}")
179
+ puts " - using #{filename}"
180
+ else
181
+ puts " - generating #{filename}"
182
+ VCR.use_cassette(method_name) { send(method_name) }
183
+ end
184
+ end
185
+ end
186
+
159
187
  def all_cassettes_generated?
160
188
  return @all_cassettes_generated if defined?(@all_cassettes_generated)
161
189
  @all_cassettes_generated = GENERATED_CASSETTES.all?{|cassette| File.exist?("#{@vcr_dir}/#{cassette}.yml") }
@@ -163,12 +191,12 @@ class VcrSetup
163
191
 
164
192
  # provide a fresh client with no memoized requests
165
193
  def new_client
166
- JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
167
- end
168
-
169
- def url
170
- return @url if defined?(@url)
171
- @url = VCR.use_cassette('url'){ new_client.send(:accessor).consumer.site }
194
+ JD::Client.new(
195
+ ENV['API_KEY'],
196
+ ENV['API_SECRET'],
197
+ environment: :sandbox,
198
+ access: [ENV['ACCESS_TOKEN'], ENV['ACCESS_SECRET']]
199
+ )
172
200
  end
173
201
 
174
202
  def catalog
@@ -176,7 +204,12 @@ class VcrSetup
176
204
  end
177
205
 
178
206
  def get_request_token
179
- @temporary_authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
207
+ @temporary_authorize = JD::Authorize.new(
208
+ ENV['API_KEY'],
209
+ ENV['API_SECRET'],
210
+ environment: :sandbox
211
+ )
212
+
180
213
  @temporary_authorize_url = @temporary_authorize.authorize_url
181
214
  end
182
215
 
@@ -189,6 +222,11 @@ class VcrSetup
189
222
  placeholders[code] = verify_code
190
223
 
191
224
  @temporary_authorize.verify(code)
225
+
226
+ unless ENV['ACCESS_TOKEN'] && ENV['ACCESS_SECRET']
227
+ set_env 'ACCESS_TOKEN', @temporary_authorize.access_token
228
+ set_env 'ACCESS_SECRET', @temporary_authorize.access_secret
229
+ end
192
230
  end
193
231
 
194
232
  def get_contribution_products
@@ -244,7 +282,14 @@ class VcrSetup
244
282
  attrs = asset_attributes.slice(
245
283
  :asset_category, :asset_type, :asset_sub_type, :links
246
284
  ).merge(
247
- title: 'i REALLY like turtles!'
285
+ title: 'i REALLY like turtles!',
286
+ links: [
287
+ {
288
+ '@type' => 'Link',
289
+ 'rel' => 'contributionDefinition',
290
+ 'uri' => "#{url}/contributionDefinitions/#{asset_attributes[:contribution_definition_id]}"
291
+ }
292
+ ]
248
293
  )
249
294
 
250
295
  new_client.put("/assets/#{@temporary_asset_id}", attrs)
@@ -386,7 +431,7 @@ class VcrSetup
386
431
  unless ENV['CONTRIBUTION_PRODUCT_ID']
387
432
  set_env(
388
433
  'CONTRIBUTION_PRODUCT_ID',
389
- client.get('/contributionProducts?clientControlled=true')['values'].first['id']
434
+ new_client.get('/contributionProducts?clientControlled=true')['values'].first['id']
390
435
  )
391
436
  end
392
437
 
@@ -397,7 +442,7 @@ class VcrSetup
397
442
  unless ENV['CONTRIBUTION_DEFINITION_ID']
398
443
  set_env(
399
444
  'CONTRIBUTION_DEFINITION_ID',
400
- client.get("/contributionProducts/#{ENV['CONTRIBUTION_PRODUCT_ID']}/contributionDefinitions")['values'].first['id']
445
+ new_client.get("/contributionProducts/#{ENV['CONTRIBUTION_PRODUCT_ID']}/contributionDefinitions")['values'].first['id']
401
446
  )
402
447
  end
403
448
 
@@ -408,7 +453,7 @@ class VcrSetup
408
453
  unless ENV['ORGANIZATION_ID']
409
454
  set_env(
410
455
  'ORGANIZATION_ID',
411
- client.get("/organizations")['values'].first['id']
456
+ new_client.get("/organizations")['values'].first['id']
412
457
  )
413
458
  end
414
459
 
@@ -416,6 +461,8 @@ class VcrSetup
416
461
  end
417
462
 
418
463
  def set_env(name, value)
464
+ puts "SAVING ENVIRONMENT VARIABLE: #{name}: #{value.inspect}"
465
+
419
466
  ENV[name] = value
420
467
  File.open('.env', 'a') { |f| f.puts "#{name}=#{value}"}
421
468
  end
@@ -429,6 +476,13 @@ class VcrSetup
429
476
  end
430
477
 
431
478
  def meets_vcr_requirements?
479
+ missing_env_vars = ['API_KEY', 'API_SECRET'].reject{|var| ENV[var]}
480
+
481
+ unless missing_env_vars.empty?
482
+ puts "The following required environment variables are missing: #{missing_env_vars.join(', ')}"
483
+ return false
484
+ end
485
+
432
486
  puts File.read("#{@vcr_dir}/warning.txt")
433
487
  $stdout.print("Do you meet the requirements? [y/N]: "); $stdout.flush
434
488