my_john_deere_api 0.10.4 → 0.11.0
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 +4 -4
- data/lib/my_john_deere_api/request/collection/assets.rb +7 -0
- data/lib/my_john_deere_api/request/individual/asset.rb +19 -0
- data/lib/my_john_deere_api/request/individual/base.rb +43 -0
- data/lib/my_john_deere_api/request/individual.rb +4 -0
- data/lib/my_john_deere_api/request.rb +1 -0
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +9 -0
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +35 -0
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +20 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +13 -0
- data/test/lib/my_john_deere_api/request_test.rb +4 -0
- data/test/support/vcr/get_asset.yml +47 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e13eed76fb39d6bd0905710f9fdfdd5ce55d9a942f241adcd757cb5390ba3107
|
4
|
+
data.tar.gz: f14973d9655407f66123cf3829bfa37e3d4a8a75f5221cf6745d4b2c64461fbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69774e1c0b8cc27697a7d6c51a922f84559e9cfaf3e0b799f86d6abb688422aa3807bbda82512bcf595803eef24b848fe1b26729262bdaa1277dd533425e1843
|
7
|
+
data.tar.gz: f5d9513614d9d5230883668364841b85a28d3603e0eff718065de0bf81d9d38c047a13f639ba6355d39c3b85d2904d6b473959c4e743d506df26da81edb55c47
|
@@ -23,5 +23,12 @@ module MyJohnDeereApi::Request
|
|
23
23
|
attributes.merge!(organization_id: associations[:organization])
|
24
24
|
Create::Asset.new(accessor, attributes).object
|
25
25
|
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Retrieve an asset from JD
|
29
|
+
|
30
|
+
def find(asset_id)
|
31
|
+
Individual::Asset.new(accessor, asset_id).object
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Request
|
4
|
+
class Individual::Asset < Individual::Base
|
5
|
+
##
|
6
|
+
# The resource path for the first page in the collection
|
7
|
+
|
8
|
+
def resource
|
9
|
+
"/assets/#{id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# This is the class used to model the data
|
14
|
+
|
15
|
+
def model
|
16
|
+
MyJohnDeereApi::Model::Asset
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Request
|
4
|
+
class Individual::Base
|
5
|
+
attr_reader :accessor, :id, :response
|
6
|
+
|
7
|
+
##
|
8
|
+
# Initialize with an accessor, and asset id
|
9
|
+
|
10
|
+
def initialize(accessor, id)
|
11
|
+
@accessor = accessor
|
12
|
+
@id = id
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# The object being requested, an asset in this case
|
17
|
+
|
18
|
+
def object
|
19
|
+
return @object if defined?(@object)
|
20
|
+
|
21
|
+
request unless response
|
22
|
+
@object = model.new(JSON.parse(response.body), accessor)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
##
|
28
|
+
# Make the request
|
29
|
+
|
30
|
+
def request
|
31
|
+
@response = accessor.get(resource, headers)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Headers for GET request
|
36
|
+
|
37
|
+
def headers
|
38
|
+
@headers ||= {
|
39
|
+
'Accept' => 'application/vnd.deere.axiom.v3+json',
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -73,6 +73,15 @@ describe 'MyJohnDeereApi::Request::Collection::Assets' do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
describe '#find(asset_id)' do
|
77
|
+
let(:asset_id) { '123' }
|
78
|
+
|
79
|
+
it 'retrieves the asset' do
|
80
|
+
asset = VCR.use_cassette('get_asset') { collection.find(asset_id) }
|
81
|
+
assert_kind_of JD::Model::Asset, asset
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
76
85
|
describe '#count' do
|
77
86
|
let(:server_response) do
|
78
87
|
contents = File.read('test/support/vcr/get_assets.yml')
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::Asset' do
|
6
|
+
let(:asset_id) { '123' }
|
7
|
+
let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
|
8
|
+
let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
|
9
|
+
let(:object) { JD::Request::Individual::Asset.new(accessor, asset_id) }
|
10
|
+
|
11
|
+
inherits_from JD::Request::Individual::Base
|
12
|
+
|
13
|
+
describe '#initialize(access_token, asset_id)' do
|
14
|
+
it 'accepts an access token' do
|
15
|
+
assert_equal accessor, object.accessor
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts asset_id as id' do
|
19
|
+
assert_equal asset_id, object.id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#resource' do
|
24
|
+
it 'returns /assets/<asset_id>' do
|
25
|
+
assert_equal "/assets/#{asset_id}", object.resource
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#object' do
|
30
|
+
it 'returns all records' do
|
31
|
+
asset = VCR.use_cassette('get_asset') { object.object }
|
32
|
+
assert_kind_of JD::Model::Asset, asset
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe 'MyJohnDeereApi::Request::Individual::Base' do
|
6
|
+
let(:asset_id) { '123' }
|
7
|
+
let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
|
8
|
+
let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
|
9
|
+
let(:object) { JD::Request::Individual::Base.new(accessor, asset_id) }
|
10
|
+
|
11
|
+
describe '#initialize(access_token, asset_id)' do
|
12
|
+
it 'accepts an access token' do
|
13
|
+
assert_equal accessor, object.accessor
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts asset_id as id' do
|
17
|
+
assert_equal asset_id, object.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Request::Individual' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads Request::Individual::Base' do
|
6
|
+
assert JD::Request::Individual::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads Request::Individual::Asset' do
|
10
|
+
assert JD::Request::Individual::Asset
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://sandboxapi.deere.com/platform/assets/123
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.deere.axiom.v3+json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
User-Agent:
|
15
|
+
- OAuth gem v0.5.4
|
16
|
+
Authorization:
|
17
|
+
- OAuth oauth_consumer_key="johndeere-wgmADngYCRmfpEbVgSyc709wnyRux5J7PAv8SE7B",
|
18
|
+
oauth_nonce="wpd9q6hPqIv2ILaJ7pysF1N6HLOSthgHDJNDhY4E", oauth_signature="SSCyoTnFLevnU28iQ%2BqArIAprHs%3D",
|
19
|
+
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1580161758", oauth_token="47bbb9c9-41a8-4bec-8127-e3c5760af2f6",
|
20
|
+
oauth_version="1.0"
|
21
|
+
response:
|
22
|
+
status:
|
23
|
+
code: 200
|
24
|
+
message: OK
|
25
|
+
headers:
|
26
|
+
Date:
|
27
|
+
- Mon, 27 Jan 2020 21:49:18 GMT
|
28
|
+
Content-Type:
|
29
|
+
- application/vnd.deere.axiom.v3+json;charset=UTF-8
|
30
|
+
X-Deere-Handling-Server:
|
31
|
+
- ip-10-214-45-211
|
32
|
+
X-Frame-Options:
|
33
|
+
- SAMEORIGIN
|
34
|
+
X-Deere-Elapsed-Ms:
|
35
|
+
- '60'
|
36
|
+
Cache-Control:
|
37
|
+
- no-store
|
38
|
+
Content-Language:
|
39
|
+
- en-US
|
40
|
+
Transfer-Encoding:
|
41
|
+
- chunked
|
42
|
+
body:
|
43
|
+
encoding: ASCII-8BIT
|
44
|
+
string: '{"@type":"ContributedAsset","title":"Flex (Watermark)","assetCategory":"DEVICE","assetType":"SENSOR","assetSubType":"ENVIRONMENTAL","lastModifiedDate":"2019-09-20T21:13:38.232Z","id":"029c288a-14d9-459f-8ee6-b4e840e672a1","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/assets/029c288a-14d9-459f-8ee6-b4e840e672a1"},{"@type":"Link","rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions/d93611c7-6f74-474f-9569-2cf88f866a32"},{"@type":"Link","rel":"organization","uri":"https://sandboxapi.deere.com/platform/organizations/444563"},{"@type":"Link","rel":"locations","uri":"https://sandboxapi.deere.com/platform/assets/029c288a-14d9-459f-8ee6-b4e840e672a1/locations"},{"@type":"Link","rel":"lastKnownLocation","uri":"https://sandboxapi.deere.com/platform/assets/029c288a-14d9-459f-8ee6-b4e840e672a1/locations?lastKnown=true"}]}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 27 Jan 2020 21:49:18 GMT
|
47
|
+
recorded_with: VCR 5.0.0
|
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.
|
4
|
+
version: 0.11.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: 2020-01-
|
12
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vcr
|
@@ -132,6 +132,9 @@ files:
|
|
132
132
|
- lib/my_john_deere_api/request/create/asset.rb
|
133
133
|
- lib/my_john_deere_api/request/create/asset_location.rb
|
134
134
|
- lib/my_john_deere_api/request/create/base.rb
|
135
|
+
- lib/my_john_deere_api/request/individual.rb
|
136
|
+
- lib/my_john_deere_api/request/individual/asset.rb
|
137
|
+
- lib/my_john_deere_api/request/individual/base.rb
|
135
138
|
- lib/my_john_deere_api/version.rb
|
136
139
|
- test/lib/my_john_deere_api/authorize_test.rb
|
137
140
|
- test/lib/my_john_deere_api/client_test.rb
|
@@ -161,6 +164,9 @@ files:
|
|
161
164
|
- test/lib/my_john_deere_api/request/create/asset_test.rb
|
162
165
|
- test/lib/my_john_deere_api/request/create/base_test.rb
|
163
166
|
- test/lib/my_john_deere_api/request/create_test.rb
|
167
|
+
- test/lib/my_john_deere_api/request/individual/asset_test.rb
|
168
|
+
- test/lib/my_john_deere_api/request/individual/base_test.rb
|
169
|
+
- test/lib/my_john_deere_api/request/individual_test.rb
|
164
170
|
- test/lib/my_john_deere_api/request_test.rb
|
165
171
|
- test/lib/my_john_deere_api/version_test.rb
|
166
172
|
- test/my_john_deere_api_test.rb
|
@@ -169,6 +175,7 @@ files:
|
|
169
175
|
- test/support/vcr/catalog.yml
|
170
176
|
- test/support/vcr/delete_asset.yml
|
171
177
|
- test/support/vcr/get_access_token.yml
|
178
|
+
- test/support/vcr/get_asset.yml
|
172
179
|
- test/support/vcr/get_asset_locations.yml
|
173
180
|
- test/support/vcr/get_assets.yml
|
174
181
|
- test/support/vcr/get_fields.yml
|