my_john_deere_api 0.5.1 → 0.5.2

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: 73cbc5de675267d73f21bf1adc0624236ad833ff0e7174dcec7e7198d9b1d1cb
4
- data.tar.gz: '0840ae125650b4f307f74e21b4b255d5bc50878fd748ec1e1835bbf2e17c885c'
3
+ metadata.gz: 4517a78430360d8ba494a5e64a206eb6924cd9ee1d9c1bcdfff6a823f17496e8
4
+ data.tar.gz: a0788ce8e4ead19974e675dbca2bf515ab530aaa0cfc561c914ab23651767d93
5
5
  SHA512:
6
- metadata.gz: 07e8d738e0ecc1e3ba071cf4e09d61be831e8851c190bc805d9cc11903a445126d0a66f5c414043d4cea3bf203c014d8bd377bde18ea79ba6312fbeda3a061d7
7
- data.tar.gz: d590a803bf509ac80ff6dc3ab1645ccacc580a733ca9cf8d53bb6d5e7ea1cfd4f2d61a6fc495ca7dc8d509fc1dede65307dbd59cb0024dd4b65d1f466e2d5af8
6
+ metadata.gz: 8baaae2f1eb4d639b31b85d0a5450fd46442d31e88f2f3495465774fd445370c0433d43ef4d0a76abb61d6495ff9bc573e4185a19fda71e3b018000ddb18eaf7
7
+ data.tar.gz: 2a8e2e13cdd2ed7687fba31a10f61c7153198925120132743db6c15f857a323a822256159b1987682fab5e237ad475cd79882bc390e48552d6fdc070da21cfd0
@@ -21,5 +21,9 @@ module MyJohnDeereApi
21
21
  @asset_sub_type = record['assetSubType']
22
22
  @last_modified_date = record['lastModifiedDate']
23
23
  end
24
+
25
+ def expected_record_type
26
+ 'ContributedAsset'
27
+ end
24
28
  end
25
29
  end
@@ -11,5 +11,9 @@ module MyJohnDeereApi
11
11
  @geometry = JSON.parse(record['geometry'])
12
12
  @measurement_data = record['measurementData']
13
13
  end
14
+
15
+ def expected_record_type
16
+ 'ContributedAssetLocation'
17
+ end
14
18
  end
15
19
  end
@@ -15,6 +15,8 @@ module MyJohnDeereApi
15
15
  # to be made, as is the case with *flags*.
16
16
 
17
17
  def initialize(record, accessor = nil)
18
+ verify_record_type(record['@type'])
19
+
18
20
  @id = record['id']
19
21
  @record_type = record['@type']
20
22
  @accessor = accessor
@@ -45,5 +47,14 @@ module MyJohnDeereApi
45
47
  def expected_record_type
46
48
  'Base'
47
49
  end
50
+
51
+ ##
52
+ # Raise an error if this is not the type of record we expect to receive
53
+
54
+ def verify_record_type(type)
55
+ unless type == expected_record_type
56
+ raise TypeMismatchError, "Expected record of type '#{expected_record_type}', but received type '#{type}'"
57
+ end
58
+ end
48
59
  end
49
60
  end
@@ -27,6 +27,10 @@ module MyJohnDeereApi
27
27
  @archived = record['archived']
28
28
  end
29
29
 
30
+ def expected_record_type
31
+ 'Field'
32
+ end
33
+
30
34
  ##
31
35
  # Infer the organization_id from the 'self' link
32
36
 
@@ -28,5 +28,9 @@ module MyJohnDeereApi
28
28
  @proximity_alert_enabled = record['proximityAlertEnabled']
29
29
  @archived = record['archived']
30
30
  end
31
+
32
+ def expected_record_type
33
+ 'Flag'
34
+ end
31
35
  end
32
36
  end
@@ -39,5 +39,9 @@ module MyJohnDeereApi
39
39
  @type = record['type']
40
40
  @member = record['member']
41
41
  end
42
+
43
+ def expected_record_type
44
+ 'Organization'
45
+ end
42
46
  end
43
47
  end
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.5.1'
2
+ VERSION='0.5.2'
3
3
  end
@@ -35,6 +35,16 @@ describe 'MyJohnDeereApi::Model::Base' do
35
35
  record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
36
36
  end
37
37
 
38
+ it 'raises an error if there is a record type mismatch' do
39
+ record = {
40
+ '@type'=>'WrongType',
41
+ 'links'=>[]
42
+ }
43
+
44
+ exception = assert_raises(JD::TypeMismatchError) { JD::Model::Base.new(record) }
45
+ assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
46
+ end
47
+
38
48
  it 'sets the base attributes' do
39
49
  assert_equal record['id'], object.id
40
50
  assert_equal record['@type'], object.record_type
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime. Bellmyer