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: d022fff0506123f5684e53e1365c9c72cd55225368bb7303db30f74e8c3bc651
4
- data.tar.gz: d6ab2cabe0386168c984ddfcfbf6aa7ff1ac4a73b8cde4cd379ba9849fbe4e96
3
+ metadata.gz: 2baeafd63d0b06c78bd534c4e88938620bb2d0baa0c19f69493303a02159db8d
4
+ data.tar.gz: 4f1f09b26eff60c313d377c61971a96262d25ccf3c3a5e143a9bcf7ec13b5374
5
5
  SHA512:
6
- metadata.gz: 0d0815d5d7634f901741c073680769d663161cc3d959cbf914bfef8fd1f799603bb38fd2e9964700b1d421fc10929fb9ae869c763058998eff091a131ad25ae5
7
- data.tar.gz: 496c89a2ff02d8eb0ea3edd05f03889863b6c444f4aea19d3752d69dae6904bb530ee1e6d58c1f3aab3cd9c432138f35b045d58b71eb556a74b60ecf9e69e8a7
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|
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.7.0'
2
+ VERSION='0.7.1'
3
3
  end
@@ -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')
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: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime. Bellmyer