my_john_deere_api 2.0.0 → 2.1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d5b6f6ff281312c3efbe68e816e2269a173fff59d55f39e9269d820affa7875
|
4
|
+
data.tar.gz: 9d84f97611bffd3c251bb1ffd1b277451b0b1486abfd67645666081f41253205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb4d195bfce24eda5d4de27a35170fc884fbccc101f91691765429c57031ebb75597b3454d93d52a1dbf81464a699af6507ab2dc7237f5b03583fdb608dbc61b
|
7
|
+
data.tar.gz: 5cacd41ef1c3ba3ffd5551d8a1d28839f7bc073a949913f7b58300d8cb9607bbe7e9433503b2aa3d28bf02b80ddd9491b2f7af6afe21a548154d394031a8725a
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module MyJohnDeereApi
|
2
2
|
class Model::Asset < Model::Base
|
3
|
+
include Helpers::CaseConversion
|
4
|
+
|
3
5
|
attr_reader :title, :asset_category, :asset_type, :asset_sub_type, :last_modified_date
|
4
6
|
|
5
7
|
##
|
@@ -11,10 +13,19 @@ module MyJohnDeereApi
|
|
11
13
|
title: title,
|
12
14
|
asset_category: asset_category,
|
13
15
|
asset_type: asset_type,
|
14
|
-
asset_sub_type: asset_sub_type
|
16
|
+
asset_sub_type: asset_sub_type,
|
17
|
+
organization_id: 'placeholder'
|
15
18
|
}
|
16
19
|
end
|
17
20
|
|
21
|
+
##
|
22
|
+
# Update the attributes in John Deere
|
23
|
+
|
24
|
+
def update new_attributes
|
25
|
+
map_attributes(camelize(new_attributes))
|
26
|
+
Request::Update::Asset.new(client, self, attributes).request
|
27
|
+
end
|
28
|
+
|
18
29
|
##
|
19
30
|
# locations associated with this asset
|
20
31
|
|
@@ -22,17 +33,17 @@ module MyJohnDeereApi
|
|
22
33
|
raise AccessTokenError unless accessor
|
23
34
|
|
24
35
|
return @locations if defined?(@locations)
|
25
|
-
@locations =
|
36
|
+
@locations = Request::Collection::AssetLocations.new(client, asset: id)
|
26
37
|
end
|
27
38
|
|
28
39
|
private
|
29
40
|
|
30
41
|
def map_attributes(record)
|
31
|
-
@title = record['title']
|
32
|
-
@asset_category = record['assetCategory']
|
33
|
-
@asset_type = record['assetType']
|
34
|
-
@asset_sub_type = record['assetSubType']
|
35
|
-
@last_modified_date = record['lastModifiedDate']
|
42
|
+
@title = record['title'] if record['title']
|
43
|
+
@asset_category = record['assetCategory'] if record['assetCategory']
|
44
|
+
@asset_type = record['assetType'] if record['assetType']
|
45
|
+
@asset_sub_type = record['assetSubType'] if record['assetSubType']
|
46
|
+
@last_modified_date = record['lastModifiedDate'] if record['lastModifiedDate']
|
36
47
|
end
|
37
48
|
|
38
49
|
def expected_record_type
|
@@ -10,7 +10,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
10
10
|
"assetCategory"=>"DEVICE",
|
11
11
|
"assetType"=>"SENSOR",
|
12
12
|
"assetSubType"=>"OTHER",
|
13
|
-
"id"=>
|
13
|
+
"id"=>asset_id,
|
14
14
|
"lastModifiedDate"=>"2018-01-31T20:36:16.727Z",
|
15
15
|
"links"=>[
|
16
16
|
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}"},
|
@@ -54,7 +54,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
54
54
|
|
55
55
|
describe '#attributes' do
|
56
56
|
it 'converts properties back to an attributes hash' do
|
57
|
-
asset = klass.new(record)
|
57
|
+
asset = klass.new(record, client)
|
58
58
|
attributes = asset.attributes
|
59
59
|
|
60
60
|
assert_equal asset.id, attributes[:id]
|
@@ -65,6 +65,27 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe '#update' do
|
69
|
+
it 'updates the attributes' do
|
70
|
+
asset = klass.new(record, client)
|
71
|
+
|
72
|
+
new_title = 'i REALLY like turtles!'
|
73
|
+
VCR.use_cassette('put_asset') { asset.update(title: new_title) }
|
74
|
+
|
75
|
+
assert_equal new_title, asset.title
|
76
|
+
assert_equal new_title, asset.attributes[:title]
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'sends the update to John Deere' do
|
80
|
+
asset = klass.new(record, client)
|
81
|
+
|
82
|
+
new_title = 'i REALLY like turtles!'
|
83
|
+
response = VCR.use_cassette('put_asset') { asset.update(title: new_title) }
|
84
|
+
|
85
|
+
assert_kind_of Net::HTTPNoContent, response
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
68
89
|
describe '#locations' do
|
69
90
|
it 'returns a collection of locations for this asset' do
|
70
91
|
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|