my_john_deere_api 1.3.6 → 1.3.7

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/my_john_deere_api/client.rb +11 -11
  3. data/lib/my_john_deere_api/model/asset.rb +1 -1
  4. data/lib/my_john_deere_api/model/base.rb +15 -6
  5. data/lib/my_john_deere_api/model/contribution_product.rb +1 -1
  6. data/lib/my_john_deere_api/model/field.rb +1 -1
  7. data/lib/my_john_deere_api/model/organization.rb +2 -2
  8. data/lib/my_john_deere_api/request/collection/asset_locations.rb +1 -1
  9. data/lib/my_john_deere_api/request/collection/assets.rb +2 -2
  10. data/lib/my_john_deere_api/request/collection/base.rb +16 -8
  11. data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +1 -1
  12. data/lib/my_john_deere_api/request/collection/contribution_products.rb +1 -1
  13. data/lib/my_john_deere_api/request/collection/fields.rb +1 -1
  14. data/lib/my_john_deere_api/request/collection/organizations.rb +1 -1
  15. data/lib/my_john_deere_api/request/create/base.rb +12 -4
  16. data/lib/my_john_deere_api/request/individual/base.rb +13 -5
  17. data/lib/my_john_deere_api/request/update/base.rb +11 -3
  18. data/lib/my_john_deere_api/version.rb +1 -1
  19. data/test/lib/my_john_deere_api/client_test.rb +0 -3
  20. data/test/lib/my_john_deere_api/model/asset_location_test.rb +6 -6
  21. data/test/lib/my_john_deere_api/model/asset_test.rb +8 -9
  22. data/test/lib/my_john_deere_api/model/base_test.rb +8 -7
  23. data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +3 -5
  24. data/test/lib/my_john_deere_api/model/contribution_product_test.rb +8 -8
  25. data/test/lib/my_john_deere_api/model/field_test.rb +8 -9
  26. data/test/lib/my_john_deere_api/model/flag_test.rb +6 -6
  27. data/test/lib/my_john_deere_api/model/organization_test.rb +9 -11
  28. data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +6 -5
  29. data/test/lib/my_john_deere_api/request/collection/assets_test.rb +6 -5
  30. data/test/lib/my_john_deere_api/request/collection/base_test.rb +8 -6
  31. data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +5 -5
  32. data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +5 -5
  33. data/test/lib/my_john_deere_api/request/collection/fields_test.rb +6 -5
  34. data/test/lib/my_john_deere_api/request/collection/flags_test.rb +6 -5
  35. data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +7 -6
  36. data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +15 -13
  37. data/test/lib/my_john_deere_api/request/create/asset_test.rb +16 -14
  38. data/test/lib/my_john_deere_api/request/create/base_test.rb +6 -4
  39. data/test/lib/my_john_deere_api/request/individual/asset_test.rb +4 -3
  40. data/test/lib/my_john_deere_api/request/individual/base_test.rb +4 -3
  41. data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +4 -3
  42. data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +4 -3
  43. data/test/lib/my_john_deere_api/request/individual/field_test.rb +4 -3
  44. data/test/lib/my_john_deere_api/request/individual/organization_test.rb +4 -3
  45. data/test/lib/my_john_deere_api/request/update/asset_test.rb +6 -5
  46. data/test/lib/my_john_deere_api/request/update/base_test.rb +6 -4
  47. data/test/support/helper.rb +7 -2
  48. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a060cb86023a65bf70b80bf717e86c725cb436e13d31d88bbd9148a235ab03c2
4
- data.tar.gz: 95198638b33c2402679745aa2c43322af1fe039b446388b1ec800b3f8be451c7
3
+ metadata.gz: 347239b756637538b1565dac76ef8d922b11fe4d473811b14a9e8f7edf134902
4
+ data.tar.gz: 670ee3f6c1ad3f8845166f9c82d8f46ad21a1c5faf4f0cd05da6b24ffc3a4fd5
5
5
  SHA512:
6
- metadata.gz: db67993c3685f8e9a2519fefdc2e790a5d94c6e7accca6c94fc4a6daa9fe4ec6009e9eb23e12adfb987fd437038bd861a9542516a0a9a8e7089dd071ee59b1a6
7
- data.tar.gz: 4bc3a3fe87d49f052c87d3f5fa746886a7c9b2edfb7db9972a507334c212d232c9d4091ae2f3c594864050ec5ce8bf9689762a2201ec7d16554dc67e50ec4488
6
+ metadata.gz: 4ee286908de1b144b7d00687e28025e6d92a9d19bf7468bfbf3e4489a8c0340b69cb92f1177b2738d13ab16e6c6b908f2cfcd57be4e00c03d954a62679dd36a8
7
+ data.tar.gz: 73308deefd549de1ff76220b14a0a267b2583fe2c2f5216a423091faaff9cebe9ea06cf20b02df63407af3f7a916de9198c21152e92eed60f8812ae10d5e3058
@@ -34,6 +34,15 @@ module MyJohnDeereApi
34
34
  self.environment = options[:environment]
35
35
  end
36
36
 
37
+ ##
38
+ # Returns an oAuth AccessToken object which can be used to make
39
+ # user-specific API requests
40
+
41
+ def accessor
42
+ return @accessor if defined?(@accessor)
43
+ @accessor = OAuth::AccessToken.new(consumer.user_get, access_token, access_secret)
44
+ end
45
+
37
46
  ##
38
47
  # generic user-specific GET request method that returns JSON
39
48
 
@@ -95,7 +104,7 @@ module MyJohnDeereApi
95
104
 
96
105
  def organizations
97
106
  return @organizations if defined?(@organizations)
98
- @organizations = MyJohnDeereApi::Request::Collection::Organizations.new(accessor)
107
+ @organizations = MyJohnDeereApi::Request::Collection::Organizations.new(self)
99
108
  end
100
109
 
101
110
  ##
@@ -103,7 +112,7 @@ module MyJohnDeereApi
103
112
 
104
113
  def contribution_products
105
114
  return @contribution_products if defined?(@contribution_products)
106
- @contribution_products = MyJohnDeereApi::Request::Collection::ContributionProducts.new(accessor)
115
+ @contribution_products = MyJohnDeereApi::Request::Collection::ContributionProducts.new(self)
107
116
  end
108
117
 
109
118
  private
@@ -116,15 +125,6 @@ module MyJohnDeereApi
116
125
  @consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment)
117
126
  end
118
127
 
119
- ##
120
- # Returns an oAuth AccessToken object which can be used to make
121
- # user-specific API requests
122
-
123
- def accessor
124
- return @accessor if defined?(@accessor)
125
- @accessor = OAuth::AccessToken.new(consumer.user_get, access_token, access_secret)
126
- end
127
-
128
128
  def headers
129
129
  @headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
130
130
  end
@@ -22,7 +22,7 @@ module MyJohnDeereApi
22
22
  raise AccessTokenError unless accessor
23
23
 
24
24
  return @locations if defined?(@locations)
25
- @locations = MyJohnDeereApi::Request::Collection::AssetLocations.new(accessor, asset: id)
25
+ @locations = MyJohnDeereApi::Request::Collection::AssetLocations.new(client, asset: id)
26
26
  end
27
27
 
28
28
  private
@@ -3,23 +3,24 @@ module MyJohnDeereApi
3
3
  include Helpers::CaseConversion
4
4
  include Helpers::UriHelpers
5
5
 
6
- attr_reader :id, :record_type, :accessor, :links
6
+ attr_reader :id, :record_type, :client, :links
7
7
 
8
8
  ##
9
9
  # arguments:
10
10
  #
11
11
  # [record] a JSON object of type 'Field', returned from the API.
12
12
  #
13
- # [accessor (optional)] a valid oAuth Access Token. This is only
14
- # needed if further API requests are going
15
- # to be made, as is the case with *flags*.
13
+ # [client] the client, because it contains all the config info.
14
+ # The alternative would be a true Config block, but then
15
+ # settings would be app-wide. This allows one app to have
16
+ # multiple clients with different settings.
16
17
 
17
- def initialize(record, accessor = nil)
18
+ def initialize(record, client = nil)
18
19
  verify_record_type(record['@type'])
19
20
 
20
21
  @id = record['id']
21
22
  @record_type = record['@type']
22
- @accessor = accessor
23
+ @client = client
23
24
 
24
25
  map_attributes(record)
25
26
 
@@ -30,6 +31,14 @@ module MyJohnDeereApi
30
31
  end
31
32
  end
32
33
 
34
+ ##
35
+ # The client accessor
36
+
37
+ def accessor
38
+ return @accessor if defined?(@accessor)
39
+ @accessor = client&.accessor
40
+ end
41
+
33
42
  private
34
43
 
35
44
  ##
@@ -10,7 +10,7 @@ module MyJohnDeereApi
10
10
 
11
11
  def contribution_definitions
12
12
  return @contribution_definitions if defined?(@contribution_definitions)
13
- @contribution_definitions = Request::Collection::ContributionDefinitions.new(accessor, contribution_product: id)
13
+ @contribution_definitions = Request::Collection::ContributionDefinitions.new(client, contribution_product: id)
14
14
  end
15
15
 
16
16
  private
@@ -17,7 +17,7 @@ module MyJohnDeereApi
17
17
  raise AccessTokenError unless accessor
18
18
 
19
19
  return @flags if defined?(@flags)
20
- @flags = Request::Collection::Flags.new(accessor, organization: organization_id, field: id)
20
+ @flags = Request::Collection::Flags.new(client, organization: organization_id, field: id)
21
21
  end
22
22
 
23
23
  private
@@ -19,7 +19,7 @@ module MyJohnDeereApi
19
19
  raise AccessTokenError unless accessor
20
20
 
21
21
  return @fields if defined?(@fields)
22
- @fields = MyJohnDeereApi::Request::Collection::Fields.new(accessor, organization: id)
22
+ @fields = MyJohnDeereApi::Request::Collection::Fields.new(client, organization: id)
23
23
  end
24
24
 
25
25
  ##
@@ -29,7 +29,7 @@ module MyJohnDeereApi
29
29
  raise AccessTokenError unless accessor
30
30
 
31
31
  return @assets if defined?(@assets)
32
- @assets = MyJohnDeereApi::Request::Collection::Assets.new(accessor, organization: id)
32
+ @assets = MyJohnDeereApi::Request::Collection::Assets.new(client, organization: id)
33
33
  end
34
34
 
35
35
  private
@@ -21,7 +21,7 @@ module MyJohnDeereApi::Request
21
21
 
22
22
  def create(attributes)
23
23
  merged_attributes = attributes.merge(asset_id: associations[:asset])
24
- Create::AssetLocation.new(accessor, merged_attributes).object
24
+ Create::AssetLocation.new(client, merged_attributes).object
25
25
  end
26
26
  end
27
27
  end
@@ -21,14 +21,14 @@ module MyJohnDeereApi::Request
21
21
 
22
22
  def create(attributes)
23
23
  merged_attributes = attributes.merge(organization_id: associations[:organization])
24
- Create::Asset.new(accessor, merged_attributes).object
24
+ Create::Asset.new(client, merged_attributes).object
25
25
  end
26
26
 
27
27
  ##
28
28
  # Retrieve an asset from JD
29
29
 
30
30
  def find(asset_id)
31
- Individual::Asset.new(accessor, asset_id).object
31
+ Individual::Asset.new(client, asset_id).object
32
32
  end
33
33
  end
34
34
  end
@@ -3,18 +3,26 @@ module MyJohnDeereApi
3
3
  include Enumerable
4
4
  include Helpers::UriHelpers
5
5
 
6
- attr_reader :accessor, :associations
6
+ attr_reader :client, :associations
7
7
 
8
8
  ##
9
- # accessor is an OAuth::AccessToken object which has the necessary
10
- # credentials to make the desired requests.
9
+ # client is the original client instance which contains
10
+ # the necessary config info.
11
11
 
12
- def initialize(accessor, associations = {})
13
- @accessor = accessor
12
+ def initialize(client, associations = {})
13
+ @client = client
14
14
  @associations = associations
15
15
  @items = []
16
16
  end
17
17
 
18
+ ##
19
+ # client accessor
20
+
21
+ def accessor
22
+ return @accessor if defined?(@accessor)
23
+ @accessor = client&.accessor
24
+ end
25
+
18
26
  ##
19
27
  # Iterate lazily through all records in the collection, fetching
20
28
  # additional pages as needed.
@@ -46,7 +54,7 @@ module MyJohnDeereApi
46
54
  def first_page
47
55
  return @first_page if defined?(@first_page)
48
56
 
49
- @first_page = JSON.parse(@accessor.get(resource, headers).body)
57
+ @first_page = JSON.parse(accessor.get(resource, headers).body)
50
58
  extract_page_contents(@first_page)
51
59
 
52
60
  @first_page
@@ -55,7 +63,7 @@ module MyJohnDeereApi
55
63
  def fetch
56
64
  return unless @next_page
57
65
 
58
- page = JSON.parse(@accessor.get(@next_page, headers).body)
66
+ page = JSON.parse(accessor.get(@next_page, headers).body)
59
67
  extract_page_contents(page)
60
68
  end
61
69
 
@@ -69,7 +77,7 @@ module MyJohnDeereApi
69
77
  end
70
78
 
71
79
  def add_items_from_page(page)
72
- @items += page['values'].map{|record| model.new(record, accessor) }
80
+ @items += page['values'].map{|record| model.new(record, client) }
73
81
  end
74
82
 
75
83
  def set_next_page(page)
@@ -20,7 +20,7 @@ module MyJohnDeereApi::Request
20
20
  # Retrieve an item from JD
21
21
 
22
22
  def find(item_id)
23
- Individual::ContributionDefinition.new(accessor, item_id).object
23
+ Individual::ContributionDefinition.new(client, item_id).object
24
24
  end
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ module MyJohnDeereApi::Request
20
20
  # Retrieve an item from JD
21
21
 
22
22
  def find(item_id)
23
- Individual::ContributionProduct.new(accessor, item_id).object
23
+ Individual::ContributionProduct.new(client, item_id).object
24
24
  end
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ module MyJohnDeereApi::Request
20
20
  # Retrieve a field from JD
21
21
 
22
22
  def find(field_id)
23
- Individual::Field.new(accessor, field_id, organization: associations[:organization]).object
23
+ Individual::Field.new(client, field_id, organization: associations[:organization]).object
24
24
  end
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ module MyJohnDeereApi::Request
20
20
  # Retrieve an organization from JD
21
21
 
22
22
  def find(organization_id)
23
- Individual::Organization.new(accessor, organization_id).object
23
+ Individual::Organization.new(client, organization_id).object
24
24
  end
25
25
  end
26
26
  end
@@ -2,18 +2,26 @@ require 'json'
2
2
 
3
3
  module MyJohnDeereApi
4
4
  class Request::Create::Base
5
- attr_reader :accessor, :attributes, :response
5
+ attr_reader :client, :attributes, :response
6
6
 
7
7
  ##
8
8
  # Accepts a valid oAuth AccessToken, and a hash of attributes.
9
9
 
10
- def initialize(accessor, attributes)
11
- @accessor = accessor
10
+ def initialize(client, attributes)
11
+ @client = client
12
12
  @attributes = attributes
13
13
 
14
14
  process_attributes
15
15
  end
16
16
 
17
+ ##
18
+ # client accessor
19
+
20
+ def accessor
21
+ return @accessor if defined?(@accessor)
22
+ @accessor = client&.accessor
23
+ end
24
+
17
25
  ##
18
26
  # Make the request, if the instance is valid
19
27
 
@@ -31,7 +39,7 @@ module MyJohnDeereApi
31
39
 
32
40
  request unless response
33
41
 
34
- @object = model.new(fetch_record, accessor)
42
+ @object = model.new(fetch_record, client)
35
43
  end
36
44
 
37
45
  ##
@@ -2,16 +2,24 @@ require 'json'
2
2
 
3
3
  module MyJohnDeereApi::Request
4
4
  class Individual::Base
5
- attr_reader :accessor, :id, :associations, :response
5
+ attr_reader :client, :id, :associations, :response
6
6
 
7
7
  ##
8
- # Initialize with an accessor, and asset id
8
+ # Initialize with a client, and asset id
9
9
 
10
- def initialize(accessor, id, associations = {})
11
- @accessor = accessor
10
+ def initialize(client, id, associations = {})
11
+ @client = client
12
12
  @id = id
13
13
  @associations = associations
14
14
  end
15
+
16
+ ##
17
+ # client accessor
18
+
19
+ def accessor
20
+ return @accessor if defined?(@accessor)
21
+ @accessor = client&.accessor
22
+ end
15
23
 
16
24
  ##
17
25
  # The object being requested, an asset in this case
@@ -20,7 +28,7 @@ module MyJohnDeereApi::Request
20
28
  return @object if defined?(@object)
21
29
 
22
30
  request unless response
23
- @object = model.new(JSON.parse(response.body), accessor)
31
+ @object = model.new(JSON.parse(response.body), client)
24
32
  end
25
33
 
26
34
  private
@@ -4,7 +4,7 @@ module MyJohnDeereApi
4
4
  class Request::Update::Base
5
5
  include Validators::Base
6
6
 
7
- attr_reader :accessor, :item, :attributes, :response
7
+ attr_reader :client, :item, :attributes, :response
8
8
 
9
9
  ##
10
10
  # Accepts a valid oAuth AccessToken, the item to be updated,
@@ -12,14 +12,22 @@ module MyJohnDeereApi
12
12
  #
13
13
  # category/type/subtype must be a recognized combination as defined above.
14
14
 
15
- def initialize(accessor, item, attributes)
16
- @accessor = accessor
15
+ def initialize(client, item, attributes)
16
+ @client = client
17
17
  @item = item
18
18
  @attributes = item.attributes.merge(attributes)
19
19
 
20
20
  process_attributes
21
21
  end
22
22
 
23
+ #
24
+ # client accessor
25
+
26
+ def accessor
27
+ return @accessor if defined?(@accessor)
28
+ @accessor = client&.accessor
29
+ end
30
+
23
31
  ##
24
32
  # Make the request, if the instance is valid
25
33
 
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='1.3.6'
2
+ VERSION='1.3.7'
3
3
  end
@@ -34,7 +34,6 @@ describe 'MyJohnDeereApi::Client' do
34
34
 
35
35
  describe '#get' do
36
36
  it 'returns the response as a Hash' do
37
- VCR.use_cassette('catalog') { client.send(:accessor) }
38
37
  response = VCR.use_cassette('get_organizations') { client.get('/organizations') }
39
38
 
40
39
  assert_kind_of Hash, response
@@ -44,7 +43,6 @@ describe 'MyJohnDeereApi::Client' do
44
43
  end
45
44
 
46
45
  it 'prepends the leading slash if needed' do
47
- VCR.use_cassette('catalog') { client.send(:accessor) }
48
46
  response = VCR.use_cassette('get_organizations') { client.get('organizations') }
49
47
 
50
48
  assert_kind_of Hash, response
@@ -54,7 +52,6 @@ describe 'MyJohnDeereApi::Client' do
54
52
  end
55
53
 
56
54
  it 'allows symbols for simple resources' do
57
- VCR.use_cassette('catalog') { client.send(:accessor) }
58
55
  response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
59
56
 
60
57
  assert_kind_of Hash, response
@@ -2,6 +2,8 @@ require 'support/helper'
2
2
  require 'json'
3
3
 
4
4
  describe 'MyJohnDeereApi::Model::AssetLocation' do
5
+ let(:klass) { JD::Model::AssetLocation }
6
+
5
7
  let(:record) do
6
8
  {
7
9
  '@type' => 'ContributedAssetLocation',
@@ -18,7 +20,7 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
18
20
  end
19
21
 
20
22
  it 'sets the attributes from the given record' do
21
- location = JD::Model::AssetLocation.new(record)
23
+ location = klass.new(record)
22
24
 
23
25
  assert_nil location.accessor
24
26
 
@@ -32,11 +34,9 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
32
34
  assert_equal 0, location.links.size
33
35
  end
34
36
 
35
- it 'accepts an optional accessor' do
36
- mock_accessor = 'mock-accessor'
37
-
38
- location = JD::Model::AssetLocation.new(record, mock_accessor)
39
- assert_equal mock_accessor, location.accessor
37
+ it 'accepts an optional client' do
38
+ location = klass.new(record, client)
39
+ assert_equal client, location.client
40
40
  end
41
41
  end
42
42
  end
@@ -1,6 +1,8 @@
1
1
  require 'support/helper'
2
2
 
3
3
  describe 'MyJohnDeereApi::Model::Asset' do
4
+ let(:klass) { JD::Model::Asset }
5
+
4
6
  let(:record) do
5
7
  {
6
8
  "@type"=>"ContributedAsset",
@@ -24,7 +26,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
24
26
  end
25
27
 
26
28
  it 'sets the attributes from the given record' do
27
- asset = JD::Model::Asset.new(record)
29
+ asset = klass.new(record)
28
30
 
29
31
  assert_nil asset.accessor
30
32
 
@@ -44,17 +46,15 @@ describe 'MyJohnDeereApi::Model::Asset' do
44
46
  end
45
47
  end
46
48
 
47
- it 'accepts an optional accessor' do
48
- mock_accessor = 'mock-accessor'
49
-
50
- asset = JD::Model::Asset.new(record, mock_accessor)
51
- assert_equal mock_accessor, asset.accessor
49
+ it 'accepts an optional client' do
50
+ asset = klass.new(record, client)
51
+ assert_equal client, asset.client
52
52
  end
53
53
  end
54
54
 
55
55
  describe '#attributes' do
56
56
  it 'converts properties back to an attributes hash' do
57
- asset = JD::Model::Asset.new(record)
57
+ asset = klass.new(record)
58
58
  attributes = asset.attributes
59
59
 
60
60
  assert_equal asset.id, attributes[:id]
@@ -67,7 +67,6 @@ describe 'MyJohnDeereApi::Model::Asset' do
67
67
 
68
68
  describe '#locations' do
69
69
  it 'returns a collection of locations for this asset' do
70
- accessor
71
70
  organization = VCR.use_cassette('get_organizations') { client.organizations.first }
72
71
  asset = VCR.use_cassette('get_assets') { organization.assets.first }
73
72
 
@@ -84,7 +83,7 @@ describe 'MyJohnDeereApi::Model::Asset' do
84
83
  end
85
84
 
86
85
  it 'raises an exception if an accessor is not available' do
87
- asset = JD::Model::Asset.new(record)
86
+ asset = klass.new(record)
88
87
 
89
88
  exception = assert_raises(JD::AccessTokenError) { asset.locations }
90
89
  assert_includes exception.message, 'Access Token must be supplied'
@@ -9,7 +9,8 @@ class SampleModel < JD::Model::Base
9
9
  end
10
10
 
11
11
  describe 'MyJohnDeereApi::Model::Base' do
12
- let(:object) { JD::Model::Base.new(record, accessor) }
12
+ let(:klass) { JD::Model::Base }
13
+ let(:object) { klass.new(record, client) }
13
14
 
14
15
  let(:record) do
15
16
  {
@@ -29,7 +30,7 @@ describe 'MyJohnDeereApi::Model::Base' do
29
30
  assert_includes object.private_methods, :id_from_uri
30
31
  end
31
32
 
32
- describe '#initialize(record, accessor = nil)' do
33
+ describe '#initialize(record, client)' do
33
34
  def link_for label
34
35
  record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
35
36
  end
@@ -40,14 +41,14 @@ describe 'MyJohnDeereApi::Model::Base' do
40
41
  'links'=>[]
41
42
  }
42
43
 
43
- exception = assert_raises(JD::TypeMismatchError) { JD::Model::Base.new(record) }
44
+ exception = assert_raises(JD::TypeMismatchError) { klass.new(record) }
44
45
  assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
45
46
  end
46
47
 
47
48
  it 'sets the base attributes' do
48
49
  assert_equal record['id'], object.id
49
50
  assert_equal record['@type'], object.record_type
50
- assert_equal accessor, object.accessor
51
+ assert_equal client, object.client
51
52
  end
52
53
 
53
54
  it 'sets the links' do
@@ -65,9 +66,9 @@ describe 'MyJohnDeereApi::Model::Base' do
65
66
  assert_equal 'somevalue', object.somefield
66
67
  end
67
68
 
68
- it 'does not require accessor' do
69
- object = JD::Model::Base.new(record)
70
- assert_nil object.accessor
69
+ it 'does not require client' do
70
+ object = klass.new(record)
71
+ assert_nil object.client
71
72
  end
72
73
  end
73
74
  end
@@ -46,11 +46,9 @@ describe 'MyJohnDeereApi::Model::ContributionDefinition' do
46
46
  end
47
47
  end
48
48
 
49
- it 'accepts an optional accessor' do
50
- mock_accessor = 'mock-accessor'
51
-
52
- asset = klass.new(record, mock_accessor)
53
- assert_equal mock_accessor, asset.accessor
49
+ it 'accepts an optional client' do
50
+ asset = klass.new(record, client)
51
+ assert_equal client, asset.client
54
52
  end
55
53
  end
56
54
  end
@@ -1,6 +1,8 @@
1
1
  require 'support/helper'
2
2
 
3
3
  describe 'MyJohnDeereApi::Model::ContributionProduct' do
4
+ let(:klass) { JD::Model::ContributionProduct }
5
+
4
6
  let(:record) do
5
7
  {
6
8
  "@type" => "ContributionProduct",
@@ -36,7 +38,7 @@ describe 'MyJohnDeereApi::Model::ContributionProduct' do
36
38
  end
37
39
 
38
40
  it 'sets the attributes from the given record' do
39
- product = JD::Model::ContributionProduct.new(record)
41
+ product = klass.new(record)
40
42
 
41
43
  # basic attributes
42
44
  assert_equal record['id'], product.id
@@ -51,24 +53,22 @@ describe 'MyJohnDeereApi::Model::ContributionProduct' do
51
53
  end
52
54
 
53
55
  it 'links to other things' do
54
- product = JD::Model::ContributionProduct.new(record)
56
+ product = klass.new(record)
55
57
 
56
58
  ['self', 'contribution_definition'].each do |association|
57
59
  assert_equal link_for(association), product.links[association]
58
60
  end
59
61
  end
60
62
 
61
- it 'accepts an optional accessor' do
62
- mock_accessor = 'mock-accessor'
63
-
64
- asset = JD::Model::ContributionProduct.new(record, mock_accessor)
65
- assert_equal mock_accessor, asset.accessor
63
+ it 'accepts an optional client' do
64
+ asset = klass.new(record, client)
65
+ assert_equal client, asset.client
66
66
  end
67
67
  end
68
68
 
69
69
  describe '#contribution_definitions' do
70
70
  it 'returns a collection of contribution definitions for this contributon product' do
71
- product = JD::Model::ContributionProduct.new(record, accessor)
71
+ product = klass.new(record, client)
72
72
 
73
73
  contribution_definitions = VCR.use_cassette('get_contribution_definitions') do
74
74
  product.contribution_definitions.all; product.contribution_definitions