my_john_deere_api 2.1.1 → 2.2.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: 3f611ef5d6785246196c22bc5e453374da5a4a513a689ad649ba1907de39c93f
|
4
|
+
data.tar.gz: 773b32b36229740d1d7885f4e8728cff83f32cb7b19d1ae65847b1bbdd8bea4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cd73bbcea8e2615b5bbf4bbf4c91531a991b5c09566f1e7917fbb77d26309b9d4b8f5c532f081c3dd0f463e004ea716f687b2a953420798a7f71f98ee5de16e
|
7
|
+
data.tar.gz: 316d9852d79c9f86c6ec55b6bf5417dcaf47ca06da5eb391b79e19d18c9e20541c625aaa098102dec981ade2e503c673f10267a263069d2f355fcdd06ff46a11
|
data/README.md
CHANGED
@@ -154,6 +154,7 @@ client
|
|
154
154
|
| ├── all
|
155
155
|
| ├── first
|
156
156
|
| └── find(asset_id)
|
157
|
+
| ├── save
|
157
158
|
| ├── update(attributes)
|
158
159
|
| └── locations
|
159
160
|
| ├── create(attributes)
|
@@ -381,6 +382,14 @@ asset.title
|
|
381
382
|
# => 'New Title', also John Deere record is updated
|
382
383
|
```
|
383
384
|
|
385
|
+
The `save` method updates John Deere with any local changes that have been made.
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
asset.title = 'New Title'
|
389
|
+
asset.save
|
390
|
+
# => Successful Net::HTTPNoContent object
|
391
|
+
```
|
392
|
+
|
384
393
|
|
385
394
|
### Direct API Requests
|
386
395
|
|
@@ -18,6 +18,24 @@ module MyJohnDeereApi
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
+
##
|
22
|
+
# Change the title, locally
|
23
|
+
|
24
|
+
def title=(value)
|
25
|
+
mark_as_unsaved
|
26
|
+
@title = value
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Save any attribute changes to John Deere
|
31
|
+
|
32
|
+
def save
|
33
|
+
if unsaved?
|
34
|
+
mark_as_saved
|
35
|
+
Request::Update::Asset.new(client, self, attributes).request
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
21
39
|
##
|
22
40
|
# Update the attributes in John Deere
|
23
41
|
|
@@ -21,6 +21,7 @@ module MyJohnDeereApi
|
|
21
21
|
@id = record['id']
|
22
22
|
@record_type = record['@type']
|
23
23
|
@client = client
|
24
|
+
@unsaved = false
|
24
25
|
|
25
26
|
map_attributes(record)
|
26
27
|
|
@@ -65,5 +66,32 @@ module MyJohnDeereApi
|
|
65
66
|
raise TypeMismatchError, "Expected record of type '#{expected_record_type}', but received type '#{type}'"
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Mark as unsaved, so we know to save it later
|
72
|
+
|
73
|
+
def mark_as_unsaved
|
74
|
+
@unsaved = true
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Mark as saved, so we don't try to save it later
|
79
|
+
|
80
|
+
def mark_as_saved
|
81
|
+
@unsaved = false
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Are changes to this model synced with JD?
|
86
|
+
def saved?
|
87
|
+
!@unsaved
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Are there pending changes to send to JD?
|
92
|
+
|
93
|
+
def unsaved?
|
94
|
+
@unsaved
|
95
|
+
end
|
68
96
|
end
|
69
97
|
end
|
@@ -65,6 +65,37 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe '#save' do
|
69
|
+
it 'sends any recent updates to John Deere' do
|
70
|
+
asset = klass.new(record, client)
|
71
|
+
new_title = 'i REALLY like turtles!'
|
72
|
+
|
73
|
+
asset.title = new_title
|
74
|
+
assert_equal new_title, asset.title
|
75
|
+
|
76
|
+
response = VCR.use_cassette('put_asset') { asset.save }
|
77
|
+
assert_kind_of Net::HTTPNoContent, response
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'does not make a JD request if nothing has changed' do
|
81
|
+
asset = klass.new(record, client)
|
82
|
+
response = asset.save
|
83
|
+
|
84
|
+
assert_nil response
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'marks the record as saved' do
|
88
|
+
asset = klass.new(record, client)
|
89
|
+
asset.title = 'i REALLY like turtles!'
|
90
|
+
|
91
|
+
response = VCR.use_cassette('put_asset') { asset.save }
|
92
|
+
assert_kind_of Net::HTTPNoContent, response
|
93
|
+
|
94
|
+
response = asset.save
|
95
|
+
assert_nil response
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
68
99
|
describe '#update' do
|
69
100
|
it 'updates the attributes' do
|
70
101
|
asset = klass.new(record, client)
|