my_john_deere_api 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9478ddbe0b4aa4f4e1d20f822db028cbc13154cd158b2cf937be9a18d4279a
|
4
|
+
data.tar.gz: ca8f3397f9d3ec5156c7a346d77c719e3ef427c166c6aa8d6db1a8ba8269c35f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f910a45e19494e09476f2cb506403e94df8eb86eb6816db23d6d2aeabe02a6ddff7ec5e4bdc35a59b3d2a53857a2cf86949ed1109c19490149ca5857d158bbe
|
7
|
+
data.tar.gz: a10d6662be6a6fd3d63acc2e8e5c6bbd41fe4e74243c5f0ad3c41aef6dcf65f740be5507e761723da879a380fcfbe9b9744dac8a79024882632c1f1300371229
|
@@ -10,13 +10,11 @@ module MyJohnDeereApi
|
|
10
10
|
def request_body
|
11
11
|
return @body if defined?(@body)
|
12
12
|
|
13
|
-
@body = [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
]
|
13
|
+
@body = [{
|
14
|
+
timestamp: timestamp,
|
15
|
+
geometry: geometry,
|
16
|
+
measurementData: attributes[:measurement_data]
|
17
|
+
}]
|
20
18
|
end
|
21
19
|
|
22
20
|
##
|
@@ -25,6 +23,8 @@ module MyJohnDeereApi
|
|
25
23
|
def timestamp
|
26
24
|
return @timestamp if defined?(@timestamp)
|
27
25
|
|
26
|
+
attributes[:timestamp] ||= Time.now.utc
|
27
|
+
|
28
28
|
@timestamp = attributes[:timestamp].is_a?(String) ?
|
29
29
|
attributes[:timestamp] :
|
30
30
|
attributes[:timestamp].strftime('%Y-%m-%dT%H:%M:%SZ')
|
@@ -36,9 +36,29 @@ module MyJohnDeereApi
|
|
36
36
|
def geometry
|
37
37
|
return @geometry if defined?(@geometry)
|
38
38
|
|
39
|
-
@geometry = attributes[:geometry]
|
40
|
-
attributes[:geometry]
|
41
|
-
|
39
|
+
@geometry = if attributes[:geometry]
|
40
|
+
attributes[:geometry].is_a?(String) ?
|
41
|
+
attributes[:geometry] :
|
42
|
+
attributes[:geometry].to_json
|
43
|
+
elsif attributes[:coordinates]
|
44
|
+
geometry_from_coordinates
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Convert just coordinates into valid geometry hash
|
50
|
+
|
51
|
+
def geometry_from_coordinates
|
52
|
+
{
|
53
|
+
type: 'Feature',
|
54
|
+
geometry: {
|
55
|
+
geometries: [
|
56
|
+
coordinates: attributes[:coordinates],
|
57
|
+
type: 'Point'
|
58
|
+
],
|
59
|
+
type: 'GeometryCollection'
|
60
|
+
}
|
61
|
+
}.to_json
|
42
62
|
end
|
43
63
|
|
44
64
|
##
|
@@ -54,6 +54,40 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
|
|
54
54
|
object = JD::Request::Create::AssetLocation.new(accessor, {})
|
55
55
|
assert_equal({}, object.errors)
|
56
56
|
end
|
57
|
+
|
58
|
+
it 'accepts simple coordinates and generates the geometry' do
|
59
|
+
attributes = {
|
60
|
+
asset_id: asset_id,
|
61
|
+
timestamp: timestamp,
|
62
|
+
coordinates: geometry[:coordinates],
|
63
|
+
measurement_data: measurement_data
|
64
|
+
}
|
65
|
+
|
66
|
+
object = JD::Request::Create::AssetLocation.new(accessor, attributes)
|
67
|
+
|
68
|
+
expected_geometry = {
|
69
|
+
type: 'Feature',
|
70
|
+
geometry: {
|
71
|
+
geometries: [
|
72
|
+
coordinates: geometry[:coordinates],
|
73
|
+
type: 'Point'
|
74
|
+
],
|
75
|
+
type: 'GeometryCollection'
|
76
|
+
}
|
77
|
+
}.to_json
|
78
|
+
|
79
|
+
assert_equal expected_geometry, object.send(:geometry)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'defaults timestamp to current time' do
|
83
|
+
attributes = valid_attributes.slice(:asset_id, :geometry, :measurement_data)
|
84
|
+
object = JD::Request::Create::AssetLocation.new(accessor, attributes)
|
85
|
+
|
86
|
+
expected_stamp = Time.now.utc.to_i
|
87
|
+
actual_stamp = DateTime.parse(object.send(:timestamp)).to_time.to_i
|
88
|
+
|
89
|
+
assert_in_delta expected_stamp, actual_stamp, 1
|
90
|
+
end
|
57
91
|
end
|
58
92
|
|
59
93
|
describe '#valid?' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime. Bellmyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vcr
|