my_john_deere_api 2.2.4 → 2.3.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: d0922043a7c3b1569cce53369feb1aefb39c8d29667b351a02ff2e63ec5d35c5
4
- data.tar.gz: 45fc68b7e4fb44ea06c22a50e1759cb6ec84e91bd278248306ede7854c1e1a00
3
+ metadata.gz: e4770ad629b97ce42d4a5482559e26506b78b67fcec897e6e08e849d9c38e6f7
4
+ data.tar.gz: af1b02dce372ce905933242226756e298553b75b6265ebb6f44d71916b20a5cd
5
5
  SHA512:
6
- metadata.gz: c65a1f6b28ead9107c40f20cc466c59d200503181016a595db746380aa923bb93f00047745eee470b73f8d83421f7f629e8c2567a4e2c34d84b488fba5ed047f
7
- data.tar.gz: e72bef48380aa51d14930972b8f0364e269282571adb4a0f21eaf8f35aca4a1795dcb087b50fcce48500a1802f1b8875eec23831f314f291fb407e9cd23ebaf4
6
+ metadata.gz: 44005e84b7c7e80ba54498e9c77f6d00e9fea447fcdc67106b55fd49e1452fc88a43d37a599506c22819e7ad4f1a166562b22a7954a966ffaba1e23d697530be
7
+ data.tar.gz: 964b2f971c765d5c115e7cf4f73372de6c69c77d15b7134c2b4d6137394ad78090c279305b300157228ee35916bf767f9c15f28d239d95a8c5242ae9d6cc8261
data/README.md CHANGED
@@ -499,6 +499,9 @@ Custom errors help clearly identify problems when using the client:
499
499
  unrecognized environment. Valid environments are `:sandbox` or `:production`.
500
500
  * **InvalidRecordError** is raised when bad input has been given, in an attempt to create or update
501
501
  a record on the John Deere platform.
502
+ * **MissingContributionDefinitionIdError** is raised when the optional contribution\_definition\_id
503
+ has not been set in the client, but an operation has been attempted that requires it - like
504
+ creating an asset in the John Deere platform.
502
505
  * **TypeMismatchError** is raised when a model is instantiated, typically when a record is received
503
506
  from John Deere and is being converted into a Ruby object. Model instantiation is normally handled
504
507
  by request objects, but this error is helpful if you're instantiating your own models for advanced
@@ -3,8 +3,8 @@ module MyJohnDeereApi
3
3
  include Helpers::EnvironmentHelper
4
4
  include Helpers::CaseConversion
5
5
 
6
- attr_reader :api_key, :api_secret, :access_token, :access_secret,
7
- :contribution_definition_id
6
+ attr_accessor :contribution_definition_id
7
+ attr_reader :api_key, :api_secret, :access_token, :access_secret
8
8
 
9
9
  DEFAULTS = {
10
10
  environment: :live
@@ -0,0 +1,12 @@
1
+ module MyJohnDeereApi
2
+ ##
3
+ # This error is used in a context that will fail in the absence of
4
+ # a valid oAuth access token. We have classes that may only need
5
+ # access tokens for some use cases.
6
+
7
+ class MissingContributionDefinitionIdError < StandardError
8
+ def initialize(message = "Contribution Definition ID must be set in the client to use this feature.")
9
+ super
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,6 @@
1
1
  module MyJohnDeereApi::Errors
2
2
  require 'my_john_deere_api/errors/invalid_record_error'
3
+ require 'my_john_deere_api/errors/missing_contribution_definition_id_error'
3
4
  require 'my_john_deere_api/errors/not_yet_implemented_error'
4
5
  require 'my_john_deere_api/errors/type_mismatch_error'
5
6
  require 'my_john_deere_api/errors/unsupported_environment_error'
@@ -36,6 +36,8 @@ module MyJohnDeereApi
36
36
  def request_body
37
37
  return @body if defined?(@body)
38
38
 
39
+ validate_contribution_definition
40
+
39
41
  @body = {
40
42
  title: attributes[:title],
41
43
  assetCategory: attributes[:asset_category],
@@ -54,6 +54,17 @@ module MyJohnDeereApi
54
54
  def process_attributes
55
55
  end
56
56
 
57
+ ##
58
+ # Raise an error if contribution_definition_id is missing
59
+
60
+ def validate_contribution_definition
61
+ unless client.contribution_definition_id
62
+ raise MissingContributionDefinitionIdError
63
+ end
64
+
65
+ true
66
+ end
67
+
57
68
  ##
58
69
  # Headers for POST request
59
70
 
@@ -19,6 +19,8 @@ module MyJohnDeereApi
19
19
  def request_body
20
20
  return @body if defined?(@body)
21
21
 
22
+ validate_contribution_definition
23
+
22
24
  @body = {
23
25
  title: attributes[:title],
24
26
  assetCategory: attributes[:asset_category],
@@ -54,6 +54,17 @@ module MyJohnDeereApi
54
54
  def process_attributes
55
55
  end
56
56
 
57
+ ##
58
+ # Raise an error if contribution_definition_id is missing
59
+
60
+ def validate_contribution_definition
61
+ unless client.contribution_definition_id
62
+ raise MissingContributionDefinitionIdError
63
+ end
64
+
65
+ true
66
+ end
67
+
57
68
  ##
58
69
  # Headers for PUT request
59
70
 
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='2.2.4'
2
+ VERSION='2.3.0'
3
3
  end
@@ -37,6 +37,16 @@ describe 'MyJohnDeereApi::Client' do
37
37
  end
38
38
  end
39
39
 
40
+ describe '#contribution_definition_id' do
41
+ it 'can be set after instantiation' do
42
+ client = JD::Client.new(api_key, api_secret)
43
+ assert_nil client.contribution_definition_id
44
+
45
+ client.contribution_definition_id = '123'
46
+ assert_equal '123', client.contribution_definition_id
47
+ end
48
+ end
49
+
40
50
  describe '#get' do
41
51
  it 'returns the response as a Hash' do
42
52
  response = VCR.use_cassette('get_organizations') { client.get('/organizations') }
@@ -0,0 +1,14 @@
1
+ require 'support/helper'
2
+
3
+ describe 'MyJohnDeereApi::MissingContributionDefinitionIdError' do
4
+ let(:klass) { MyJohnDeereApi::MissingContributionDefinitionIdError }
5
+ let(:error) { klass.new }
6
+
7
+ it 'inherits from StandardError' do
8
+ assert_kind_of StandardError, error
9
+ end
10
+
11
+ it 'has a default message' do
12
+ assert_includes error.message, 'Contribution Definition ID must be set in the client to use this feature.'
13
+ end
14
+ end
@@ -6,6 +6,10 @@ describe 'MyJohnDeereApi Errors' do
6
6
  assert JD::InvalidRecordError
7
7
  end
8
8
 
9
+ it 'loads MissingContributionDefinitionIdError' do
10
+ assert JD::MissingContributionDefinitionIdError
11
+ end
12
+
9
13
  it 'loads NotYetImplementedError' do
10
14
  assert JD::NotYetImplementedError
11
15
  end
@@ -129,6 +129,7 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
129
129
  it 'properly forms the request body' do
130
130
  object = klass.new(client, attributes)
131
131
  body = object.send(:request_body)
132
+
132
133
  assert_equal attributes[:title], body[:title]
133
134
  assert_equal attributes[:asset_category], body[:assetCategory]
134
135
  assert_equal attributes[:asset_type], body[:assetType]
@@ -143,6 +144,15 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
143
144
  assert_equal "#{base_url}/contributionDefinitions/#{contribution_definition_id}",
144
145
  body[:links].first['uri']
145
146
  end
147
+
148
+ it 'raises an exception when contribution_definition_id is not set' do
149
+ client.contribution_definition_id = nil
150
+ object = klass.new(client, attributes)
151
+
152
+ assert_raises(JD::MissingContributionDefinitionIdError) do
153
+ object.send(:request_body)
154
+ end
155
+ end
146
156
  end
147
157
 
148
158
  describe '#request' do
@@ -26,4 +26,20 @@ describe 'MyJohnDeereApi::Request::Create::Base' do
26
26
  assert_equal expected, headers['Content-Type']
27
27
  end
28
28
  end
29
+
30
+ describe '#validate_contribution_definition' do
31
+ it 'does nothing when contribution_definition_id is present' do
32
+ object = klass.new(client, attributes)
33
+ assert object.send(:validate_contribution_definition)
34
+ end
35
+
36
+ it 'raises an error when contribution_definition_id is missing' do
37
+ client.contribution_definition_id = nil
38
+ object = klass.new(client, attributes)
39
+
40
+ assert_raises(JD::MissingContributionDefinitionIdError) do
41
+ object.send(:validate_contribution_definition)
42
+ end
43
+ end
44
+ end
29
45
  end
@@ -78,6 +78,15 @@ describe 'MyJohnDeereApi::Request::Update::Asset' do
78
78
  assert_equal "#{base_url}/contributionDefinitions/#{contribution_definition_id}",
79
79
  body[:links].first['uri']
80
80
  end
81
+
82
+ it 'raises an exception when contribution_definition_id is not set' do
83
+ client.contribution_definition_id = nil
84
+ object = klass.new(client, item, attributes)
85
+
86
+ assert_raises(JD::MissingContributionDefinitionIdError) do
87
+ object.send(:request_body)
88
+ end
89
+ end
81
90
  end
82
91
 
83
92
  describe '#request' do
@@ -57,4 +57,20 @@ describe 'MyJohnDeereApi::Request::Update::Base' do
57
57
  assert_equal expected, headers['Content-Type']
58
58
  end
59
59
  end
60
+
61
+ describe '#validate_contribution_definition' do
62
+ it 'does nothing when contribution_definition_id is present' do
63
+ object = klass.new(client, item, attributes)
64
+ assert object.send(:validate_contribution_definition)
65
+ end
66
+
67
+ it 'raises an error when contribution_definition_id is missing' do
68
+ client.contribution_definition_id = nil
69
+ object = klass.new(client, item, attributes)
70
+
71
+ assert_raises(JD::MissingContributionDefinitionIdError) do
72
+ object.send(:validate_contribution_definition)
73
+ end
74
+ end
75
+ end
60
76
  end
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.4
4
+ version: 2.3.0
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-16 00:00:00.000000000 Z
12
+ date: 2020-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vcr
@@ -108,6 +108,7 @@ files:
108
108
  - lib/my_john_deere_api/consumer.rb
109
109
  - lib/my_john_deere_api/errors.rb
110
110
  - lib/my_john_deere_api/errors/invalid_record_error.rb
111
+ - lib/my_john_deere_api/errors/missing_contribution_definition_id_error.rb
111
112
  - lib/my_john_deere_api/errors/not_yet_implemented_error.rb
112
113
  - lib/my_john_deere_api/errors/type_mismatch_error.rb
113
114
  - lib/my_john_deere_api/errors/unsupported_environment_error.rb
@@ -157,6 +158,7 @@ files:
157
158
  - test/lib/my_john_deere_api/client_test.rb
158
159
  - test/lib/my_john_deere_api/consumer_test.rb
159
160
  - test/lib/my_john_deere_api/errors/invalid_record_error_test.rb
161
+ - test/lib/my_john_deere_api/errors/missing_contribution_definition_id_error_test.rb
160
162
  - test/lib/my_john_deere_api/errors/not_yet_implemented_error_test.rb
161
163
  - test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb
162
164
  - test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb