my_john_deere_api 0.5.2 → 0.5.3

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: 4517a78430360d8ba494a5e64a206eb6924cd9ee1d9c1bcdfff6a823f17496e8
4
- data.tar.gz: a0788ce8e4ead19974e675dbca2bf515ab530aaa0cfc561c914ab23651767d93
3
+ metadata.gz: 601608699538179bc7ddc8d1254e7eb8372330454ec4efca84888124c0e9a6d8
4
+ data.tar.gz: 283de34a0dc91842e298006a454d10359e8c6e24636fc867c813be6704d32633
5
5
  SHA512:
6
- metadata.gz: 8baaae2f1eb4d639b31b85d0a5450fd46442d31e88f2f3495465774fd445370c0433d43ef4d0a76abb61d6495ff9bc573e4185a19fda71e3b018000ddb18eaf7
7
- data.tar.gz: 2a8e2e13cdd2ed7687fba31a10f61c7153198925120132743db6c15f857a323a822256159b1987682fab5e237ad475cd79882bc390e48552d6fdc070da21cfd0
6
+ metadata.gz: 4d722923f80db0b4d69afc7119062ad0b1b60baf8ed1ba7d6cf07b3fcc1316649c9f71372fa37e81864d5b1b9df0886c2d002da364ff2d912b45d8a3bab0f9b6
7
+ data.tar.gz: 178540687735cd42fdb64bb699eb16eed4f976aee180185789ae5268a16ca18f246a1be5ab730458e5b0ca1bf7ba364ee0c7a6cfa382581354b6821b47022224
@@ -41,6 +41,21 @@ class MyJohnDeereApi::Client
41
41
  JSON.parse(response.body)
42
42
  end
43
43
 
44
+ ##
45
+ # generic user-specific POSST request method that returns JSON
46
+
47
+ def post resource, body
48
+ resource = resource.to_s
49
+ resource = "/#{resource}" unless resource =~ /^\//
50
+ response = accessor.post(resource, body.to_json, post_headers)
51
+
52
+ if response.body.size > 0
53
+ JSON.parse(response.body)
54
+ else
55
+ {}
56
+ end
57
+ end
58
+
44
59
  ##
45
60
  # organizations associated with this access
46
61
 
@@ -71,4 +86,8 @@ class MyJohnDeereApi::Client
71
86
  def headers
72
87
  @headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
73
88
  end
89
+
90
+ def post_headers
91
+ @post_headers ||= headers.merge({'Content-Type' => 'application/vnd.deere.axiom.v3+json'})
92
+ end
74
93
  end
@@ -1,3 +1,4 @@
1
1
  module MyJohnDeereApi::Request
2
2
  autoload :Collection, 'my_john_deere_api/request/collection'
3
+ autoload :Create, 'my_john_deere_api/request/create'
3
4
  end
@@ -0,0 +1,5 @@
1
+ module MyJohnDeereApi::Request::Create
2
+ autoload :Base, 'my_john_deere_api/request/create/base'
3
+ autoload :Asset, 'my_john_deere_api/request/create/asset'
4
+ autoload :AssetLocation, 'my_john_deere_api/request/create/asset_location'
5
+ end
@@ -0,0 +1,10 @@
1
+ module MyJohnDeereApi
2
+ class Request::Create::Asset < Request::Create::Base
3
+ attr_reader :accessor, :attributes
4
+
5
+ def initialize(accessor, attributes)
6
+ @accessor = accessor
7
+ @attributes = attributes
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module MyJohnDeereApi
2
+ class Request::Create::AssetLocation < Request::Create::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MyJohnDeereApi
2
+ class Request::Create::Base
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.5.2'
2
+ VERSION='0.5.3'
3
3
  end
@@ -69,6 +69,55 @@ describe 'MyJohnDeereApi::Client' do
69
69
  end
70
70
  end
71
71
 
72
+ describe '#post' do
73
+ let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
74
+
75
+ let(:body) do
76
+ {
77
+ "@type": "FlagCategory",
78
+ "categoryTitle": "Mountain Dew",
79
+ "sourceNode": "7ba95d7a-f798-46d0-9bf9-c39c31bcf984",
80
+ "links": [
81
+ {
82
+ "rel": "contributionDefinition",
83
+ "uri": "https://sandboxapi.deere.com/platform/contributionDefinitions/#{ENV['CONTRIBUTION_DEFINITION_ID']}"
84
+ }
85
+ ],
86
+ "preferred": true
87
+ }
88
+ end
89
+
90
+ it 'returns the response as a Hash' do
91
+ VCR.use_cassette('catalog') { client.send(:accessor) }
92
+
93
+ response = VCR.use_cassette('post_flag_categories') { client.post("/organizations/#{ENV['ORGANIZATION_ID']}/flagCategories", body) }
94
+
95
+ assert_equal Hash.new, response
96
+ end
97
+
98
+ # it 'prepends the leading slash if needed' do
99
+ # client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
100
+ # VCR.use_cassette('catalog') { client.send(:accessor) }
101
+ # response = VCR.use_cassette('get_organizations') { client.get('organizations') }
102
+ #
103
+ # assert_kind_of Hash, response
104
+ # assert_kind_of Integer, response['total']
105
+ # assert response['values'].all?{|value| value['@type'] == 'Organization'}
106
+ # assert response['values'].all?{|value| value.has_key?('links')}
107
+ # end
108
+ #
109
+ # it 'allows symbols for simple resources' do
110
+ # client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
111
+ # VCR.use_cassette('catalog') { client.send(:accessor) }
112
+ # response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
113
+ #
114
+ # assert_kind_of Hash, response
115
+ # assert_kind_of Integer, response['total']
116
+ # assert response['values'].all?{|value| value['@type'] == 'Organization'}
117
+ # assert response['values'].all?{|value| value.has_key?('links')}
118
+ # end
119
+ end
120
+
72
121
  describe '#organizations' do
73
122
  it 'returns a collection of organizations for this account' do
74
123
  client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
@@ -0,0 +1,10 @@
1
+ require 'support/helper'
2
+
3
+ describe 'MyJohnDeereApi::Request::Create::AssetLocation' do
4
+ let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
5
+ let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
6
+
7
+ describe '#initialize(access_token, attributes)' do
8
+
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'support/helper'
2
+
3
+ describe 'MyJohnDeereApi::Request::Create::Asset' do
4
+ let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
5
+ let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
6
+
7
+ describe '#initialize(access_token, attributes)' do
8
+ it 'accepts an accessor and attributes' do
9
+ attributes = {attribute: 'value'}
10
+ object = JD::Request::Create::Asset.new(accessor, attributes)
11
+
12
+ assert_equal accessor, object.accessor
13
+ assert_equal attributes, object.attributes
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ require 'support/helper'
2
+
3
+ describe 'MyJohnDeereApi::Request::Create::Base' do
4
+ let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
5
+ let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
6
+
7
+ describe '#initialize(access_token, attributes)' do
8
+
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'support/helper'
2
+
3
+ describe 'MyJohnDeereApi::Request::Create' do
4
+ describe 'loading dependencies' do
5
+ it 'loads Request::Create::Base' do
6
+ assert JD::Request::Create::Base
7
+ end
8
+
9
+ it 'loads Request::Create::Asset' do
10
+ assert JD::Request::Create::Asset
11
+ end
12
+
13
+ it 'loads Request::Create::AssetLocation' do
14
+ assert JD::Request::Create::AssetLocation
15
+ end
16
+ end
17
+ end
@@ -5,5 +5,9 @@ describe 'MyJohnDeereApi::Request' do
5
5
  it 'loads Request::Collection' do
6
6
  assert JD::Request::Collection
7
7
  end
8
+
9
+ it 'loads Request::Create' do
10
+ assert JD::Request::Create
11
+ end
8
12
  end
9
13
  end
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://sandboxapi.deere.com/platform/organizations/444563/flagCategories
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"@type":"FlagCategory","categoryTitle":"Mountain Dew","sourceNode":"7ba95d7a-f798-46d0-9bf9-c39c31bcf984","links":[{"rel":"contributionDefinition","uri":"https://sandboxapi.deere.com/platform/contributionDefinitions/d93611c7-6f74-474f-9569-2cf88f866a32"}],"preferred":true}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.deere.axiom.v3+json
12
+ Content-Type:
13
+ - application/vnd.deere.axiom.v3+json
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ User-Agent:
17
+ - OAuth gem v0.5.4
18
+ Content-Length:
19
+ - '274'
20
+ Authorization:
21
+ - OAuth oauth_body_hash="aNgumBwEzeKYfLOtt5eKxESOxZw%3D", oauth_consumer_key="johndeere-wgmADngYCRmfpEbVgSyc709wnyRux5J7PAv8SE7B",
22
+ oauth_nonce="wTCf5Hv2r9t83Zfm7DkZaRQleb9TAz5Y1aeVElSU08", oauth_signature="arrFHdesSS315MPGWJWz%2FCYbrLE%3D",
23
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1579215133", oauth_token="47bbb9c9-41a8-4bec-8127-e3c5760af2f6",
24
+ oauth_version="1.0"
25
+ response:
26
+ status:
27
+ code: 409
28
+ message: Conflict
29
+ headers:
30
+ Date:
31
+ - Thu, 16 Jan 2020 22:52:13 GMT
32
+ X-Deere-Handling-Server:
33
+ - ip-10-214-45-154
34
+ X-Frame-Options:
35
+ - SAMEORIGIN
36
+ Location:
37
+ - https://sandboxapi.deere.com/platform/flagCategories/b57110f3-0297-461c-81aa-d3b16e111d4d
38
+ X-Deere-Elapsed-Ms:
39
+ - '420'
40
+ Content-Length:
41
+ - '0'
42
+ Connection:
43
+ - close
44
+ body:
45
+ encoding: UTF-8
46
+ string: ''
47
+ http_version:
48
+ recorded_at: Thu, 16 Jan 2020 22:52:14 GMT
49
+ recorded_with: VCR 5.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_john_deere_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime. Bellmyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vcr
@@ -120,6 +120,10 @@ files:
120
120
  - lib/my_john_deere_api/request/collection/fields.rb
121
121
  - lib/my_john_deere_api/request/collection/flags.rb
122
122
  - lib/my_john_deere_api/request/collection/organizations.rb
123
+ - lib/my_john_deere_api/request/create.rb
124
+ - lib/my_john_deere_api/request/create/asset.rb
125
+ - lib/my_john_deere_api/request/create/asset_location.rb
126
+ - lib/my_john_deere_api/request/create/base.rb
123
127
  - lib/my_john_deere_api/version.rb
124
128
  - test/lib/my_john_deere_api/authorize_test.rb
125
129
  - test/lib/my_john_deere_api/client_test.rb
@@ -144,6 +148,10 @@ files:
144
148
  - test/lib/my_john_deere_api/request/collection/flags_test.rb
145
149
  - test/lib/my_john_deere_api/request/collection/organizations_test.rb
146
150
  - test/lib/my_john_deere_api/request/collection_test.rb
151
+ - test/lib/my_john_deere_api/request/create/asset_location_test.rb
152
+ - test/lib/my_john_deere_api/request/create/asset_test.rb
153
+ - test/lib/my_john_deere_api/request/create/base_test.rb
154
+ - test/lib/my_john_deere_api/request/create_test.rb
147
155
  - test/lib/my_john_deere_api/request_test.rb
148
156
  - test/lib/my_john_deere_api/version_test.rb
149
157
  - test/my_john_deere_api_test.rb
@@ -157,6 +165,7 @@ files:
157
165
  - test/support/vcr/get_flags.yml
158
166
  - test/support/vcr/get_organizations.yml
159
167
  - test/support/vcr/get_request_token.yml
168
+ - test/support/vcr/post_flag_categories.yml
160
169
  homepage: https://github.com/Intellifarm/my_john_deere_api
161
170
  licenses:
162
171
  - MIT