my_john_deere_api 0.12.4 → 0.12.6
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 +4 -4
- data/lib/my_john_deere_api/client.rb +10 -3
- data/lib/my_john_deere_api/model/contribution_product.rb +24 -0
- data/lib/my_john_deere_api/model/field.rb +1 -1
- data/lib/my_john_deere_api/model/organization.rb +1 -1
- data/lib/my_john_deere_api/model.rb +1 -0
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +2 -2
- data/lib/my_john_deere_api/request/collection/assets.rb +2 -2
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +26 -0
- data/lib/my_john_deere_api/request/collection.rb +1 -0
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +19 -0
- data/lib/my_john_deere_api/request/individual.rb +3 -2
- data/lib/my_john_deere_api/version.rb +1 -1
- data/test/lib/my_john_deere_api/authorize_test.rb +6 -6
- data/test/lib/my_john_deere_api/client_test.rb +31 -70
- data/test/lib/my_john_deere_api/consumer_test.rb +14 -14
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +8 -23
- data/test/lib/my_john_deere_api/model/asset_test.rb +6 -9
- data/test/lib/my_john_deere_api/model/base_test.rb +3 -4
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +68 -0
- data/test/lib/my_john_deere_api/model/field_test.rb +8 -11
- data/test/lib/my_john_deere_api/model/flag_test.rb +1 -1
- data/test/lib/my_john_deere_api/model/organization_test.rb +19 -22
- data/test/lib/my_john_deere_api/model_test.rb +4 -0
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +9 -48
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +9 -31
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +2 -5
- data/test/lib/my_john_deere_api/request/collection/contribution_products_test.rb +88 -0
- data/test/lib/my_john_deere_api/request/collection/fields_test.rb +4 -12
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +5 -19
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +2 -4
- data/test/lib/my_john_deere_api/request/collection_test.rb +4 -0
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +20 -50
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +10 -24
- data/test/lib/my_john_deere_api/request/create/base_test.rb +0 -2
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +0 -3
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +0 -3
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +32 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +4 -0
- data/test/support/helper.rb +56 -5
- data/test/support/vcr/catalog.yml +51 -7
- data/test/support/vcr/delete_asset.yml +51 -10
- data/test/support/vcr/get_access_token.yml +8 -8
- data/test/support/vcr/get_asset.yml +107 -10
- data/test/support/vcr/get_asset_locations.yml +154 -17
- data/test/support/vcr/get_assets.yml +110 -10
- data/test/support/vcr/get_contribution_product.yml +91 -0
- data/test/support/vcr/get_contribution_products.yml +91 -0
- data/test/support/vcr/get_fields.yml +108 -11
- data/test/support/vcr/get_flags.yml +11 -11
- data/test/support/vcr/get_organization.yml +90 -0
- data/test/support/vcr/get_organizations.yml +73 -30
- data/test/support/vcr/get_request_token.yml +14 -14
- data/test/support/vcr/post_asset_locations.yml +165 -20
- data/test/support/vcr/post_assets.yml +119 -22
- data/test/support/vcr/{app_consumer.yml → url.yml} +7 -7
- data/test/support/vcr/warning.txt +24 -0
- data/test/support/vcr_setup.rb +420 -0
- metadata +14 -4
- data/test/support/vcr/post_flag_categories.yml +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d79f9ae5d1b5b960422791626144c4ef7f5d812668c6b55ac0c08ee75c06ddc3
|
4
|
+
data.tar.gz: ac5d0b960dfd945dcf4c6a7f70824db56f6592acdf760fd43663b7b9d6506a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758d942d65896071bc7ac6340f83731faa02b53d9d96d56881d1adb0c3b5bc24dd1a613dd1d162a4be07bfcde8b99be3ec2375b476b958472e674bdaed4e6711
|
7
|
+
data.tar.gz: a21fa3beac2fe3cce6bbb7e33f7eda267fe6bd6f89a4a9e4f235b4106724d2efe73fddb46b9b6b9c1d84983db054bedc19a26b62ca8ec0a69be0abdf43fd71d2
|
@@ -55,7 +55,7 @@ module MyJohnDeereApi
|
|
55
55
|
if response.body.size > 0
|
56
56
|
JSON.parse(response.body)
|
57
57
|
else
|
58
|
-
|
58
|
+
response
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -70,7 +70,7 @@ module MyJohnDeereApi
|
|
70
70
|
if response.body && response.body.size > 0
|
71
71
|
JSON.parse(response.body)
|
72
72
|
else
|
73
|
-
|
73
|
+
response
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -79,7 +79,14 @@ module MyJohnDeereApi
|
|
79
79
|
|
80
80
|
def organizations
|
81
81
|
return @organizations if defined?(@organizations)
|
82
|
-
@organizations = MyJohnDeereApi::Request::Collection::Organizations.new(accessor)
|
82
|
+
@organizations = MyJohnDeereApi::Request::Collection::Organizations.new(accessor)
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# contribution products associated with this app (not user-specific)
|
87
|
+
|
88
|
+
def contribution_products
|
89
|
+
[]
|
83
90
|
end
|
84
91
|
|
85
92
|
private
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Model::ContributionProduct < Model::Base
|
3
|
+
attr_reader :market_place_name, :market_place_description, :default_locale,
|
4
|
+
:current_status, :activation_callback, :preview_images,
|
5
|
+
:supported_regions, :supported_operation_centers
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def map_attributes(record)
|
10
|
+
@market_place_name = record['marketPlaceName']
|
11
|
+
@market_place_description = record['marketPlaceDescription']
|
12
|
+
@default_locale = record['defaultLocale']
|
13
|
+
@current_status = record['currentStatus']
|
14
|
+
@activation_callback = record['activationCallback']
|
15
|
+
@preview_images = record['previewImages']
|
16
|
+
@supported_regions = record['supportedRegions']
|
17
|
+
@supported_operation_centers = record['supportedOperationCenters']
|
18
|
+
end
|
19
|
+
|
20
|
+
def expected_record_type
|
21
|
+
'ContributionProduct'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -17,7 +17,7 @@ module MyJohnDeereApi
|
|
17
17
|
raise AccessTokenError unless accessor
|
18
18
|
|
19
19
|
return @flags if defined?(@flags)
|
20
|
-
@flags = Request::Collection::Flags.new(accessor, organization: organization_id, field: id)
|
20
|
+
@flags = Request::Collection::Flags.new(accessor, organization: organization_id, field: id)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -19,7 +19,7 @@ module MyJohnDeereApi
|
|
19
19
|
raise AccessTokenError unless accessor
|
20
20
|
|
21
21
|
return @fields if defined?(@fields)
|
22
|
-
@fields = MyJohnDeereApi::Request::Collection::Fields.new(accessor, organization: id)
|
22
|
+
@fields = MyJohnDeereApi::Request::Collection::Fields.new(accessor, organization: id)
|
23
23
|
end
|
24
24
|
|
25
25
|
##
|
@@ -2,6 +2,7 @@ module MyJohnDeereApi::Model
|
|
2
2
|
autoload :Base, 'my_john_deere_api/model/base'
|
3
3
|
autoload :Asset, 'my_john_deere_api/model/asset'
|
4
4
|
autoload :AssetLocation, 'my_john_deere_api/model/asset_location'
|
5
|
+
autoload :ContributionProduct, 'my_john_deere_api/model/contribution_product'
|
5
6
|
autoload :Organization, 'my_john_deere_api/model/organization'
|
6
7
|
autoload :Field, 'my_john_deere_api/model/field'
|
7
8
|
autoload :Flag, 'my_john_deere_api/model/flag'
|
@@ -20,8 +20,8 @@ module MyJohnDeereApi::Request
|
|
20
20
|
# Create a new asset location
|
21
21
|
|
22
22
|
def create(attributes)
|
23
|
-
attributes.merge
|
24
|
-
Create::AssetLocation.new(accessor,
|
23
|
+
merged_attributes = attributes.merge(asset_id: associations[:asset])
|
24
|
+
Create::AssetLocation.new(accessor, merged_attributes).object
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -20,8 +20,8 @@ module MyJohnDeereApi::Request
|
|
20
20
|
# Create a new asset
|
21
21
|
|
22
22
|
def create(attributes)
|
23
|
-
attributes.merge
|
24
|
-
Create::Asset.new(accessor,
|
23
|
+
merged_attributes = attributes.merge(organization_id: associations[:organization])
|
24
|
+
Create::Asset.new(accessor, merged_attributes).object
|
25
25
|
end
|
26
26
|
|
27
27
|
##
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Request
|
4
|
+
class Collection::ContributionProducts < Collection::Base
|
5
|
+
##
|
6
|
+
# The resource path for the first page in the collection
|
7
|
+
|
8
|
+
def resource
|
9
|
+
"/contributionProducts?clientControlled=true"
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# This is the class used to model the data
|
14
|
+
|
15
|
+
def model
|
16
|
+
MyJohnDeereApi::Model::ContributionProduct
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Retrieve an item from JD
|
21
|
+
|
22
|
+
def find(item_id)
|
23
|
+
Individual::ContributionProduct.new(accessor, item_id).object
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,6 +2,7 @@ module MyJohnDeereApi::Request::Collection
|
|
2
2
|
autoload :Base, 'my_john_deere_api/request/collection/base'
|
3
3
|
autoload :Assets, 'my_john_deere_api/request/collection/assets'
|
4
4
|
autoload :AssetLocations, 'my_john_deere_api/request/collection/asset_locations'
|
5
|
+
autoload :ContributionProducts, 'my_john_deere_api/request/collection/contribution_products'
|
5
6
|
autoload :Organizations, 'my_john_deere_api/request/collection/organizations'
|
6
7
|
autoload :Fields, 'my_john_deere_api/request/collection/fields'
|
7
8
|
autoload :Flags, 'my_john_deere_api/request/collection/flags'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Request
|
4
|
+
class Individual::ContributionProduct < Individual::Base
|
5
|
+
##
|
6
|
+
# The resource path for the first page in the collection
|
7
|
+
|
8
|
+
def resource
|
9
|
+
"/contributionProducts/#{id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# This is the class used to model the data
|
14
|
+
|
15
|
+
def model
|
16
|
+
MyJohnDeereApi::Model::ContributionProduct
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module MyJohnDeereApi::Request::Individual
|
2
|
-
autoload :Base,
|
3
|
-
autoload :Asset,
|
2
|
+
autoload :Base, 'my_john_deere_api/request/individual/base'
|
3
|
+
autoload :Asset, 'my_john_deere_api/request/individual/asset'
|
4
|
+
autoload :ContributionProduct, 'my_john_deere_api/request/individual/contribution_product'
|
4
5
|
end
|
@@ -7,7 +7,7 @@ def contains_parameters?(uri)
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def create_authorize
|
10
|
-
VCR.use_cassette('catalog'){ JD::Authorize.new(
|
10
|
+
VCR.use_cassette('catalog'){ JD::Authorize.new(api_key, api_secret, environment: :sandbox) }
|
11
11
|
end
|
12
12
|
|
13
13
|
def fancy_url
|
@@ -17,16 +17,16 @@ end
|
|
17
17
|
describe 'MyJohnDeereApi::Authorize' do
|
18
18
|
describe 'initialization' do
|
19
19
|
it 'sets the api key/secret' do
|
20
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(
|
20
|
+
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(api_key, api_secret) }
|
21
21
|
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
22
|
+
assert_equal api_key, authorize.api_key
|
23
|
+
assert_equal api_secret, authorize.api_secret
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'accepts the environment' do
|
27
27
|
environment = :sandbox
|
28
28
|
|
29
|
-
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(
|
29
|
+
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(api_key, api_secret, environment: environment) }
|
30
30
|
assert_equal environment, authorize.environment
|
31
31
|
end
|
32
32
|
end
|
@@ -46,7 +46,7 @@ describe 'MyJohnDeereApi::Authorize' do
|
|
46
46
|
authorize = create_authorize
|
47
47
|
|
48
48
|
url = VCR.use_cassette('get_request_token') { authorize.authorize_url }
|
49
|
-
links = VCR.use_cassette('catalog') { JD::Consumer.new(
|
49
|
+
links = VCR.use_cassette('catalog') { JD::Consumer.new(api_key, api_secret, environment: :sandbox).send(:links) }
|
50
50
|
|
51
51
|
assert_includes url, "#{links[:authorize_request_token]}"
|
52
52
|
|
@@ -3,17 +3,17 @@ require 'support/helper'
|
|
3
3
|
describe 'MyJohnDeereApi::Client' do
|
4
4
|
describe '#initialize(api_key, api_secret)' do
|
5
5
|
it 'sets the api key/secret' do
|
6
|
-
client = JD::Client.new(
|
6
|
+
client = JD::Client.new(api_key, api_secret)
|
7
7
|
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
8
|
+
assert_equal api_key, client.api_key
|
9
|
+
assert_equal api_secret, client.api_secret
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'accepts access token/secret' do
|
13
13
|
access_token = 'token'
|
14
14
|
access_secret = 'secret'
|
15
15
|
|
16
|
-
client = JD::Client.new(
|
16
|
+
client = JD::Client.new(api_key, api_secret, access: [access_token, access_secret])
|
17
17
|
|
18
18
|
assert_equal access_token, client.access_token
|
19
19
|
assert_equal access_secret, client.access_secret
|
@@ -22,14 +22,13 @@ describe 'MyJohnDeereApi::Client' do
|
|
22
22
|
it 'accepts the environment' do
|
23
23
|
environment = :sandbox
|
24
24
|
|
25
|
-
client = JD::Client.new(
|
25
|
+
client = JD::Client.new(api_key, api_secret, environment: environment)
|
26
26
|
assert_equal environment, client.environment
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe '#get' do
|
31
31
|
it 'returns the response as a Hash' do
|
32
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
33
32
|
VCR.use_cassette('catalog') { client.send(:accessor) }
|
34
33
|
response = VCR.use_cassette('get_organizations') { client.get('/organizations') }
|
35
34
|
|
@@ -40,7 +39,6 @@ describe 'MyJohnDeereApi::Client' do
|
|
40
39
|
end
|
41
40
|
|
42
41
|
it 'prepends the leading slash if needed' do
|
43
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
44
42
|
VCR.use_cassette('catalog') { client.send(:accessor) }
|
45
43
|
response = VCR.use_cassette('get_organizations') { client.get('organizations') }
|
46
44
|
|
@@ -51,7 +49,6 @@ describe 'MyJohnDeereApi::Client' do
|
|
51
49
|
end
|
52
50
|
|
53
51
|
it 'allows symbols for simple resources' do
|
54
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
55
52
|
VCR.use_cassette('catalog') { client.send(:accessor) }
|
56
53
|
response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
|
57
54
|
|
@@ -63,83 +60,50 @@ describe 'MyJohnDeereApi::Client' do
|
|
63
60
|
end
|
64
61
|
|
65
62
|
describe '#post' do
|
66
|
-
let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
|
67
|
-
|
68
|
-
let(:body) do
|
69
|
-
{
|
70
|
-
"@type": "FlagCategory",
|
71
|
-
"categoryTitle": "Mountain Dew",
|
72
|
-
"sourceNode": "7ba95d7a-f798-46d0-9bf9-c39c31bcf984",
|
73
|
-
"links": [
|
74
|
-
{
|
75
|
-
"rel": "contributionDefinition",
|
76
|
-
"uri": "https://sandboxapi.deere.com/platform/contributionDefinitions/#{ENV['CONTRIBUTION_DEFINITION_ID']}"
|
77
|
-
}
|
78
|
-
],
|
79
|
-
"preferred": true
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
63
|
it 'returns the response as a Hash' do
|
84
|
-
VCR.use_cassette('
|
85
|
-
|
86
|
-
|
64
|
+
response = VCR.use_cassette('post_assets') do
|
65
|
+
client.post("/organizations/#{organization_id}/assets", CONFIG.asset_attributes)
|
66
|
+
end
|
87
67
|
|
88
|
-
assert_equal
|
68
|
+
assert_equal '201', response.code
|
69
|
+
assert_equal 'Created', response.message
|
70
|
+
assert_includes response['Location'], "/assets/#{asset_id}"
|
89
71
|
end
|
90
72
|
|
91
73
|
it 'prepends the leading slash if needed' do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
assert_kind_of Hash, response
|
97
|
-
assert_kind_of Integer, response['total']
|
98
|
-
assert response['values'].all?{|value| value['@type'] == 'Organization'}
|
99
|
-
assert response['values'].all?{|value| value.has_key?('links')}
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'allows symbols for simple resources' do
|
103
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
104
|
-
VCR.use_cassette('catalog') { client.send(:accessor) }
|
105
|
-
response = VCR.use_cassette('get_organizations') { client.get(:organizations) }
|
74
|
+
response = VCR.use_cassette('post_assets') do
|
75
|
+
client.post("organizations/#{organization_id}/assets", CONFIG.asset_attributes)
|
76
|
+
end
|
106
77
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
assert response['values'].all?{|value| value.has_key?('links')}
|
78
|
+
assert_equal '201', response.code
|
79
|
+
assert_equal 'Created', response.message
|
80
|
+
assert_includes response['Location'], "/assets/#{asset_id}"
|
111
81
|
end
|
112
82
|
end
|
113
83
|
|
114
84
|
describe '#delete' do
|
115
85
|
it 'sends the request' do
|
116
|
-
|
117
|
-
VCR.use_cassette('catalog') { client.send(:accessor) }
|
118
|
-
response = VCR.use_cassette('delete_asset') { client.delete("/assets/123") }
|
86
|
+
response = VCR.use_cassette('delete_asset') { client.delete("/assets/#{asset_id}") }
|
119
87
|
|
120
|
-
|
88
|
+
assert_equal '204', response.code
|
89
|
+
assert_equal 'No Content', response.message
|
121
90
|
end
|
122
91
|
|
123
92
|
it 'prepends the leading slash if needed' do
|
124
|
-
|
125
|
-
VCR.use_cassette('catalog') { client.send(:accessor) }
|
126
|
-
response = VCR.use_cassette('get_organizations') { client.get('organizations') }
|
93
|
+
response = VCR.use_cassette('delete_asset') { client.delete("assets/#{asset_id}") }
|
127
94
|
|
128
|
-
|
95
|
+
assert_equal '204', response.code
|
96
|
+
assert_equal 'No Content', response.message
|
129
97
|
end
|
130
98
|
end
|
131
99
|
|
132
100
|
describe '#organizations' do
|
133
101
|
it 'returns a collection of organizations for this account' do
|
134
|
-
|
135
|
-
VCR.use_cassette('catalog') { client.send(:accessor) }
|
136
|
-
|
137
|
-
# force full loading of organizations
|
138
|
-
VCR.use_cassette('get_organizations') { client.organizations }
|
102
|
+
organizations = VCR.use_cassette('get_organizations') { client.organizations.all; client.organizations }
|
139
103
|
|
140
|
-
assert_kind_of
|
104
|
+
assert_kind_of JD::Request::Collection::Organizations, organizations
|
141
105
|
|
142
|
-
|
106
|
+
organizations.each do |organization|
|
143
107
|
assert_kind_of JD::Model::Organization, organization
|
144
108
|
end
|
145
109
|
end
|
@@ -149,25 +113,22 @@ describe 'MyJohnDeereApi::Client' do
|
|
149
113
|
it 'receives the api key/secret and environment of the client' do
|
150
114
|
environment = :sandbox
|
151
115
|
|
152
|
-
client = JD::Client.new(
|
116
|
+
client = JD::Client.new(api_key, api_secret, environment: environment)
|
153
117
|
consumer = client.send :consumer
|
154
118
|
|
155
119
|
assert_kind_of JD::Consumer, consumer
|
156
|
-
assert_equal
|
157
|
-
assert_equal
|
120
|
+
assert_equal api_key, consumer.api_key
|
121
|
+
assert_equal api_secret, consumer.api_secret
|
158
122
|
assert_equal environment, consumer.environment
|
159
123
|
end
|
160
124
|
end
|
161
125
|
|
162
126
|
describe '#accessor' do
|
163
127
|
it 'returns an object that can make user-specific requests' do
|
164
|
-
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
165
|
-
accessor = VCR.use_cassette('catalog') { client.send :accessor }
|
166
|
-
|
167
128
|
assert_kind_of OAuth::AccessToken, accessor
|
168
129
|
assert_kind_of OAuth::Consumer, accessor.consumer
|
169
|
-
assert_equal
|
170
|
-
assert_equal
|
130
|
+
assert_equal access_token, accessor.token
|
131
|
+
assert_equal access_secret, accessor.secret
|
171
132
|
end
|
172
133
|
end
|
173
134
|
end
|
@@ -3,15 +3,15 @@ require 'support/helper'
|
|
3
3
|
describe 'JD::Consumer' do
|
4
4
|
describe '#initialize' do
|
5
5
|
it 'requires an api key and secret' do
|
6
|
-
consumer = JD::Consumer.new(
|
6
|
+
consumer = JD::Consumer.new(api_key, api_secret)
|
7
7
|
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
8
|
+
assert_equal api_key, consumer.api_key
|
9
|
+
assert_equal api_secret, consumer.api_secret
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'accepts the environment' do
|
13
13
|
environment = :sandbox
|
14
|
-
consumer = JD::Consumer.new(
|
14
|
+
consumer = JD::Consumer.new(api_key, api_secret, environment: environment)
|
15
15
|
|
16
16
|
assert_equal environment, consumer.environment
|
17
17
|
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
@@ -19,14 +19,14 @@ describe 'JD::Consumer' do
|
|
19
19
|
|
20
20
|
it 'accepts an arbitrary base_url' do
|
21
21
|
base_url = 'https://example.com'
|
22
|
-
consumer = JD::Consumer.new(
|
22
|
+
consumer = JD::Consumer.new(api_key, api_secret, base_url: base_url)
|
23
23
|
|
24
24
|
assert_equal base_url, consumer.base_url
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'uses specified base_url regardless of specified environment' do
|
28
28
|
base_url = 'https://example.com'
|
29
|
-
consumer = JD::Consumer.new(
|
29
|
+
consumer = JD::Consumer.new(api_key, api_secret, base_url: base_url, environment: :sandbox)
|
30
30
|
|
31
31
|
assert_equal base_url, consumer.base_url
|
32
32
|
end
|
@@ -34,24 +34,24 @@ describe 'JD::Consumer' do
|
|
34
34
|
|
35
35
|
describe '#app_get' do
|
36
36
|
it 'creates a working oAuth consumer for non-user-specific GET requests' do
|
37
|
-
consumer = JD::Consumer.new(
|
38
|
-
app_get = VCR.use_cassette('
|
37
|
+
consumer = JD::Consumer.new(api_key, api_secret, environment: :sandbox)
|
38
|
+
app_get = VCR.use_cassette('catalog') { consumer.app_get }
|
39
39
|
|
40
40
|
assert_kind_of OAuth::Consumer, app_get
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
41
|
+
assert_equal api_key, app_get.key
|
42
|
+
assert_equal api_secret, app_get.secret
|
43
43
|
assert_equal JD::Consumer::URLS[:sandbox], app_get.site
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '#user_get' do
|
48
48
|
it 'creates a working oAuth consumer for user-specific GET requests' do
|
49
|
-
consumer = JD::Consumer.new(
|
50
|
-
user_get = VCR.use_cassette('
|
49
|
+
consumer = JD::Consumer.new(api_key, api_secret, environment: :sandbox)
|
50
|
+
user_get = VCR.use_cassette('catalog') { consumer.user_get }
|
51
51
|
|
52
52
|
assert_kind_of OAuth::Consumer, user_get
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
53
|
+
assert_equal api_key, user_get.key
|
54
|
+
assert_equal api_secret, user_get.secret
|
55
55
|
assert_equal "#{JD::Consumer::URLS[:sandbox]}/platform", user_get.site
|
56
56
|
end
|
57
57
|
end
|
@@ -4,29 +4,14 @@ require 'json'
|
|
4
4
|
describe 'MyJohnDeereApi::Model::AssetLocation' do
|
5
5
|
let(:record) do
|
6
6
|
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
"@type"=>"BasicMeasurement",
|
13
|
-
"name"=>"[1 Foot](https://app.realmfive.com/map?device=0x0080CDEF)",
|
14
|
-
"value"=>"82",
|
15
|
-
"unit"=>"cB"
|
16
|
-
}, {
|
17
|
-
"@type"=>"BasicMeasurement",
|
18
|
-
"name"=>"[2 Feet](https://app.realmfive.com/map?device=0x0080CDEF)",
|
19
|
-
"value"=>"31",
|
20
|
-
"unit"=>"cB"
|
21
|
-
}
|
22
|
-
],
|
23
|
-
"links"=>[]
|
7
|
+
'@type' => 'ContributedAssetLocation',
|
8
|
+
'timestamp' => CONFIG.timestamp,
|
9
|
+
'geometry' => CONFIG.geometry.to_json,
|
10
|
+
'measurementData' => CONFIG.measurement_data,
|
11
|
+
'links' => []
|
24
12
|
}
|
25
13
|
end
|
26
14
|
|
27
|
-
let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
|
28
|
-
let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
|
29
|
-
|
30
15
|
describe '#initialize' do
|
31
16
|
def link_for label
|
32
17
|
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
@@ -48,10 +33,10 @@ describe 'MyJohnDeereApi::Model::AssetLocation' do
|
|
48
33
|
end
|
49
34
|
|
50
35
|
it 'accepts an optional accessor' do
|
51
|
-
|
36
|
+
mock_accessor = 'mock-accessor'
|
52
37
|
|
53
|
-
location = JD::Model::AssetLocation.new(record,
|
54
|
-
assert_equal
|
38
|
+
location = JD::Model::AssetLocation.new(record, mock_accessor)
|
39
|
+
assert_equal mock_accessor, location.accessor
|
55
40
|
end
|
56
41
|
end
|
57
42
|
end
|
@@ -11,16 +11,13 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
11
11
|
"id"=>"123456",
|
12
12
|
"lastModifiedDate"=>"2018-01-31T20:36:16.727Z",
|
13
13
|
"links"=>[
|
14
|
-
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets
|
15
|
-
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations
|
16
|
-
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/
|
14
|
+
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}"},
|
15
|
+
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}"},
|
16
|
+
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}/locations"},
|
17
17
|
]
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
-
let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
|
22
|
-
let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
|
23
|
-
|
24
21
|
describe '#initialize' do
|
25
22
|
def link_for label
|
26
23
|
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
@@ -48,10 +45,10 @@ describe 'MyJohnDeereApi::Model::Asset' do
|
|
48
45
|
end
|
49
46
|
|
50
47
|
it 'accepts an optional accessor' do
|
51
|
-
|
48
|
+
mock_accessor = 'mock-accessor'
|
52
49
|
|
53
|
-
asset = JD::Model::Asset.new(record,
|
54
|
-
assert_equal
|
50
|
+
asset = JD::Model::Asset.new(record, mock_accessor)
|
51
|
+
assert_equal mock_accessor, asset.accessor
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
@@ -10,7 +10,6 @@ end
|
|
10
10
|
|
11
11
|
describe 'MyJohnDeereApi::Model::Base' do
|
12
12
|
let(:object) { JD::Model::Base.new(record, accessor) }
|
13
|
-
let(:accessor) { 'accessor' }
|
14
13
|
|
15
14
|
let(:record) do
|
16
15
|
{
|
@@ -18,9 +17,9 @@ describe 'MyJohnDeereApi::Model::Base' do
|
|
18
17
|
'id'=>'123',
|
19
18
|
'somefield'=>'somevalue',
|
20
19
|
"links"=>[
|
21
|
-
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets
|
22
|
-
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations
|
23
|
-
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/
|
20
|
+
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}"},
|
21
|
+
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}"},
|
22
|
+
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}/locations"},
|
24
23
|
]
|
25
24
|
}
|
26
25
|
end
|