my_john_deere_api 0.7.0 → 0.7.1
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: 2baeafd63d0b06c78bd534c4e88938620bb2d0baa0c19f69493303a02159db8d
|
4
|
+
data.tar.gz: 4f1f09b26eff60c313d377c61971a96262d25ccf3c3a5e143a9bcf7ec13b5374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c87ff1c342ab2e1d363efb72cda2a40fdb465e98be34a22d1a22f0ae9014da13134a808fc88e3800fae1203e94ad7b772fd2346ae97245daafeb8c1cda50a4
|
7
|
+
data.tar.gz: bc8b999834e472b36656bcb70c55671e4962ae4a70ac68f3ba4ca04fedee7f678d658b2ad1f744e57a476a6e8733bb56cdff7fed91bd88fe1f1ac364e4cc2d26
|
@@ -15,5 +15,13 @@ module MyJohnDeereApi::Request
|
|
15
15
|
def model
|
16
16
|
MyJohnDeereApi::Model::AssetLocation
|
17
17
|
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Create a new asset location
|
21
|
+
|
22
|
+
def create(attributes)
|
23
|
+
attributes.merge!(asset_id: associations[:asset])
|
24
|
+
Create::AssetLocation.new(accessor, attributes).object
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
@@ -65,11 +65,19 @@ module MyJohnDeereApi
|
|
65
65
|
# our timestamp, which must be unique.
|
66
66
|
|
67
67
|
path = response['location'].split('/platform').last
|
68
|
+
|
69
|
+
# API will only accept a timestamp *range*, and the start must be lower
|
70
|
+
# than the end. We buffer start/end times by one second, then find the
|
71
|
+
# exact match.
|
68
72
|
start_date = timestamp_add(timestamp, -1)
|
69
73
|
end_date = timestamp_add(timestamp, 1)
|
70
74
|
path += "?startDate=#{start_date}&endDate=#{end_date}"
|
75
|
+
|
71
76
|
result = accessor.get(path, headers)
|
72
77
|
|
78
|
+
# Timestamps are returned with seconds in decimals, even though these
|
79
|
+
# are always zero. So we compare actual DateTime objects parsed from
|
80
|
+
# the timestamp strings.
|
73
81
|
parsed_stamp = DateTime.parse(timestamp)
|
74
82
|
|
75
83
|
JSON.parse(result.body)['values'].detect do |record|
|
@@ -46,6 +46,51 @@ describe 'MyJohnDeereApi::Request::Collection::AssetLocations' do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe '#create(attributes)' do
|
50
|
+
let(:asset_id) { ENV['ASSET_ID'] }
|
51
|
+
let(:timestamp) { DateTime.parse(timestamp_string) }
|
52
|
+
let(:timestamp_string) { '2020-01-18T00:31:00Z' }
|
53
|
+
|
54
|
+
let(:geometry) do
|
55
|
+
{
|
56
|
+
type: 'Point',
|
57
|
+
coordinates: [-103.115633, 41.670166]
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:measurement_data) do
|
62
|
+
[
|
63
|
+
{
|
64
|
+
name: 'Temperature',
|
65
|
+
value: '68.0',
|
66
|
+
unit: 'F'
|
67
|
+
}
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'creates a new asset with the given attributes' do
|
72
|
+
attributes = {
|
73
|
+
timestamp: timestamp,
|
74
|
+
geometry: geometry,
|
75
|
+
measurement_data: measurement_data
|
76
|
+
}
|
77
|
+
|
78
|
+
object = VCR.use_cassette('post_asset_locations') { collection.create(attributes) }
|
79
|
+
|
80
|
+
assert_kind_of JD::Model::AssetLocation, object
|
81
|
+
|
82
|
+
# API returns seconds with decimals, even though they're always zero
|
83
|
+
integer_stamp = DateTime.parse(object.timestamp).strftime('%Y-%m-%dT%H:%M:%SZ')
|
84
|
+
|
85
|
+
# API returns string keys and an extra '@type' key
|
86
|
+
object_measurement_data = object.measurement_data.first.transform_keys{|k| k.to_sym}.slice(:name, :value, :unit)
|
87
|
+
|
88
|
+
assert_equal timestamp_string, integer_stamp
|
89
|
+
assert_equal geometry.to_json, object.geometry.to_json
|
90
|
+
assert_equal measurement_data.first, object_measurement_data
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
49
94
|
describe '#count' do
|
50
95
|
let(:server_response) do
|
51
96
|
contents = File.read('test/support/vcr/get_asset_locations.yml')
|