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: 12dd779b0061a90ac8b9d20b3a5111fe1b8f76ebf4153817480abe886a4d45f0
4
- data.tar.gz: 8d4bf6db2d2dd9a720c500c0300ff9409766ed639f3191154de6319bae5d171e
3
+ metadata.gz: 1d5b6f6ff281312c3efbe68e816e2269a173fff59d55f39e9269d820affa7875
4
+ data.tar.gz: 9d84f97611bffd3c251bb1ffd1b277451b0b1486abfd67645666081f41253205
5
5
  SHA512:
6
- metadata.gz: 5af6c3d0843479c8c05cdc36f3cbb1645b26a76e41de187ff513ba78089586c1a890c229918a39ffc3599b4f989b718a288a78f208f72fcd8027dccb2381861b
7
- data.tar.gz: 59e8a16606a6b002b91970745894759af3e69d0a674dd1e01f2099acf4836ed61afabcaba9ffbe298f40ac71ca078a5d614923a095864db6ecc9998a1ad2a669
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 = MyJohnDeereApi::Request::Collection::AssetLocations.new(client, asset: id)
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
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='2.0.0'
2
+ VERSION='2.1.0'
3
3
  end
@@ -10,7 +10,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
10
10
  "assetCategory"=>"DEVICE",
11
11
  "assetType"=>"SENSOR",
12
12
  "assetSubType"=>"OTHER",
13
- "id"=>"123456",
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 }
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer