my_john_deere_api 2.2.0 → 2.2.1

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: 3f611ef5d6785246196c22bc5e453374da5a4a513a689ad649ba1907de39c93f
4
- data.tar.gz: 773b32b36229740d1d7885f4e8728cff83f32cb7b19d1ae65847b1bbdd8bea4a
3
+ metadata.gz: eb14a8c4e0fb2065e96d8a7f9bcff1502c2af26f3d312992765aecf36d15000f
4
+ data.tar.gz: 6d4095d5d77723b5b0e3e14dac54f414b28b998b6653fe85eecd7d2141de7aeb
5
5
  SHA512:
6
- metadata.gz: 7cd73bbcea8e2615b5bbf4bbf4c91531a991b5c09566f1e7917fbb77d26309b9d4b8f5c532f081c3dd0f463e004ea716f687b2a953420798a7f71f98ee5de16e
7
- data.tar.gz: 316d9852d79c9f86c6ec55b6bf5417dcaf47ca06da5eb391b79e19d18c9e20541c625aaa098102dec981ade2e503c673f10267a263069d2f355fcdd06ff46a11
6
+ metadata.gz: 31c66ca8dad9ce28792a20c61323c967cffb704f006ff752f11492d60ab458e81f462b5aee043bab130d0941c9ac37f9c667a4f57bf77e4885930502d2952bb6
7
+ data.tar.gz: f2dda7cbed562b64376dc86609048a2b55eef468a4b745ca1bc785da7fea38741b2adc8f396832419078758801369e4c2a03a95661b60728b7d814c29b6fdb12
@@ -8,14 +8,14 @@ module MyJohnDeereApi
8
8
  ##
9
9
  # arguments:
10
10
  #
11
- # [record] a JSON object of type 'Field', returned from the API.
12
- #
13
11
  # [client] the client, because it contains all the config info.
14
12
  # The alternative would be a true Config block, but then
15
13
  # settings would be app-wide. This allows one app to have
16
14
  # multiple clients with different settings.
15
+ #
16
+ # [record] a JSON object of type 'Field', returned from the API.
17
17
 
18
- def initialize(record, client = nil)
18
+ def initialize(client, record)
19
19
  verify_record_type(record['@type'])
20
20
 
21
21
  @id = record['id']
@@ -77,7 +77,7 @@ module MyJohnDeereApi
77
77
  end
78
78
 
79
79
  def add_items_from_page(page)
80
- @items += page['values'].map{|record| model.new(record, client) }
80
+ @items += page['values'].map{|record| model.new(client, record) }
81
81
  end
82
82
 
83
83
  def set_next_page(page)
@@ -39,7 +39,7 @@ module MyJohnDeereApi
39
39
 
40
40
  request unless response
41
41
 
42
- @object = model.new(fetch_record, client)
42
+ @object = model.new(client, fetch_record)
43
43
  end
44
44
 
45
45
  ##
@@ -12,10 +12,10 @@ module MyJohnDeereApi::Request
12
12
  @id = id
13
13
  @associations = associations
14
14
  end
15
-
15
+
16
16
  ##
17
17
  # client accessor
18
-
18
+
19
19
  def accessor
20
20
  return @accessor if defined?(@accessor)
21
21
  @accessor = client&.accessor
@@ -28,7 +28,7 @@ module MyJohnDeereApi::Request
28
28
  return @object if defined?(@object)
29
29
 
30
30
  request unless response
31
- @object = model.new(JSON.parse(response.body), client)
31
+ @object = model.new(client, JSON.parse(response.body))
32
32
  end
33
33
 
34
34
  private
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='2.2.0'
2
+ VERSION='2.2.1'
3
3
  end
@@ -20,9 +20,10 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
20
20
  end
21
21
 
22
22
  it 'sets the attributes from the given record' do
23
- location = klass.new(record)
23
+ location = klass.new(client, record)
24
24
 
25
- assert_nil location.accessor
25
+ assert_equal client, location.client
26
+ assert_equal accessor, location.accessor
26
27
 
27
28
  # basic attributes
28
29
  assert_equal record['timestamp'], location.timestamp
@@ -33,10 +34,5 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
33
34
  assert_kind_of Hash, location.links
34
35
  assert_equal 0, location.links.size
35
36
  end
36
-
37
- it 'accepts an optional client' do
38
- location = klass.new(record, client)
39
- assert_equal client, location.client
40
- end
41
37
  end
42
38
  end
@@ -26,9 +26,10 @@ describe 'MyJohnDeereApi::Model::Asset' do
26
26
  end
27
27
 
28
28
  it 'sets the attributes from the given record' do
29
- asset = klass.new(record)
29
+ asset = klass.new(client, record)
30
30
 
31
- assert_nil asset.accessor
31
+ assert_equal client, asset.client
32
+ assert_equal accessor, asset.accessor
32
33
 
33
34
  # basic attributes
34
35
  assert_equal record['id'], asset.id
@@ -45,16 +46,11 @@ describe 'MyJohnDeereApi::Model::Asset' do
45
46
  assert_equal link_for(association), asset.links[association]
46
47
  end
47
48
  end
48
-
49
- it 'accepts an optional client' do
50
- asset = klass.new(record, client)
51
- assert_equal client, asset.client
52
- end
53
49
  end
54
50
 
55
51
  describe '#attributes' do
56
52
  it 'converts properties back to an attributes hash' do
57
- asset = klass.new(record, client)
53
+ asset = klass.new(client, record)
58
54
  attributes = asset.attributes
59
55
 
60
56
  assert_equal asset.id, attributes[:id]
@@ -67,7 +63,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
67
63
 
68
64
  describe '#save' do
69
65
  it 'sends any recent updates to John Deere' do
70
- asset = klass.new(record, client)
66
+ asset = klass.new(client, record)
71
67
  new_title = 'i REALLY like turtles!'
72
68
 
73
69
  asset.title = new_title
@@ -78,14 +74,14 @@ describe 'MyJohnDeereApi::Model::Asset' do
78
74
  end
79
75
 
80
76
  it 'does not make a JD request if nothing has changed' do
81
- asset = klass.new(record, client)
77
+ asset = klass.new(client, record)
82
78
  response = asset.save
83
79
 
84
80
  assert_nil response
85
81
  end
86
82
 
87
83
  it 'marks the record as saved' do
88
- asset = klass.new(record, client)
84
+ asset = klass.new(client, record)
89
85
  asset.title = 'i REALLY like turtles!'
90
86
 
91
87
  response = VCR.use_cassette('put_asset') { asset.save }
@@ -98,7 +94,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
98
94
 
99
95
  describe '#update' do
100
96
  it 'updates the attributes' do
101
- asset = klass.new(record, client)
97
+ asset = klass.new(client, record)
102
98
 
103
99
  new_title = 'i REALLY like turtles!'
104
100
  VCR.use_cassette('put_asset') { asset.update(title: new_title) }
@@ -108,7 +104,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
108
104
  end
109
105
 
110
106
  it 'sends the update to John Deere' do
111
- asset = klass.new(record, client)
107
+ asset = klass.new(client, record)
112
108
 
113
109
  new_title = 'i REALLY like turtles!'
114
110
  response = VCR.use_cassette('put_asset') { asset.update(title: new_title) }
@@ -133,12 +129,5 @@ describe 'MyJohnDeereApi::Model::Asset' do
133
129
  assert_kind_of JD::Model::AssetLocation, location
134
130
  end
135
131
  end
136
-
137
- it 'raises an exception if an accessor is not available' do
138
- asset = klass.new(record)
139
-
140
- exception = assert_raises(JD::AccessTokenError) { asset.locations }
141
- assert_includes exception.message, 'Access Token must be supplied'
142
- end
143
132
  end
144
133
  end
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  describe 'MyJohnDeereApi::Model::Base' do
12
12
  let(:klass) { JD::Model::Base }
13
- let(:object) { klass.new(record, client) }
13
+ let(:object) { klass.new(client, record) }
14
14
 
15
15
  let(:record) do
16
16
  {
@@ -30,22 +30,29 @@ describe 'MyJohnDeereApi::Model::Base' do
30
30
  assert_includes object.private_methods, :id_from_uri
31
31
  end
32
32
 
33
- describe '#initialize(record, client)' do
33
+ describe '#initialize(client, record)' do
34
34
  def link_for label
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
- }
38
+ describe 'when the wrong record type is passed' do
39
+ let(:record) do
40
+ {
41
+ '@type'=>'WrongType',
42
+ 'links'=>[]
43
+ }
44
+ end
43
45
 
44
- exception = assert_raises(JD::TypeMismatchError) { klass.new(record) }
45
- assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
46
+ it 'raises a TypeMismatch error' do
47
+ exception = assert_raises(JD::TypeMismatchError) { object }
48
+ assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
49
+ end
46
50
  end
47
51
 
48
52
  it 'sets the base attributes' do
53
+ assert_equal client, object.client
54
+ assert_equal accessor, object.accessor
55
+
49
56
  assert_equal record['id'], object.id
50
57
  assert_equal record['@type'], object.record_type
51
58
  assert_equal client, object.client
@@ -62,13 +69,8 @@ describe 'MyJohnDeereApi::Model::Base' do
62
69
  end
63
70
 
64
71
  it 'maps additional fields in subclasses' do
65
- object = SampleModel.new(record)
72
+ object = SampleModel.new(client, record)
66
73
  assert_equal 'somevalue', object.somefield
67
74
  end
68
-
69
- it 'does not require client' do
70
- object = klass.new(record)
71
- assert_nil object.client
72
- end
73
75
  end
74
76
  end
@@ -31,7 +31,10 @@ describe 'MyJohnDeereApi::Model::ContributionDefinition' do
31
31
  end
32
32
 
33
33
  it 'sets the attributes from the given record' do
34
- definition = klass.new(record)
34
+ definition = klass.new(client, record)
35
+
36
+ assert_equal client, definition.client
37
+ assert_equal accessor, definition.accessor
35
38
 
36
39
  # basic attributes
37
40
  assert_equal record['id'], definition.id
@@ -39,16 +42,11 @@ describe 'MyJohnDeereApi::Model::ContributionDefinition' do
39
42
  end
40
43
 
41
44
  it 'links to other things' do
42
- product = klass.new(record)
45
+ product = klass.new(client, record)
43
46
 
44
47
  ['self', 'contribution_product'].each do |association|
45
48
  assert_equal link_for(association), product.links[association]
46
49
  end
47
50
  end
48
-
49
- it 'accepts an optional client' do
50
- asset = klass.new(record, client)
51
- assert_equal client, asset.client
52
- end
53
51
  end
54
52
  end
@@ -38,7 +38,10 @@ describe 'MyJohnDeereApi::Model::ContributionProduct' do
38
38
  end
39
39
 
40
40
  it 'sets the attributes from the given record' do
41
- product = klass.new(record)
41
+ product = klass.new(client, record)
42
+
43
+ assert_equal client, product.client
44
+ assert_equal accessor, product.accessor
42
45
 
43
46
  # basic attributes
44
47
  assert_equal record['id'], product.id
@@ -53,22 +56,17 @@ describe 'MyJohnDeereApi::Model::ContributionProduct' do
53
56
  end
54
57
 
55
58
  it 'links to other things' do
56
- product = klass.new(record)
59
+ product = klass.new(client, record)
57
60
 
58
61
  ['self', 'contribution_definition'].each do |association|
59
62
  assert_equal link_for(association), product.links[association]
60
63
  end
61
64
  end
62
-
63
- it 'accepts an optional client' do
64
- asset = klass.new(record, client)
65
- assert_equal client, asset.client
66
- end
67
65
  end
68
66
 
69
67
  describe '#contribution_definitions' do
70
68
  it 'returns a collection of contribution definitions for this contributon product' do
71
- product = klass.new(record, client)
69
+ product = klass.new(client, record)
72
70
 
73
71
  contribution_definitions = VCR.use_cassette('get_contribution_definitions') do
74
72
  product.contribution_definitions.all; product.contribution_definitions
@@ -23,9 +23,10 @@ describe 'MyJohnDeereApi::Model::Field' do
23
23
  end
24
24
 
25
25
  it 'sets the attributes from the given record' do
26
- field = klass.new(record)
26
+ field = klass.new(client, record)
27
27
 
28
- assert_nil field.client
28
+ assert_equal client, field.client
29
+ assert_equal accessor, field.accessor
29
30
 
30
31
  # basic attributes
31
32
  assert_equal record['name'], field.name
@@ -39,11 +40,6 @@ describe 'MyJohnDeereApi::Model::Field' do
39
40
  assert_equal link_for(association), field.links[association]
40
41
  end
41
42
  end
42
-
43
- it 'accepts an optional accessor' do
44
- field = klass.new(record, client)
45
- assert_equal client, field.client
46
- end
47
43
  end
48
44
 
49
45
  describe '#flags' do
@@ -58,19 +54,11 @@ describe 'MyJohnDeereApi::Model::Field' do
58
54
  assert_kind_of JD::Model::Flag, flag
59
55
  end
60
56
  end
61
-
62
- it 'raises an exception if an accessor is not available' do
63
- field = klass.new(record)
64
-
65
- exception = assert_raises(JD::AccessTokenError) { field.flags }
66
-
67
- assert_includes exception.message, 'Access Token must be supplied'
68
- end
69
57
  end
70
58
 
71
59
  describe 'private #organization_id' do
72
60
  it "infers the organization_id from links" do
73
- field = klass.new(record)
61
+ field = klass.new(client, record)
74
62
  assert_equal organization_id, field.send(:organization_id)
75
63
  end
76
64
  end
@@ -3,7 +3,7 @@ require 'json'
3
3
 
4
4
  describe 'MyJohnDeereApi::Model::Flag' do
5
5
  let(:klass) { JD::Model::Flag }
6
-
6
+
7
7
  let(:record) do
8
8
  {
9
9
  "@type"=>"Flag",
@@ -26,27 +26,23 @@ describe 'MyJohnDeereApi::Model::Flag' do
26
26
  end
27
27
 
28
28
  it 'sets the attributes from the given record' do
29
- field = klass.new(record)
29
+ flag = klass.new(client, record)
30
30
 
31
- assert_nil field.accessor
31
+ assert_equal client, flag.client
32
+ assert_equal accessor, flag.accessor
32
33
 
33
34
  # basic attributes
34
- assert_equal JSON.parse(record['geometry']), field.geometry
35
- assert_equal record['archived'], field.archived?
36
- assert_equal record['proximityAlertEnabled'], field.proximity_alert_enabled?
37
- assert_equal record['notes'], field.notes
38
- assert_equal record['id'], field.id
35
+ assert_equal JSON.parse(record['geometry']), flag.geometry
36
+ assert_equal record['archived'], flag.archived?
37
+ assert_equal record['proximityAlertEnabled'], flag.proximity_alert_enabled?
38
+ assert_equal record['notes'], flag.notes
39
+ assert_equal record['id'], flag.id
39
40
 
40
41
  # links to other things
41
- assert_kind_of Hash, field.links
42
- assert_equal link_for('field'), field.links['field']
43
- assert_equal link_for('createdBy'), field.links['created_by']
44
- assert_equal link_for('lastModifiedBy'), field.links['last_modified_by']
45
- end
46
-
47
- it 'accepts an optional client' do
48
- field = klass.new(record, client)
49
- assert_equal client, field.client
42
+ assert_kind_of Hash, flag.links
43
+ assert_equal link_for('field'), flag.links['field']
44
+ assert_equal link_for('createdBy'), flag.links['created_by']
45
+ assert_equal link_for('lastModifiedBy'), flag.links['last_modified_by']
50
46
  end
51
47
  end
52
48
  end
@@ -36,14 +36,16 @@ describe 'MyJohnDeereApi::Model::Organization' do
36
36
  end
37
37
 
38
38
  it 'sets the attributes from the given record' do
39
- organization = klass.new(record)
39
+ organization = klass.new(client, record)
40
+
41
+ assert_equal client, organization.client
42
+ assert_equal accessor, organization.accessor
40
43
 
41
44
  # basic attributes
42
45
  assert_equal record['name'], organization.name
43
46
  assert_equal record['type'], organization.type
44
47
  assert_equal record['member'], organization.member?
45
48
  assert_equal record['id'], organization.id
46
- assert_nil organization.accessor
47
49
 
48
50
  # links to other things
49
51
  assert_kind_of Hash, organization.links
@@ -52,11 +54,6 @@ describe 'MyJohnDeereApi::Model::Organization' do
52
54
  assert_equal link_for(association), organization.links[association]
53
55
  end
54
56
  end
55
-
56
- it 'accepts an optional client' do
57
- organization = klass.new(record, client)
58
- assert_equal client, organization.client
59
- end
60
57
  end
61
58
 
62
59
  describe '#fields' do
@@ -70,14 +67,6 @@ describe 'MyJohnDeereApi::Model::Organization' do
70
67
  assert_kind_of JD::Model::Field, field
71
68
  end
72
69
  end
73
-
74
- it 'raises an exception if an accessor is not available' do
75
- organization = klass.new(record)
76
-
77
- exception = assert_raises(JD::AccessTokenError) { organization.fields }
78
-
79
- assert_includes exception.message, 'Access Token must be supplied'
80
- end
81
70
  end
82
71
 
83
72
  describe '#assets' do
@@ -91,12 +80,5 @@ describe 'MyJohnDeereApi::Model::Organization' do
91
80
  assert_kind_of JD::Model::Asset, assets
92
81
  end
93
82
  end
94
-
95
- it 'raises an exception if an accessor is not available' do
96
- organization = klass.new(record)
97
-
98
- exception = assert_raises(JD::AccessTokenError) { organization.assets }
99
- assert_includes exception.message, 'Access Token must be supplied'
100
- end
101
83
  end
102
84
  end
@@ -3,7 +3,7 @@ require 'support/helper'
3
3
  describe 'MyJohnDeereApi::Request::Update::Asset' do
4
4
  let(:klass) { JD::Request::Update::Asset }
5
5
  let(:object) { klass.new(client, item, attributes) }
6
- let(:item) { JD::Model::Asset.new(record, client) }
6
+ let(:item) { JD::Model::Asset.new(client, record) }
7
7
 
8
8
  let(:attributes) do
9
9
  {
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: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-15 00:00:00.000000000 Z
12
+ date: 2020-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vcr