my_john_deere_api 0.8.2 → 0.9.0

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: 242077415772b4bb77b74351f3f98a50f5f4c593e12677ec500a2fb2dc13dced
4
- data.tar.gz: bd92b88d075ccd0cf741011426c27ce594b6021ead50f98c05e4426f53f614cd
3
+ metadata.gz: 41fea97474f3ff4ef830cfdd646087d1fa57e693f0da95075639da8c0ca83adf
4
+ data.tar.gz: 24afb45536681d94ddbd90d560090b4864e3bb4b839824a6247634eeb33641c4
5
5
  SHA512:
6
- metadata.gz: e6e5d1d1240261d1d987053f365ed1299f9c1b9d64b8194f19d4d95c155fceebd79b2bae1e039e7f755d831b40a34b461575a2c64267e257408d76d73deb4b00
7
- data.tar.gz: f0df1ab91d6fd93a74636a555bacc5ebca37ae1a8723c88884bf03f0244eb2a4576b26b2f112a3cd093ad602abedbd3ce54c0696cc82ce51ae688645ec66db4e
6
+ metadata.gz: ab7e7b57cd96c8e8bcc895e5ea275ac1afd56659b9bf74bb3f848acb15e4a5c7c77f1d979508ad606e0cb55ddefc8d30aa2748bfd9364f82149674572d1bcf5c
7
+ data.tar.gz: 0a5fb27c9d4206ecaad1b80e037d37d229dcd4be26cd3b8b3ed19937ce561e3d2b79bb0ed5edfb5e1c724dae4301556d3486d486bf2aef90cd49f2902e8de50f
@@ -2,7 +2,7 @@ class MyJohnDeereApi::Authorize
2
2
  attr_reader :api_key, :api_secret,
3
3
  :request_token, :request_secret,
4
4
  :access_token, :access_secret,
5
- :environment
5
+ :environment, :options
6
6
 
7
7
  DEFAULTS = {
8
8
  environment: :production
@@ -15,7 +15,7 @@ class MyJohnDeereApi::Authorize
15
15
  # on behalf of a user.
16
16
 
17
17
  def initialize(api_key, api_secret, options = {})
18
- options = DEFAULTS.merge(options)
18
+ @options = DEFAULTS.merge(options)
19
19
 
20
20
  @api_key = api_key
21
21
  @api_secret = api_secret
@@ -29,11 +29,13 @@ class MyJohnDeereApi::Authorize
29
29
  def authorize_url
30
30
  return @authorize_url if defined?(@authorize_url)
31
31
 
32
- requester = consumer.get_request_token
32
+ request_options = options.slice(:oauth_callback)
33
+
34
+ requester = consumer.get_request_token(request_options)
33
35
  @request_token = requester.token
34
36
  @request_secret = requester.secret
35
37
 
36
- @authorize_url = requester.authorize_url
38
+ @authorize_url = requester.authorize_url(request_options)
37
39
  end
38
40
 
39
41
  ##
@@ -59,13 +59,6 @@ module MyJohnDeereApi
59
59
  @is_valid = errors.empty?
60
60
  end
61
61
 
62
- ##
63
- # Run validations unique to a given model. This should be overridden
64
- # by children where needed.
65
-
66
- def validate_attributes
67
- end
68
-
69
62
  ##
70
63
  # Raises an error if the record is invalid. Passes the errors hash
71
64
  # to the error, in order to build a useful message string.
@@ -76,6 +69,13 @@ module MyJohnDeereApi
76
69
 
77
70
  private
78
71
 
72
+ ##
73
+ # Run validations unique to a given model. This should be overridden
74
+ # by children where needed.
75
+
76
+ def validate_attributes
77
+ end
78
+
79
79
  ##
80
80
  # Convert inputs into working attributes. This allows us to auto-create
81
81
  # some attributes from others, or set defaults, on a class-by-class basis.
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.8.2'
2
+ VERSION='0.9.0'
3
3
  end
@@ -12,6 +12,9 @@ describe 'MyJohnDeereApi::Request::Collection::AssetLocations' do
12
12
  let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
13
13
  let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
14
14
  let(:collection) { JD::Request::Collection::AssetLocations.new(accessor, asset: asset_id) }
15
+ let(:object) { collection }
16
+
17
+ inherits_from JD::Request::Collection::Base
15
18
 
16
19
  describe '#initialize(access_token)' do
17
20
  it 'accepts an access token' do
@@ -12,6 +12,9 @@ describe 'MyJohnDeereApi::Request::Collection::Assets' do
12
12
  let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
13
13
  let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
14
14
  let(:collection) { JD::Request::Collection::Assets.new(accessor, organization: organization_id) }
15
+ let(:object) { collection }
16
+
17
+ inherits_from JD::Request::Collection::Base
15
18
 
16
19
  describe '#initialize(access_token)' do
17
20
  it 'accepts an access token' do
@@ -12,6 +12,9 @@ describe 'MyJohnDeereApi::Request::Collection::Fields' do
12
12
  let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
13
13
  let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
14
14
  let(:collection) { JD::Request::Collection::Fields.new(accessor, organization: organization_id) }
15
+ let(:object) { collection }
16
+
17
+ inherits_from JD::Request::Collection::Base
15
18
 
16
19
  describe '#initialize(access_token)' do
17
20
  it 'accepts an access token' do
@@ -18,6 +18,9 @@ describe 'MyJohnDeereApi::Request::Collection::Flags' do
18
18
  let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
19
19
  let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
20
20
  let(:collection) { JD::Request::Collection::Flags.new(accessor, organization: organization_id, field: field_id) }
21
+ let(:object) { collection }
22
+
23
+ inherits_from JD::Request::Collection::Base
21
24
 
22
25
  describe '#initialize(access_token)' do
23
26
  it 'accepts an access token' do
@@ -6,6 +6,9 @@ describe 'MyJohnDeereApi::Request::Collection::Organizations' do
6
6
  let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
7
7
  let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
8
8
  let(:collection) { JD::Request::Collection::Organizations.new(accessor) }
9
+ let(:object) { collection }
10
+
11
+ inherits_from JD::Request::Collection::Base
9
12
 
10
13
  describe '#initialize(access_token)' do
11
14
  it 'accepts an access token' do
@@ -49,10 +49,12 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
49
49
 
50
50
  let(:attributes) { valid_attributes }
51
51
 
52
+ let(:object) { JD::Request::Create::AssetLocation.new(accessor, attributes) }
53
+
54
+ inherits_from MyJohnDeereApi::Request::Create::Base
55
+
52
56
  describe '#initialize(access_token, attributes)' do
53
57
  it 'accepts an accessor and attributes' do
54
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
55
-
56
58
  assert_equal accessor, object.accessor
57
59
  assert_equal attributes, object.attributes
58
60
  end
@@ -70,8 +72,6 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
70
72
  measurement_data: measurement_data
71
73
  }
72
74
 
73
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
74
-
75
75
  assert_equal geometry.to_json, object.attributes[:geometry]
76
76
  end
77
77
 
@@ -88,8 +88,6 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
88
88
 
89
89
  describe '#valid?' do
90
90
  it 'returns true when all required attributes are present' do
91
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
92
-
93
91
  assert object.valid?
94
92
  assert_empty object.errors
95
93
  end
@@ -161,7 +159,6 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
161
159
 
162
160
  describe '#request_body' do
163
161
  it 'properly forms the request body' do
164
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
165
162
  body = object.send(:request_body)
166
163
 
167
164
  assert_kind_of Array, body
@@ -173,7 +170,6 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
173
170
 
174
171
  describe '#request' do
175
172
  it 'makes the request' do
176
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
177
173
  VCR.use_cassette('post_asset_locations') { object.request }
178
174
 
179
175
  assert_kind_of Net::HTTPCreated, object.response
@@ -182,7 +178,6 @@ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
182
178
 
183
179
  describe '#object' do
184
180
  it 'returns the asset location model instance' do
185
- object = JD::Request::Create::AssetLocation.new(accessor, attributes)
186
181
  result = VCR.use_cassette('post_asset_locations') { object.object }
187
182
 
188
183
  assert_kind_of JD::Model::AssetLocation, result
@@ -27,12 +27,14 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
27
27
  }
28
28
  end
29
29
 
30
+ let(:object) { JD::Request::Create::Asset.new(accessor, attributes) }
31
+
30
32
  let(:attributes) { valid_attributes }
31
33
 
34
+ inherits_from MyJohnDeereApi::Request::Create::Base
35
+
32
36
  describe '#initialize(access_token, attributes)' do
33
37
  it 'accepts an accessor and attributes' do
34
- object = JD::Request::Create::Asset.new(accessor, attributes)
35
-
36
38
  assert_equal accessor, object.accessor
37
39
  assert_equal attributes, object.attributes
38
40
  end
@@ -45,8 +47,6 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
45
47
 
46
48
  describe '#valid?' do
47
49
  it 'returns true when all required attributes are present' do
48
- object = JD::Request::Create::Asset.new(accessor, attributes)
49
-
50
50
  assert object.valid?
51
51
  assert_empty object.errors
52
52
  end
@@ -173,7 +173,6 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
173
173
 
174
174
  describe '#request' do
175
175
  it 'makes the request' do
176
- object = JD::Request::Create::Asset.new(accessor, attributes)
177
176
  VCR.use_cassette('post_assets') { object.request }
178
177
 
179
178
  assert_kind_of Net::HTTPCreated, object.response
@@ -20,4 +20,23 @@ SECRET_PATTERN = /^[0-9A-Za-z\-+=\/]+$/
20
20
  VCR.configure do |config|
21
21
  config.cassette_library_dir = 'test/support/vcr'
22
22
  config.hook_into :webmock
23
+ end
24
+
25
+ class Minitest::Spec
26
+ class << self
27
+ def inherits_from klass
28
+ it "inherits from #{klass}" do
29
+ public_methods = Hash.new([]).merge({
30
+ JD::Request::Create::Base => [:request, :object, :valid?, :validate!],
31
+ JD::Request::Collection::Base => [:each, :all, :count],
32
+ })
33
+
34
+ assert_kind_of klass, object
35
+
36
+ public_methods[klass].each do |method_name|
37
+ assert object.respond_to?(method_name)
38
+ end
39
+ end
40
+ end
41
+ end
23
42
  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: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime. Bellmyer