my_john_deere_api 0.0.4 → 0.1.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: 1972b07d8f4e72723a8984e459a5fc97e7587914b06415dcd2ce181d6db3c43b
4
- data.tar.gz: 6ecea1bd5fef0c60e04c510674c54adae3dd80967f3132fbba68e54d199a57e9
3
+ metadata.gz: dbad97d98f7f86489ff758e97b1f8e596db52adef1a0948618e073cacd393f6d
4
+ data.tar.gz: 268f2309b43dc543268d5ad97151b4a4f6fb4e84ba8a7a6504e4f35a78177616
5
5
  SHA512:
6
- metadata.gz: 905162ea13bdb92ef6a7a1c0d86db73e351c0edf8f3b8420a8cb93193eb6e0e4e717436ca535b705636c0fe01256ee2797e9ae20f9e020b515cc15ad0e649c3b
7
- data.tar.gz: 28a612aab3944a40bf19e23bc3640db8cdcff1e78faed99e374320df64ceb7441df5b92171e5aa2c0beb56ef90c26aa3dd2bae3cd5a061d4c3ba96277142f837
6
+ metadata.gz: 02cdd40ea10657f8a4102c185fce3114da462fb68e52688dfb219ff4dbf36ab9a621f2e6be6bd1713312097a8ebeb7466dd3976a019a803b1300e51a5b1a7bfa
7
+ data.tar.gz: 13c524f8779b12210e40fcf632ecb171e088a942b30215a1d049559bdacf7bd4e3211c26d0ea9fa29fecacca5f948cae4703dc423803e63d80e21198b19fc236
@@ -30,6 +30,17 @@ class MyJohnDeereApi::Client
30
30
  @environment = options[:environment]
31
31
  end
32
32
 
33
+ ##
34
+ # generic user-specific GET request method that returns JSON
35
+
36
+ def get resource
37
+ resource = resource.to_s
38
+ resource = "/#{resource}" unless resource =~ /^\//
39
+ response = accessor.get(resource, headers)
40
+
41
+ JSON.parse(response.body)
42
+ end
43
+
33
44
  private
34
45
 
35
46
  ##
@@ -48,4 +59,8 @@ class MyJohnDeereApi::Client
48
59
  return @accessor if defined?(@accessor)
49
60
  @accessor = OAuth::AccessToken.new(consumer.user_get, access_token, access_secret)
50
61
  end
62
+
63
+ def headers
64
+ @headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
65
+ end
51
66
  end
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.0.4'
2
+ VERSION='0.1.0'
3
3
  end
@@ -34,6 +34,41 @@ describe 'MyJohnDeereApi::Client' do
34
34
  end
35
35
  end
36
36
 
37
+ describe '#get' do
38
+ it 'returns the response as a Hash' do
39
+ client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
40
+ VCR.use_cassette('catalog') { client.send(:accessor) }
41
+ response = VCR.use_cassette('get_organizations') { client.get('/organizations') }
42
+
43
+ assert_kind_of Hash, response
44
+ assert_equal 2, response['total']
45
+ assert response['values'].all?{|value| value['@type'] == 'Organization'}
46
+ assert response['values'].all?{|value| value.has_key?('links')}
47
+ end
48
+
49
+ it 'prepends the leading slash if needed' do
50
+ client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
51
+ VCR.use_cassette('catalog') { client.send(:accessor) }
52
+ response = VCR.use_cassette('get_organizations') { client.get('organizations') }
53
+
54
+ assert_kind_of Hash, response
55
+ assert_equal 2, response['total']
56
+ assert response['values'].all?{|value| value['@type'] == 'Organization'}
57
+ assert response['values'].all?{|value| value.has_key?('links')}
58
+ end
59
+
60
+ it 'allows symbols for simple resources' do
61
+ client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
62
+ VCR.use_cassette('catalog') { client.send(:accessor) }
63
+ response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
64
+
65
+ assert_kind_of Hash, response
66
+ assert_equal 2, response['total']
67
+ assert response['values'].all?{|value| value['@type'] == 'Organization'}
68
+ assert response['values'].all?{|value| value.has_key?('links')}
69
+ end
70
+ end
71
+
37
72
  describe '#consumer' do
38
73
  it 'receives the api key/secret and environment of the client' do
39
74
  environment = :sandbox
@@ -51,7 +86,6 @@ describe 'MyJohnDeereApi::Client' do
51
86
  describe '#accessor' do
52
87
  it 'returns an object that can make user-specific requests' do
53
88
  client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
54
- consumer = client.send(:consumer)
55
89
  accessor = VCR.use_cassette('catalog') { client.send :accessor }
56
90
 
57
91
  assert_kind_of OAuth::AccessToken, accessor
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://sandboxapi.deere.com/platform/organizations
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/vnd.deere.axiom.v3+json
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ User-Agent:
15
+ - OAuth gem v0.5.4
16
+ Authorization:
17
+ - OAuth oauth_consumer_key="johndeere-wgmADngYCRmfpEbVgSyc709wnyRux5J7PAv8SE7B",
18
+ oauth_nonce="kndkJ0Y5SmSiWKPLw7e1peNgotFj5t2hHkpX89mmQWk", oauth_signature="uSxP9P%2BZcpG7dZwZhOQM7noYcTI%3D",
19
+ oauth_signature_method="HMAC-SHA1", oauth_timestamp="1578435671", oauth_token="47bbb9c9-41a8-4bec-8127-e3c5760af2f6",
20
+ oauth_version="1.0"
21
+ response:
22
+ status:
23
+ code: 200
24
+ message: OK
25
+ headers:
26
+ Date:
27
+ - Tue, 07 Jan 2020 22:21:12 GMT
28
+ Content-Type:
29
+ - application/vnd.deere.axiom.v3+json;charset=UTF-8
30
+ X-Deere-Handling-Server:
31
+ - ip-10-214-44-238
32
+ X-Frame-Options:
33
+ - SAMEORIGIN
34
+ X-Deere-Elapsed-Ms:
35
+ - '115'
36
+ Cache-Control:
37
+ - no-store
38
+ Content-Language:
39
+ - en-US
40
+ Transfer-Encoding:
41
+ - chunked
42
+ body:
43
+ encoding: ASCII-8BIT
44
+ string: '{"links":[{"rel":"self","uri":"https://sandboxapi.deere.com/platform/organizations"}],"total":2,"values":[{"@type":"Organization","name":"Century
45
+ Farms","type":"customer","member":true,"id":"444563","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/organizations/444563"},{"@type":"Link","rel":"machines","uri":"https://sandboxapi.deere.com/platform/organizations/444563/machines"},{"@type":"Link","rel":"wdtCapableMachines","uri":"https://sandboxapi.deere.com/platform/organizations/444563/machines?capability=wdt"},{"@type":"Link","rel":"files","uri":"https://sandboxapi.deere.com/platform/organizations/444563/files"},{"@type":"Link","rel":"transferableFiles","uri":"https://sandboxapi.deere.com/platform/organizations/444563/files?transferable=true"},{"@type":"Link","rel":"uploadFile","uri":"https://sandboxapi.deere.com/platform/organizations/444563/files"},{"@type":"Link","rel":"sendFileToMachine","uri":"https://sandboxapi.deere.com/platform/organizations/444563/fileTransfers"},{"@type":"Link","rel":"addMachine","uri":"https://sandboxapi.deere.com/platform/organizations/444563/machines"},{"@type":"Link","rel":"addField","uri":"https://sandboxapi.deere.com/platform/organizations/444563/fields"},{"@type":"Link","rel":"assets","uri":"https://sandboxapi.deere.com/platform/organizations/444563/assets"},{"@type":"Link","rel":"fields","uri":"https://sandboxapi.deere.com/platform/organizations/444563/fields"},{"@type":"Link","rel":"farms","uri":"https://sandboxapi.deere.com/platform/organizations/444563/farms"},{"@type":"Link","rel":"boundaries","uri":"https://sandboxapi.deere.com/platform/organizations/444563/boundaries"},{"@type":"Link","rel":"clients","uri":"https://sandboxapi.deere.com/platform/organizations/444563/clients"},{"@type":"Link","rel":"controllers","uri":"https://sandboxapi.deere.com/platform/organizations/444563/orgController"}]},{"@type":"Organization","name":"JJ''s
46
+ Farm","type":"customer","member":true,"id":"443911","links":[{"@type":"Link","rel":"self","uri":"https://sandboxapi.deere.com/platform/organizations/443911"},{"@type":"Link","rel":"machines","uri":"https://sandboxapi.deere.com/platform/organizations/443911/machines"},{"@type":"Link","rel":"wdtCapableMachines","uri":"https://sandboxapi.deere.com/platform/organizations/443911/machines?capability=wdt"},{"@type":"Link","rel":"files","uri":"https://sandboxapi.deere.com/platform/organizations/443911/files"},{"@type":"Link","rel":"transferableFiles","uri":"https://sandboxapi.deere.com/platform/organizations/443911/files?transferable=true"},{"@type":"Link","rel":"uploadFile","uri":"https://sandboxapi.deere.com/platform/organizations/443911/files"},{"@type":"Link","rel":"sendFileToMachine","uri":"https://sandboxapi.deere.com/platform/organizations/443911/fileTransfers"},{"@type":"Link","rel":"addMachine","uri":"https://sandboxapi.deere.com/platform/organizations/443911/machines"},{"@type":"Link","rel":"addField","uri":"https://sandboxapi.deere.com/platform/organizations/443911/fields"},{"@type":"Link","rel":"assets","uri":"https://sandboxapi.deere.com/platform/organizations/443911/assets"},{"@type":"Link","rel":"fields","uri":"https://sandboxapi.deere.com/platform/organizations/443911/fields"},{"@type":"Link","rel":"farms","uri":"https://sandboxapi.deere.com/platform/organizations/443911/farms"},{"@type":"Link","rel":"boundaries","uri":"https://sandboxapi.deere.com/platform/organizations/443911/boundaries"},{"@type":"Link","rel":"clients","uri":"https://sandboxapi.deere.com/platform/organizations/443911/clients"},{"@type":"Link","rel":"controllers","uri":"https://sandboxapi.deere.com/platform/organizations/443911/orgController"}]}]}'
47
+ http_version:
48
+ recorded_at: Tue, 07 Jan 2020 22:21:13 GMT
49
+ recorded_with: VCR 5.0.0
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.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime. Bellmyer
@@ -108,6 +108,7 @@ files:
108
108
  - test/support/vcr/app_consumer.yml
109
109
  - test/support/vcr/catalog.yml
110
110
  - test/support/vcr/get_access_token.yml
111
+ - test/support/vcr/get_organizations.yml
111
112
  - test/support/vcr/get_request_token.yml
112
113
  - test/test_my_john_deere_api.rb
113
114
  homepage: https://github.com/Intellifarm/my_john_deere_api