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,37 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Helpers::CaseConversion
|
4
|
+
private
|
5
|
+
|
6
|
+
##
|
7
|
+
# convert a text or camelcase string to underscore
|
8
|
+
|
9
|
+
def underscore(something)
|
10
|
+
something = something.to_s if something.is_a?(Symbol)
|
11
|
+
|
12
|
+
if something.is_a?(String)
|
13
|
+
something.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/\s+/, '_').gsub(/_+/, '_').downcase
|
14
|
+
elsif something.is_a?(Hash)
|
15
|
+
something.transform_keys{ |key| underscore(key) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# convert text or underscored string to camelcase
|
21
|
+
|
22
|
+
def camelize(something)
|
23
|
+
something = something.to_s if something.is_a?(Symbol)
|
24
|
+
|
25
|
+
if something.is_a?(String)
|
26
|
+
list = something.strip.split(/[_\s]+/)
|
27
|
+
|
28
|
+
# preserve case of the first element
|
29
|
+
new_list = [list.shift]
|
30
|
+
new_list += list.map(&:capitalize)
|
31
|
+
|
32
|
+
new_list.join('')
|
33
|
+
elsif something.is_a?(Hash)
|
34
|
+
something.transform_keys{ |key| camelize(key) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
module Helpers::EnvironmentHelper
|
5
|
+
attr_reader :environment
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
##
|
10
|
+
# Intelligently set the environment
|
11
|
+
|
12
|
+
def environment=(value)
|
13
|
+
value = (value || :live).to_sym
|
14
|
+
|
15
|
+
@environment = case value
|
16
|
+
when :sandbox, :live
|
17
|
+
value
|
18
|
+
when :production
|
19
|
+
:live
|
20
|
+
else
|
21
|
+
raise UnsupportedEnvironmentError, value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi::Helpers::UriHelpers
|
4
|
+
private
|
5
|
+
|
6
|
+
##
|
7
|
+
# extract just the path from the uri, excluding the platform prefix
|
8
|
+
def uri_path(uri)
|
9
|
+
URI.parse(uri).path.gsub(/^\/platform/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# infer id from uri
|
14
|
+
|
15
|
+
def id_from_uri(uri, label)
|
16
|
+
parts = uri.split('/')
|
17
|
+
parts[parts.index(label.to_s) + 1]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
module Helpers::ValidateContributionDefinition
|
5
|
+
private
|
6
|
+
|
7
|
+
##
|
8
|
+
# Raise an error if contribution_definition_id is missing
|
9
|
+
|
10
|
+
def validate_contribution_definition
|
11
|
+
if client.contribution_definition_id.nil?
|
12
|
+
raise MissingContributionDefinitionIdError
|
13
|
+
end
|
14
|
+
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module MyJohnDeereApi::Model
|
2
|
+
autoload :Base, 'my_john_deere_api/model/base'
|
3
|
+
autoload :Asset, 'my_john_deere_api/model/asset'
|
4
|
+
autoload :AssetLocation, 'my_john_deere_api/model/asset_location'
|
5
|
+
autoload :ContributionProduct, 'my_john_deere_api/model/contribution_product'
|
6
|
+
autoload :ContributionDefinition, 'my_john_deere_api/model/contribution_definition'
|
7
|
+
autoload :Organization, 'my_john_deere_api/model/organization'
|
8
|
+
autoload :Field, 'my_john_deere_api/model/field'
|
9
|
+
autoload :Flag, 'my_john_deere_api/model/flag'
|
10
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Model::Asset < Model::Base
|
3
|
+
include Helpers::CaseConversion
|
4
|
+
|
5
|
+
attr_reader :title, :asset_category, :asset_type, :asset_sub_type, :last_modified_date
|
6
|
+
|
7
|
+
##
|
8
|
+
# A listing of attributes that can be passed back to John Deere
|
9
|
+
|
10
|
+
def attributes
|
11
|
+
{
|
12
|
+
id: id,
|
13
|
+
title: title,
|
14
|
+
asset_category: asset_category,
|
15
|
+
asset_type: asset_type,
|
16
|
+
asset_sub_type: asset_sub_type,
|
17
|
+
organization_id: 'placeholder'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Change the title, locally
|
23
|
+
|
24
|
+
def title=(value)
|
25
|
+
mark_as_unsaved
|
26
|
+
@title = value
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Save any attribute changes to John Deere
|
31
|
+
|
32
|
+
def save
|
33
|
+
if unsaved?
|
34
|
+
mark_as_saved
|
35
|
+
Request::Update::Asset.new(client, self, attributes).request
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Update the attributes in John Deere
|
41
|
+
|
42
|
+
def update new_attributes
|
43
|
+
map_attributes(camelize(new_attributes))
|
44
|
+
Request::Update::Asset.new(client, self, attributes).request
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# locations associated with this asset
|
49
|
+
|
50
|
+
def locations
|
51
|
+
return @locations if defined?(@locations)
|
52
|
+
@locations = Request::Collection::AssetLocations.new(client, asset: id)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def map_attributes(record)
|
58
|
+
@title = record['title'] if record['title']
|
59
|
+
@asset_category = record['assetCategory'] if record['assetCategory']
|
60
|
+
@asset_type = record['assetType'] if record['assetType']
|
61
|
+
@asset_sub_type = record['assetSubType'] if record['assetSubType']
|
62
|
+
@last_modified_date = record['lastModifiedDate'] if record['lastModifiedDate']
|
63
|
+
end
|
64
|
+
|
65
|
+
def expected_record_type
|
66
|
+
'ContributedAsset'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
class Model::AssetLocation < Model::Base
|
5
|
+
attr_reader :timestamp, :geometry, :measurement_data
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def map_attributes(record)
|
10
|
+
@timestamp = record['timestamp']
|
11
|
+
@geometry = JSON.parse(record['geometry'])
|
12
|
+
@measurement_data = record['measurementData']
|
13
|
+
end
|
14
|
+
|
15
|
+
def expected_record_type
|
16
|
+
'ContributedAssetLocation'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Model::Base
|
3
|
+
include Helpers::CaseConversion
|
4
|
+
include Helpers::UriHelpers
|
5
|
+
|
6
|
+
attr_reader :id, :record_type, :client, :links
|
7
|
+
|
8
|
+
##
|
9
|
+
# arguments:
|
10
|
+
#
|
11
|
+
# [client] the client, because it contains all the config info.
|
12
|
+
# The alternative would be a true Config block, but then
|
13
|
+
# settings would be app-wide. This allows one app to have
|
14
|
+
# multiple clients with different settings.
|
15
|
+
#
|
16
|
+
# [record] a JSON object of type 'Field', returned from the API.
|
17
|
+
|
18
|
+
def initialize(client, record)
|
19
|
+
verify_record_type(record['@type'])
|
20
|
+
|
21
|
+
@id = record['id']
|
22
|
+
@record_type = record['@type']
|
23
|
+
@client = client
|
24
|
+
@unsaved = false
|
25
|
+
|
26
|
+
map_attributes(record)
|
27
|
+
|
28
|
+
@links = {}
|
29
|
+
|
30
|
+
record['links'].each do |association|
|
31
|
+
@links[underscore(association['rel'])] = uri_path(association['uri'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# The client accessor
|
37
|
+
|
38
|
+
def accessor
|
39
|
+
return @accessor if defined?(@accessor)
|
40
|
+
@accessor = client&.accessor
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
##
|
46
|
+
# This method receives the full record hash and extracts whatever extra
|
47
|
+
# attributes are needed for the given base class. This is intended to
|
48
|
+
# be overridden by child classes instead of monkeypatching #initialize.
|
49
|
+
|
50
|
+
def map_attributes(record)
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Expected record type. Override in child classes.
|
56
|
+
|
57
|
+
def expected_record_type
|
58
|
+
'Base'
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Raise an error if this is not the type of record we expect to receive
|
63
|
+
|
64
|
+
def verify_record_type(type)
|
65
|
+
unless type == expected_record_type
|
66
|
+
raise TypeMismatchError, "Expected record of type '#{expected_record_type}', but received type '#{type}'"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Mark as unsaved, so we know to save it later
|
72
|
+
|
73
|
+
def mark_as_unsaved
|
74
|
+
@unsaved = true
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Mark as saved, so we don't try to save it later
|
79
|
+
|
80
|
+
def mark_as_saved
|
81
|
+
@unsaved = false
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Are changes to this model synced with JD?
|
86
|
+
def saved?
|
87
|
+
!@unsaved
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Are there pending changes to send to JD?
|
92
|
+
|
93
|
+
def unsaved?
|
94
|
+
@unsaved
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
|
8
|
+
##
|
9
|
+
# contribution definitions associated with this contribution product
|
10
|
+
|
11
|
+
def contribution_definitions
|
12
|
+
return @contribution_definitions if defined?(@contribution_definitions)
|
13
|
+
@contribution_definitions = Request::Collection::ContributionDefinitions.new(client, contribution_product: id)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def map_attributes(record)
|
19
|
+
@market_place_name = record['marketPlaceName']
|
20
|
+
@market_place_description = record['marketPlaceDescription']
|
21
|
+
@default_locale = record['defaultLocale']
|
22
|
+
@current_status = record['currentStatus']
|
23
|
+
@activation_callback = record['activationCallback']
|
24
|
+
@preview_images = record['previewImages']
|
25
|
+
@supported_regions = record['supportedRegions']
|
26
|
+
@supported_operation_centers = record['supportedOperationCenters']
|
27
|
+
end
|
28
|
+
|
29
|
+
def expected_record_type
|
30
|
+
'ContributionProduct'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MyJohnDeereApi
|
2
|
+
class Model::Field < Model::Base
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
##
|
6
|
+
# Since the archived attribute is boolean, we reflect this in the
|
7
|
+
# method name instead of using a standard attr_reader.
|
8
|
+
|
9
|
+
def archived?
|
10
|
+
@archived
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# flags associated with this organization
|
15
|
+
|
16
|
+
def flags
|
17
|
+
return @flags if defined?(@flags)
|
18
|
+
@flags = Request::Collection::Flags.new(client, organization: organization_id, field: id)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def map_attributes(record)
|
24
|
+
@name = record['name']
|
25
|
+
@archived = record['archived']
|
26
|
+
end
|
27
|
+
|
28
|
+
def expected_record_type
|
29
|
+
'Field'
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Infer the organization_id from the 'self' link
|
34
|
+
|
35
|
+
def organization_id
|
36
|
+
return @organization_id if defined?(@organization_id)
|
37
|
+
@organization_id = id_from_uri(links['self'], :organizations)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
class Model::Flag < Model::Base
|
5
|
+
attr_reader :notes, :geometry
|
6
|
+
|
7
|
+
##
|
8
|
+
# Since the archived attribute is boolean, we reflect this in the
|
9
|
+
# method name instead of using a standard attr_reader.
|
10
|
+
|
11
|
+
def archived?
|
12
|
+
@archived
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Since the proximity_alert_enabled attribute is boolean, we reflect this
|
17
|
+
# in the method name instead of using a standard attr_reader.
|
18
|
+
|
19
|
+
def proximity_alert_enabled?
|
20
|
+
@proximity_alert_enabled
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def map_attributes(record)
|
26
|
+
@notes = record['notes']
|
27
|
+
@geometry =JSON.parse(record['geometry'])
|
28
|
+
@proximity_alert_enabled = record['proximityAlertEnabled']
|
29
|
+
@archived = record['archived']
|
30
|
+
end
|
31
|
+
|
32
|
+
def expected_record_type
|
33
|
+
'Flag'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module MyJohnDeereApi
|
4
|
+
class Model::Organization < Model::Base
|
5
|
+
attr_reader :name, :type
|
6
|
+
|
7
|
+
##
|
8
|
+
# Since the member attribute is boolean, we reflect this in the
|
9
|
+
# method name instead of using a standard attr_reader.
|
10
|
+
|
11
|
+
def member?
|
12
|
+
@member
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# fields associated with this organization
|
17
|
+
|
18
|
+
def fields
|
19
|
+
return @fields if defined?(@fields)
|
20
|
+
@fields = MyJohnDeereApi::Request::Collection::Fields.new(client, organization: id)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# assets associated with this organization
|
25
|
+
|
26
|
+
def assets
|
27
|
+
return @assets if defined?(@assets)
|
28
|
+
@assets = MyJohnDeereApi::Request::Collection::Assets.new(client, organization: id)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def map_attributes(record)
|
34
|
+
@name = record['name']
|
35
|
+
@type = record['type']
|
36
|
+
@member = record['member']
|
37
|
+
end
|
38
|
+
|
39
|
+
def expected_record_type
|
40
|
+
'Organization'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|