my_john_deere_api 2.4.1
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 +7 -0
- data/README.md +813 -0
- data/Rakefile +9 -0
- data/lib/my_john_deere_api.rb +17 -0
- data/lib/my_john_deere_api/authorize.rb +69 -0
- data/lib/my_john_deere_api/client.rb +151 -0
- data/lib/my_john_deere_api/consumer.rb +90 -0
- data/lib/my_john_deere_api/errors.rb +7 -0
- data/lib/my_john_deere_api/errors/invalid_record_error.rb +29 -0
- data/lib/my_john_deere_api/errors/missing_contribution_definition_id_error.rb +12 -0
- data/lib/my_john_deere_api/errors/not_yet_implemented_error.rb +12 -0
- data/lib/my_john_deere_api/errors/type_mismatch_error.rb +12 -0
- data/lib/my_john_deere_api/errors/unsupported_environment_error.rb +18 -0
- data/lib/my_john_deere_api/helpers.rb +6 -0
- data/lib/my_john_deere_api/helpers/case_conversion.rb +37 -0
- data/lib/my_john_deere_api/helpers/environment_helper.rb +25 -0
- data/lib/my_john_deere_api/helpers/uri_helpers.rb +19 -0
- data/lib/my_john_deere_api/helpers/validate_contribution_definition.rb +18 -0
- data/lib/my_john_deere_api/model.rb +10 -0
- data/lib/my_john_deere_api/model/asset.rb +69 -0
- data/lib/my_john_deere_api/model/asset_location.rb +19 -0
- data/lib/my_john_deere_api/model/base.rb +97 -0
- data/lib/my_john_deere_api/model/contribution_definition.rb +15 -0
- data/lib/my_john_deere_api/model/contribution_product.rb +33 -0
- data/lib/my_john_deere_api/model/field.rb +40 -0
- data/lib/my_john_deere_api/model/flag.rb +36 -0
- data/lib/my_john_deere_api/model/organization.rb +43 -0
- data/lib/my_john_deere_api/net_http_retry.rb +2 -0
- data/lib/my_john_deere_api/net_http_retry/decorator.rb +53 -0
- data/lib/my_john_deere_api/net_http_retry/max_retries_exceeded_error.rb +20 -0
- data/lib/my_john_deere_api/request.rb +6 -0
- data/lib/my_john_deere_api/request/collection.rb +10 -0
- data/lib/my_john_deere_api/request/collection/asset_locations.rb +27 -0
- data/lib/my_john_deere_api/request/collection/assets.rb +34 -0
- data/lib/my_john_deere_api/request/collection/base.rb +91 -0
- data/lib/my_john_deere_api/request/collection/contribution_definitions.rb +26 -0
- data/lib/my_john_deere_api/request/collection/contribution_products.rb +26 -0
- data/lib/my_john_deere_api/request/collection/fields.rb +26 -0
- data/lib/my_john_deere_api/request/collection/flags.rb +33 -0
- data/lib/my_john_deere_api/request/collection/organizations.rb +26 -0
- data/lib/my_john_deere_api/request/create.rb +5 -0
- data/lib/my_john_deere_api/request/create/asset.rb +57 -0
- data/lib/my_john_deere_api/request/create/asset_location.rb +110 -0
- data/lib/my_john_deere_api/request/create/base.rb +67 -0
- data/lib/my_john_deere_api/request/individual.rb +8 -0
- data/lib/my_john_deere_api/request/individual/asset.rb +19 -0
- data/lib/my_john_deere_api/request/individual/base.rb +52 -0
- data/lib/my_john_deere_api/request/individual/contribution_definition.rb +19 -0
- data/lib/my_john_deere_api/request/individual/contribution_product.rb +19 -0
- data/lib/my_john_deere_api/request/individual/field.rb +19 -0
- data/lib/my_john_deere_api/request/individual/organization.rb +19 -0
- data/lib/my_john_deere_api/request/update.rb +4 -0
- data/lib/my_john_deere_api/request/update/asset.rb +40 -0
- data/lib/my_john_deere_api/request/update/base.rb +67 -0
- data/lib/my_john_deere_api/validators.rb +5 -0
- data/lib/my_john_deere_api/validators/asset.rb +35 -0
- data/lib/my_john_deere_api/validators/asset_location.rb +34 -0
- data/lib/my_john_deere_api/validators/base.rb +67 -0
- data/lib/my_john_deere_api/version.rb +3 -0
- data/test/lib/my_john_deere_api/authorize_test.rb +81 -0
- data/test/lib/my_john_deere_api/client_test.rb +225 -0
- data/test/lib/my_john_deere_api/consumer_test.rb +58 -0
- data/test/lib/my_john_deere_api/errors/invalid_record_error_test.rb +26 -0
- data/test/lib/my_john_deere_api/errors/max_retries_exceeded_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/missing_contribution_definition_id_error_test.rb +14 -0
- data/test/lib/my_john_deere_api/errors/not_yet_implemented_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/type_mismatch_error_test.rb +13 -0
- data/test/lib/my_john_deere_api/errors/unsupported_environment_error_test.rb +18 -0
- data/test/lib/my_john_deere_api/errors_test.rb +25 -0
- data/test/lib/my_john_deere_api/helpers/case_conversion_test.rb +100 -0
- data/test/lib/my_john_deere_api/helpers/environment_helper_test.rb +67 -0
- data/test/lib/my_john_deere_api/helpers/uri_helpers_test.rb +58 -0
- data/test/lib/my_john_deere_api/helpers/validate_contribution_definition_test.rb +74 -0
- data/test/lib/my_john_deere_api/helpers_test.rb +21 -0
- data/test/lib/my_john_deere_api/model/asset_location_test.rb +38 -0
- data/test/lib/my_john_deere_api/model/asset_test.rb +133 -0
- data/test/lib/my_john_deere_api/model/base_test.rb +76 -0
- data/test/lib/my_john_deere_api/model/contribution_definition_test.rb +52 -0
- data/test/lib/my_john_deere_api/model/contribution_product_test.rb +82 -0
- data/test/lib/my_john_deere_api/model/field_test.rb +65 -0
- data/test/lib/my_john_deere_api/model/flag_test.rb +48 -0
- data/test/lib/my_john_deere_api/model/organization_test.rb +84 -0
- data/test/lib/my_john_deere_api/model_test.rb +37 -0
- data/test/lib/my_john_deere_api/net_http_retry/decorator_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/collection/asset_locations_test.rb +102 -0
- data/test/lib/my_john_deere_api/request/collection/assets_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/collection/base_test.rb +27 -0
- data/test/lib/my_john_deere_api/request/collection/contribution_definitions_test.rb +88 -0
- 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 +86 -0
- data/test/lib/my_john_deere_api/request/collection/flags_test.rb +92 -0
- data/test/lib/my_john_deere_api/request/collection/organizations_test.rb +87 -0
- data/test/lib/my_john_deere_api/request/collection_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/create/asset_location_test.rb +163 -0
- data/test/lib/my_john_deere_api/request/create/asset_test.rb +182 -0
- data/test/lib/my_john_deere_api/request/create/base_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/create_test.rb +17 -0
- data/test/lib/my_john_deere_api/request/individual/asset_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/base_test.rb +18 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_definition_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/contribution_product_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual/field_test.rb +37 -0
- data/test/lib/my_john_deere_api/request/individual/organization_test.rb +33 -0
- data/test/lib/my_john_deere_api/request/individual_test.rb +29 -0
- data/test/lib/my_john_deere_api/request/update/asset_test.rb +99 -0
- data/test/lib/my_john_deere_api/request/update/base_test.rb +60 -0
- data/test/lib/my_john_deere_api/request/update_test.rb +13 -0
- data/test/lib/my_john_deere_api/request_test.rb +21 -0
- data/test/lib/my_john_deere_api/validators/asset_location_test.rb +61 -0
- data/test/lib/my_john_deere_api/validators/asset_test.rb +93 -0
- data/test/lib/my_john_deere_api/validators/base_test.rb +92 -0
- data/test/lib/my_john_deere_api/validators_test.rb +17 -0
- data/test/lib/my_john_deere_api/version_test.rb +9 -0
- data/test/my_john_deere_api_test.rb +37 -0
- data/test/support/helper.rb +97 -0
- data/test/support/vcr/accessor/delete_failed.yml +327 -0
- data/test/support/vcr/accessor/delete_max_failed.yml +615 -0
- data/test/support/vcr/accessor/delete_retry.yml +191 -0
- data/test/support/vcr/accessor/delete_retry_too_soon.yml +191 -0
- data/test/support/vcr/accessor/get_failed.yml +390 -0
- data/test/support/vcr/accessor/get_max_failed.yml +734 -0
- data/test/support/vcr/accessor/get_retry.yml +226 -0
- data/test/support/vcr/accessor/get_retry_too_soon.yml +226 -0
- data/test/support/vcr/accessor/post_failed.yml +417 -0
- data/test/support/vcr/accessor/post_max_failed.yml +785 -0
- data/test/support/vcr/accessor/post_retry.yml +241 -0
- data/test/support/vcr/accessor/post_retry_too_soon.yml +241 -0
- data/test/support/vcr/accessor/put_failed.yml +372 -0
- data/test/support/vcr/accessor/put_max_failed.yml +700 -0
- data/test/support/vcr/accessor/put_retry.yml +216 -0
- data/test/support/vcr/accessor/put_retry_too_soon.yml +216 -0
- data/test/support/vcr/catalog.yml +89 -0
- data/test/support/vcr/delete_asset.yml +82 -0
- data/test/support/vcr/get_access_token.yml +41 -0
- data/test/support/vcr/get_asset.yml +144 -0
- data/test/support/vcr/get_asset_locations.yml +196 -0
- data/test/support/vcr/get_assets.yml +152 -0
- data/test/support/vcr/get_contribution_definition.yml +90 -0
- data/test/support/vcr/get_contribution_definitions.yml +91 -0
- 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_field.yml +144 -0
- data/test/support/vcr/get_fields.yml +146 -0
- data/test/support/vcr/get_flags.yml +47 -0
- data/test/support/vcr/get_organization.yml +90 -0
- data/test/support/vcr/get_organizations.yml +149 -0
- data/test/support/vcr/get_request_token.yml +83 -0
- data/test/support/vcr/post_asset_locations.yml +244 -0
- data/test/support/vcr/post_assets.yml +192 -0
- data/test/support/vcr/put_asset.yml +87 -0
- data/test/support/vcr/warning.txt +28 -0
- data/test/support/vcr_setup.rb +488 -0
- metadata +277 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Helpers' do
|
4
|
+
describe 'loading dependencies' do
|
5
|
+
it 'loads Helpers::UriHelpers' do
|
6
|
+
assert JD::Helpers::UriHelpers
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads Helpers::CaseConversion' do
|
10
|
+
assert JD::Helpers::CaseConversion
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'loads Helpers::EnvironmentHelper' do
|
14
|
+
assert JD::Helpers::EnvironmentHelper
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'loads Helpers::ValidateContributionDefinition' do
|
18
|
+
assert JD::Helpers::ValidateContributionDefinition
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe 'MyJohnDeereApi::Model::AssetLocation' do
|
5
|
+
let(:klass) { JD::Model::AssetLocation }
|
6
|
+
|
7
|
+
let(:record) do
|
8
|
+
{
|
9
|
+
'@type' => 'ContributedAssetLocation',
|
10
|
+
'timestamp' => CONFIG.timestamp,
|
11
|
+
'geometry' => CONFIG.geometry.to_json,
|
12
|
+
'measurementData' => CONFIG.measurement_data,
|
13
|
+
'links' => []
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#initialize' do
|
18
|
+
def link_for label
|
19
|
+
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'sets the attributes from the given record' do
|
23
|
+
location = klass.new(client, record)
|
24
|
+
|
25
|
+
assert_equal client, location.client
|
26
|
+
assert_equal accessor, location.accessor
|
27
|
+
|
28
|
+
# basic attributes
|
29
|
+
assert_equal record['timestamp'], location.timestamp
|
30
|
+
assert_equal JSON.parse(record['geometry']), location.geometry
|
31
|
+
assert_equal record['measurementData'], location.measurement_data
|
32
|
+
|
33
|
+
# links to other things
|
34
|
+
assert_kind_of Hash, location.links
|
35
|
+
assert_equal 0, location.links.size
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Model::Asset' do
|
4
|
+
let(:klass) { JD::Model::Asset }
|
5
|
+
|
6
|
+
let(:record) do
|
7
|
+
{
|
8
|
+
"@type"=>"ContributedAsset",
|
9
|
+
"title"=>"Happy Device",
|
10
|
+
"assetCategory"=>"DEVICE",
|
11
|
+
"assetType"=>"SENSOR",
|
12
|
+
"assetSubType"=>"OTHER",
|
13
|
+
"id"=>asset_id,
|
14
|
+
"lastModifiedDate"=>"2018-01-31T20:36:16.727Z",
|
15
|
+
"links"=>[
|
16
|
+
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}"},
|
17
|
+
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}"},
|
18
|
+
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}/locations"},
|
19
|
+
]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#initialize' do
|
24
|
+
def link_for label
|
25
|
+
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the attributes from the given record' do
|
29
|
+
asset = klass.new(client, record)
|
30
|
+
|
31
|
+
assert_equal client, asset.client
|
32
|
+
assert_equal accessor, asset.accessor
|
33
|
+
|
34
|
+
# basic attributes
|
35
|
+
assert_equal record['id'], asset.id
|
36
|
+
assert_equal record['title'], asset.title
|
37
|
+
assert_equal record['assetCategory'], asset.asset_category
|
38
|
+
assert_equal record['assetType'], asset.asset_type
|
39
|
+
assert_equal record['assetSubType'], asset.asset_sub_type
|
40
|
+
assert_equal record['lastModifiedDate'], asset.last_modified_date
|
41
|
+
|
42
|
+
# links to other things
|
43
|
+
assert_kind_of Hash, asset.links
|
44
|
+
|
45
|
+
['self', 'organization', 'locations'].each do |association|
|
46
|
+
assert_equal link_for(association), asset.links[association]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#attributes' do
|
52
|
+
it 'converts properties back to an attributes hash' do
|
53
|
+
asset = klass.new(client, record)
|
54
|
+
attributes = asset.attributes
|
55
|
+
|
56
|
+
assert_equal asset.id, attributes[:id]
|
57
|
+
assert_equal asset.title, attributes[:title]
|
58
|
+
assert_equal asset.asset_category, attributes[:asset_category]
|
59
|
+
assert_equal asset.asset_type, attributes[:asset_type]
|
60
|
+
assert_equal asset.asset_sub_type, attributes[:asset_sub_type]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#save' do
|
65
|
+
it 'sends any recent updates to John Deere' do
|
66
|
+
asset = klass.new(client, record)
|
67
|
+
new_title = 'i REALLY like turtles!'
|
68
|
+
|
69
|
+
asset.title = new_title
|
70
|
+
assert_equal new_title, asset.title
|
71
|
+
|
72
|
+
response = VCR.use_cassette('put_asset') { asset.save }
|
73
|
+
assert_kind_of Net::HTTPNoContent, response
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does not make a JD request if nothing has changed' do
|
77
|
+
asset = klass.new(client, record)
|
78
|
+
response = asset.save
|
79
|
+
|
80
|
+
assert_nil response
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'marks the record as saved' do
|
84
|
+
asset = klass.new(client, record)
|
85
|
+
asset.title = 'i REALLY like turtles!'
|
86
|
+
|
87
|
+
response = VCR.use_cassette('put_asset') { asset.save }
|
88
|
+
assert_kind_of Net::HTTPNoContent, response
|
89
|
+
|
90
|
+
response = asset.save
|
91
|
+
assert_nil response
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#update' do
|
96
|
+
it 'updates the attributes' do
|
97
|
+
asset = klass.new(client, record)
|
98
|
+
|
99
|
+
new_title = 'i REALLY like turtles!'
|
100
|
+
VCR.use_cassette('put_asset') { asset.update(title: new_title) }
|
101
|
+
|
102
|
+
assert_equal new_title, asset.title
|
103
|
+
assert_equal new_title, asset.attributes[:title]
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'sends the update to John Deere' do
|
107
|
+
asset = klass.new(client, record)
|
108
|
+
|
109
|
+
new_title = 'i REALLY like turtles!'
|
110
|
+
response = VCR.use_cassette('put_asset') { asset.update(title: new_title) }
|
111
|
+
|
112
|
+
assert_kind_of Net::HTTPNoContent, response
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#locations' do
|
117
|
+
it 'returns a collection of locations for this asset' do
|
118
|
+
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|
119
|
+
asset = VCR.use_cassette('get_assets') { organization.assets.first }
|
120
|
+
|
121
|
+
locations = VCR.use_cassette('get_asset_locations') do
|
122
|
+
asset.locations.all
|
123
|
+
asset.locations
|
124
|
+
end
|
125
|
+
|
126
|
+
assert_kind_of Array, locations.all
|
127
|
+
|
128
|
+
locations.each do |location|
|
129
|
+
assert_kind_of JD::Model::AssetLocation, location
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
class SampleModel < JD::Model::Base
|
4
|
+
attr_reader :somefield
|
5
|
+
|
6
|
+
def map_attributes(record)
|
7
|
+
@somefield = record['somefield']
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'MyJohnDeereApi::Model::Base' do
|
12
|
+
let(:klass) { JD::Model::Base }
|
13
|
+
let(:object) { klass.new(client, record) }
|
14
|
+
|
15
|
+
let(:record) do
|
16
|
+
{
|
17
|
+
'@type'=>'Base',
|
18
|
+
'id'=>'123',
|
19
|
+
'somefield'=>'somevalue',
|
20
|
+
"links"=>[
|
21
|
+
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}"},
|
22
|
+
{"@type"=>"Link", "rel"=>"organization", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}"},
|
23
|
+
{"@type"=>"Link", "rel"=>"locations", "uri"=>"https://sandboxapi.deere.com/platform/assets/#{asset_id}/locations"},
|
24
|
+
]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'includes UriHelpers' do
|
29
|
+
assert_includes object.private_methods, :uri_path
|
30
|
+
assert_includes object.private_methods, :id_from_uri
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#initialize(client, record)' do
|
34
|
+
def link_for label
|
35
|
+
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when the wrong record type is passed' do
|
39
|
+
let(:record) do
|
40
|
+
{
|
41
|
+
'@type'=>'WrongType',
|
42
|
+
'links'=>[]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'raises a TypeMismatch error' do
|
47
|
+
exception = assert_raises(JD::TypeMismatchError) { object }
|
48
|
+
assert_equal "Expected record of type 'Base', but received type 'WrongType'", exception.message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sets the base attributes' do
|
53
|
+
assert_equal client, object.client
|
54
|
+
assert_equal accessor, object.accessor
|
55
|
+
|
56
|
+
assert_equal record['id'], object.id
|
57
|
+
assert_equal record['@type'], object.record_type
|
58
|
+
assert_equal client, object.client
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'sets the links' do
|
62
|
+
links = object.links
|
63
|
+
|
64
|
+
assert_kind_of Hash, links
|
65
|
+
|
66
|
+
['self', 'organization', 'locations'].each do |link|
|
67
|
+
assert_equal link_for(link), links[link]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'maps additional fields in subclasses' do
|
72
|
+
object = SampleModel.new(client, record)
|
73
|
+
assert_equal 'somevalue', object.somefield
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Model::ContributionDefinition' do
|
4
|
+
let(:klass) { JD::Model::ContributionDefinition }
|
5
|
+
|
6
|
+
let(:record) do
|
7
|
+
{
|
8
|
+
"@type" => "ContributionDefinition",
|
9
|
+
"name" => "Definition Name",
|
10
|
+
"actionDefinitions" => [],
|
11
|
+
"id" => "00000000-0000-0000-0000-000000000000",
|
12
|
+
"links" => [
|
13
|
+
{
|
14
|
+
"@type" => "Link",
|
15
|
+
"rel" => "self",
|
16
|
+
"uri" => "https://sandboxapi.deere.com/platform/contributionDefinitions/00000000-0000-0000-0000-000000000000"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"@type" => "Link",
|
20
|
+
"rel" => "contributionProduct",
|
21
|
+
"uri" => "https://sandboxapi.deere.com/platform/contributionProducts/00000000-0000-0000-0000-000000000000"
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#initialize' do
|
28
|
+
def link_for label
|
29
|
+
camel_label = label.gsub(/_(.)/){|m| m[1].upcase}
|
30
|
+
record['links'].detect{|link| link['rel'] == camel_label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sets the attributes from the given record' do
|
34
|
+
definition = klass.new(client, record)
|
35
|
+
|
36
|
+
assert_equal client, definition.client
|
37
|
+
assert_equal accessor, definition.accessor
|
38
|
+
|
39
|
+
# basic attributes
|
40
|
+
assert_equal record['id'], definition.id
|
41
|
+
assert_equal record['name'], definition.name
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'links to other things' do
|
45
|
+
product = klass.new(client, record)
|
46
|
+
|
47
|
+
['self', 'contribution_product'].each do |association|
|
48
|
+
assert_equal link_for(association), product.links[association]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Model::ContributionProduct' do
|
4
|
+
let(:klass) { JD::Model::ContributionProduct }
|
5
|
+
|
6
|
+
let(:record) do
|
7
|
+
{
|
8
|
+
"@type" => "ContributionProduct",
|
9
|
+
"marketPlaceName" => "SpiffyApp",
|
10
|
+
"marketPlaceDescription" => "SpiffyApp",
|
11
|
+
"marketPlaceLogo" => "https://example.com/logo.png",
|
12
|
+
"defaultLocale" => "en-us",
|
13
|
+
"currentStatus" => "APPROVED",
|
14
|
+
"activationCallback" => "https://example.com/activation_callback",
|
15
|
+
"previewImages" => ["https://example.com/preview.png"],
|
16
|
+
"supportedRegions" => ["US"],
|
17
|
+
"supportedOperationCenters" => ["something"],
|
18
|
+
"id" => "#{contribution_product_id}",
|
19
|
+
"links" => [
|
20
|
+
{
|
21
|
+
"@type" => "Link",
|
22
|
+
"rel" => "self",
|
23
|
+
"uri" => "https://sandboxapi.deere.com/platform/contributionProducts/#{contribution_product_id}"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"@type" => "Link",
|
27
|
+
"rel" => "contributionDefinition",
|
28
|
+
"uri" => "https://sandboxapi.deere.com/platform/contributionProducts/#{contribution_product_id}/contributionDefinitions"
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#initialize' do
|
35
|
+
def link_for label
|
36
|
+
camel_label = label.gsub(/_(.)/){|m| m[1].upcase}
|
37
|
+
record['links'].detect{|link| link['rel'] == camel_label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets the attributes from the given record' do
|
41
|
+
product = klass.new(client, record)
|
42
|
+
|
43
|
+
assert_equal client, product.client
|
44
|
+
assert_equal accessor, product.accessor
|
45
|
+
|
46
|
+
# basic attributes
|
47
|
+
assert_equal record['id'], product.id
|
48
|
+
assert_equal record['marketPlaceName'], product.market_place_name
|
49
|
+
assert_equal record['marketPlaceDescription'], product.market_place_description
|
50
|
+
assert_equal record['defaultLocale'], product.default_locale
|
51
|
+
assert_equal record['currentStatus'], product.current_status
|
52
|
+
assert_equal record['activationCallback'], product.activation_callback
|
53
|
+
assert_equal record['previewImages'], product.preview_images
|
54
|
+
assert_equal record['supportedRegions'], product.supported_regions
|
55
|
+
assert_equal record['supportedOperationCenters'], product.supported_operation_centers
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'links to other things' do
|
59
|
+
product = klass.new(client, record)
|
60
|
+
|
61
|
+
['self', 'contribution_definition'].each do |association|
|
62
|
+
assert_equal link_for(association), product.links[association]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#contribution_definitions' do
|
68
|
+
it 'returns a collection of contribution definitions for this contributon product' do
|
69
|
+
product = klass.new(client, record)
|
70
|
+
|
71
|
+
contribution_definitions = VCR.use_cassette('get_contribution_definitions') do
|
72
|
+
product.contribution_definitions.all; product.contribution_definitions
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_kind_of JD::Request::Collection::ContributionDefinitions, contribution_definitions
|
76
|
+
|
77
|
+
contribution_definitions.each do |contribution_definition|
|
78
|
+
assert_kind_of JD::Model::ContributionDefinition, contribution_definition
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Model::Field' do
|
4
|
+
let(:klass) { JD::Model::Field }
|
5
|
+
|
6
|
+
let(:record) do
|
7
|
+
{
|
8
|
+
"@type"=>"Field",
|
9
|
+
"name"=>"Happy Field",
|
10
|
+
"archived"=>false,
|
11
|
+
"id"=>"123456",
|
12
|
+
"links"=>[
|
13
|
+
{"@type"=>"Link", "rel"=>"self", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}/fields/#{field_id}"},
|
14
|
+
{"@type"=>"Link", "rel"=>"clients", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}/fields/#{field_id}/clients"},
|
15
|
+
{"@type"=>"Link", "rel"=>"notes", "uri"=>"https://sandboxapi.deere.com/platform/organizations/#{organization_id}/fields/#{field_id}/notes"},
|
16
|
+
]
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#initialize' do
|
21
|
+
def link_for label
|
22
|
+
record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the attributes from the given record' do
|
26
|
+
field = klass.new(client, record)
|
27
|
+
|
28
|
+
assert_equal client, field.client
|
29
|
+
assert_equal accessor, field.accessor
|
30
|
+
|
31
|
+
# basic attributes
|
32
|
+
assert_equal record['name'], field.name
|
33
|
+
assert_equal record['archived'], field.archived?
|
34
|
+
assert_equal record['id'], field.id
|
35
|
+
|
36
|
+
# links to other things
|
37
|
+
assert_kind_of Hash, field.links
|
38
|
+
|
39
|
+
['clients', 'notes'].each do |association|
|
40
|
+
assert_equal link_for(association), field.links[association]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#flags' do
|
46
|
+
it 'returns a collection of flags for this organization' do
|
47
|
+
organization = VCR.use_cassette('get_organizations') { client.organizations.first }
|
48
|
+
field = VCR.use_cassette('get_fields') { organization.fields.first }
|
49
|
+
flags = VCR.use_cassette('get_flags') { field.flags.all }
|
50
|
+
|
51
|
+
assert_kind_of Array, flags
|
52
|
+
|
53
|
+
flags.each do |flag|
|
54
|
+
assert_kind_of JD::Model::Flag, flag
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'private #organization_id' do
|
60
|
+
it "infers the organization_id from links" do
|
61
|
+
field = klass.new(client, record)
|
62
|
+
assert_equal organization_id, field.send(:organization_id)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|