my_john_deere_api 1.3.7 → 2.0.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: 347239b756637538b1565dac76ef8d922b11fe4d473811b14a9e8f7edf134902
4
- data.tar.gz: 670ee3f6c1ad3f8845166f9c82d8f46ad21a1c5faf4f0cd05da6b24ffc3a4fd5
3
+ metadata.gz: 12dd779b0061a90ac8b9d20b3a5111fe1b8f76ebf4153817480abe886a4d45f0
4
+ data.tar.gz: 8d4bf6db2d2dd9a720c500c0300ff9409766ed639f3191154de6319bae5d171e
5
5
  SHA512:
6
- metadata.gz: 4ee286908de1b144b7d00687e28025e6d92a9d19bf7468bfbf3e4489a8c0340b69cb92f1177b2738d13ab16e6c6b908f2cfcd57be4e00c03d954a62679dd36a8
7
- data.tar.gz: 73308deefd549de1ff76220b14a0a267b2583fe2c2f5216a423091faaff9cebe9ea06cf20b02df63407af3f7a916de9198c21152e92eed60f8812ae10d5e3058
6
+ metadata.gz: 5af6c3d0843479c8c05cdc36f3cbb1645b26a76e41de187ff513ba78089586c1a890c229918a39ffc3599b4f989b718a288a78f208f72fcd8027dccb2381861b
7
+ data.tar.gz: 59e8a16606a6b002b91970745894759af3e69d0a674dd1e01f2099acf4836ed61afabcaba9ffbe298f40ac71ca078a5d614923a095864db6ecc9998a1ad2a669
@@ -3,14 +3,15 @@ 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, :environment
6
+ attr_reader :api_key, :api_secret, :access_token, :access_secret,
7
+ :contribution_definition_id
7
8
 
8
9
  DEFAULTS = {
9
10
  environment: :live
10
11
  }
11
12
 
12
13
  ##
13
- # Creates the client with everthing it needs to perform API requests.
14
+ # Creates the client with everything it needs to perform API requests.
14
15
  # User-specific credentials are optional, but user-specific API
15
16
  # requests are only possible if they are supplied.
16
17
  #
@@ -18,6 +19,9 @@ module MyJohnDeereApi
18
19
  #
19
20
  # [:environment] :sandbox or :live
20
21
  #
22
+ # [:contribution_definition_id] optional, but needed for some requests
23
+ # like asset create/update.
24
+ #
21
25
  # [:access] an array with two elements, the access_token
22
26
  # and the access_secret of the given user
23
27
 
@@ -32,6 +36,7 @@ module MyJohnDeereApi
32
36
  end
33
37
 
34
38
  self.environment = options[:environment]
39
+ @contribution_definition_id = options[:contribution_definition_id]
35
40
  end
36
41
 
37
42
  ##
@@ -45,7 +45,7 @@ module MyJohnDeereApi
45
45
  {
46
46
  '@type' => 'Link',
47
47
  'rel' => 'contributionDefinition',
48
- 'uri' => "#{accessor.consumer.site}/contributionDefinitions/#{attributes[:contribution_definition_id]}"
48
+ 'uri' => "#{accessor.consumer.site}/contributionDefinitions/#{client.contribution_definition_id}"
49
49
  }
50
50
  ]
51
51
  }
@@ -28,7 +28,7 @@ module MyJohnDeereApi
28
28
  {
29
29
  '@type' => 'Link',
30
30
  'rel' => 'contributionDefinition',
31
- 'uri' => "#{accessor.consumer.site}/contributionDefinitions/#{attributes[:contribution_definition_id]}"
31
+ 'uri' => "#{accessor.consumer.site}/contributionDefinitions/#{client.contribution_definition_id}"
32
32
  }
33
33
  ]
34
34
  }
@@ -16,7 +16,7 @@ module MyJohnDeereApi::Validators
16
16
  private
17
17
 
18
18
  def required_attributes
19
- [:organization_id, :contribution_definition_id, :title]
19
+ [:organization_id, :title]
20
20
  end
21
21
 
22
22
  def validate_attributes
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='1.3.7'
2
+ VERSION='2.0.0'
3
3
  end
@@ -30,6 +30,11 @@ describe 'MyJohnDeereApi::Client' do
30
30
  client = JD::Client.new(api_key, api_secret, environment: environment)
31
31
  assert_equal environment, client.environment
32
32
  end
33
+
34
+ it 'accepts a contribution_definition_id' do
35
+ client = JD::Client.new(api_key, api_secret, contribution_definition_id: contribution_definition_id)
36
+ assert_equal contribution_definition_id, client.contribution_definition_id
37
+ end
33
38
  end
34
39
 
35
40
  describe '#get' do
@@ -63,12 +68,12 @@ describe 'MyJohnDeereApi::Client' do
63
68
 
64
69
  describe '#post' do
65
70
  let(:attributes) do
66
- CONFIG.sanitized_asset_attributes.merge(
71
+ CONFIG.asset_attributes.merge(
67
72
  links: [
68
73
  {
69
74
  '@type' => 'Link',
70
75
  'rel' => 'contributionDefinition',
71
- 'uri' => "#{CONFIG.url}/contributionDefinitions/#{CONFIG.sanitized_asset_attributes[:contribution_definition_id]}"
76
+ 'uri' => "#{CONFIG.url}/contributionDefinitions/#{contribution_definition_id}"
72
77
  }
73
78
  ]
74
79
  )
@@ -99,7 +104,7 @@ describe 'MyJohnDeereApi::Client' do
99
104
  let(:new_title) { 'i REALLY like turtles!' }
100
105
 
101
106
  let(:attributes) do
102
- CONFIG.sanitized_asset_attributes.slice(
107
+ CONFIG.asset_attributes.slice(
103
108
  :asset_category, :asset_type, :asset_sub_type, :links
104
109
  ).merge(
105
110
  title: new_title,
@@ -107,7 +112,7 @@ describe 'MyJohnDeereApi::Client' do
107
112
  {
108
113
  '@type' => 'Link',
109
114
  'rel' => 'contributionDefinition',
110
- 'uri' => "#{CONFIG.url}/contributionDefinitions/#{CONFIG.sanitized_asset_attributes[:contribution_definition_id]}"
115
+ 'uri' => "#{CONFIG.url}/contributionDefinitions/#{contribution_definition_id}"
111
116
  }
112
117
  ]
113
118
  )
@@ -43,7 +43,7 @@ describe 'MyJohnDeereApi::Request::Collection::Assets' do
43
43
 
44
44
  describe '#create(attributes)' do
45
45
  it 'creates a new asset with the given attributes' do
46
- attributes = CONFIG.sanitized_asset_attributes
46
+ attributes = CONFIG.asset_attributes
47
47
  object = VCR.use_cassette('post_assets') { collection.create(attributes) }
48
48
 
49
49
  assert_kind_of JD::Model::Asset, object
@@ -7,9 +7,8 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
7
7
  end
8
8
 
9
9
  let(:valid_attributes) do
10
- CONFIG.sanitized_asset_attributes.merge(
10
+ CONFIG.asset_attributes.merge(
11
11
  organization_id: organization_id,
12
- contribution_definition_id: contribution_definition_id,
13
12
  )
14
13
  end
15
14
 
@@ -41,13 +40,6 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
41
40
  assert_equal 'is required', object.errors[:organization_id]
42
41
  end
43
42
 
44
- it 'requires contribution_definition_id' do
45
- object = klass.new(client, attributes_without(:contribution_definition_id))
46
-
47
- refute object.valid?
48
- assert_equal 'is required', object.errors[:contribution_definition_id]
49
- end
50
-
51
43
  it 'requires title' do
52
44
  object = klass.new(client, attributes_without(:title))
53
45
 
@@ -137,7 +129,6 @@ describe 'MyJohnDeereApi::Request::Create::Asset' do
137
129
  it 'properly forms the request body' do
138
130
  object = klass.new(client, attributes)
139
131
  body = object.send(:request_body)
140
-
141
132
  assert_equal attributes[:title], body[:title]
142
133
  assert_equal attributes[:asset_category], body[:assetCategory]
143
134
  assert_equal attributes[:asset_type], body[:assetType]
@@ -8,7 +8,6 @@ describe 'MyJohnDeereApi::Request::Update::Asset' do
8
8
  let(:attributes) do
9
9
  {
10
10
  organization_id: organization_id,
11
- contribution_definition_id: contribution_definition_id
12
11
  }
13
12
  end
14
13
 
@@ -18,7 +18,6 @@ describe 'MyJohnDeereApi::Validators::Asset' do
18
18
  let(:valid_attributes) do
19
19
  {
20
20
  organization_id: '000000',
21
- contribution_definition_id: '00000000-0000-0000-0000-000000000000',
22
21
  title: "Bob's Stuff"
23
22
  }
24
23
  end
@@ -32,7 +31,7 @@ describe 'MyJohnDeereApi::Validators::Asset' do
32
31
  end
33
32
 
34
33
  it 'requires several attributes' do
35
- [:organization_id, :contribution_definition_id, :title].each do |attr|
34
+ [:organization_id, :title].each do |attr|
36
35
  object = klass.new(valid_attributes.merge(attr => nil))
37
36
 
38
37
  refute object.valid?
@@ -87,7 +87,13 @@ class VcrSetup
87
87
 
88
88
  # provide a client with sanitized credentials
89
89
  def client
90
- JD::Client.new(api_key, api_secret, environment: :sandbox, access: [access_token, access_secret])
90
+ JD::Client.new(
91
+ api_key,
92
+ api_secret,
93
+ contribution_definition_id: contribution_definition_id,
94
+ environment: :sandbox,
95
+ access: [access_token, access_secret]
96
+ )
91
97
  end
92
98
 
93
99
  def timestamp
@@ -138,17 +144,6 @@ class VcrSetup
138
144
 
139
145
  def asset_attributes
140
146
  @asset_attributes ||= {
141
- contribution_definition_id: ENV['CONTRIBUTION_DEFINITION_ID'],
142
- title: 'Asset Title',
143
- asset_category: 'DEVICE',
144
- asset_type: 'SENSOR',
145
- asset_sub_type: 'ENVIRONMENTAL'
146
- }.freeze
147
- end
148
-
149
- def sanitized_asset_attributes
150
- @sanitized_asset_attributes ||= {
151
- contribution_definition_id: contribution_definition_id,
152
147
  title: 'Asset Title',
153
148
  asset_category: 'DEVICE',
154
149
  asset_type: 'SENSOR',
@@ -195,6 +190,7 @@ class VcrSetup
195
190
  ENV['API_KEY'],
196
191
  ENV['API_SECRET'],
197
192
  environment: :sandbox,
193
+ contribution_definition_id: ENV['CONTRIBUTION_DEFINITION_ID'],
198
194
  access: [ENV['ACCESS_TOKEN'], ENV['ACCESS_SECRET']]
199
195
  )
200
196
  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: 1.3.7
4
+ version: 2.0.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-14 00:00:00.000000000 Z
12
+ date: 2020-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vcr