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,53 @@ | |
| 1 | 
            +
            module MyJohnDeereApi
         | 
| 2 | 
            +
              module NetHttpRetry
         | 
| 3 | 
            +
                class Decorator
         | 
| 4 | 
            +
                  attr_reader :object, :request_methods, :retry_delay_exponent, :max_retries, :response_codes
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  DEFAULTS = {
         | 
| 7 | 
            +
                    request_methods:      [:get, :post, :put, :delete],
         | 
| 8 | 
            +
                    retry_delay_exponent: 2,
         | 
| 9 | 
            +
                    max_retries: 12,
         | 
| 10 | 
            +
                    response_codes: ['429', '503']
         | 
| 11 | 
            +
                  }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def initialize(object, options={})
         | 
| 14 | 
            +
                    @object = object
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    [:request_methods, :retry_delay_exponent, :max_retries].each do |option|
         | 
| 17 | 
            +
                      instance_variable_set(:"@#{option}", options[option] || DEFAULTS[option])
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    @response_codes = (options[:response_codes] || DEFAULTS[:response_codes]).map(&:to_s)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def request(method_name, *args)
         | 
| 24 | 
            +
                    retries = 0
         | 
| 25 | 
            +
                    result = object.send(method_name, *args)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    while response_codes.include?(result.code)
         | 
| 28 | 
            +
                      if retries >= max_retries
         | 
| 29 | 
            +
                        raise MaxRetriesExceededError.new(method_name, "#{result.code} #{result.message}")
         | 
| 30 | 
            +
                      end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                      delay = [result['retry-after'].to_i, retry_delay_exponent ** retries].max
         | 
| 33 | 
            +
                      sleep(delay)
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                      result = object.send(method_name, *args)
         | 
| 36 | 
            +
                      retries += 1
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    result
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  private
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def method_missing(method_name, *args, &block)
         | 
| 45 | 
            +
                    if request_methods.include?(method_name)
         | 
| 46 | 
            +
                      request(method_name, *args)
         | 
| 47 | 
            +
                    else
         | 
| 48 | 
            +
                      object.send(method_name, *args, &block)
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            module MyJohnDeereApi
         | 
| 2 | 
            +
              module NetHttpRetry
         | 
| 3 | 
            +
                ##
         | 
| 4 | 
            +
                # This error is used when a single request has exceeded
         | 
| 5 | 
            +
                # the number of retries allowed by NetHttpRetry::Decorator::MAX_RETRIES.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                class MaxRetriesExceededError < StandardError
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  ##
         | 
| 10 | 
            +
                  # argument is a string which describes the attempted request
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def initialize(request_method, response_message)
         | 
| 13 | 
            +
                    message = "Max retries exceeded for #{request_method.to_s.upcase} " +
         | 
| 14 | 
            +
                              "request: #{response_message}"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    super(message)
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,6 @@ | |
| 1 | 
            +
            module MyJohnDeereApi::Request
         | 
| 2 | 
            +
              autoload :Collection,           'my_john_deere_api/request/collection'
         | 
| 3 | 
            +
              autoload :Create,               'my_john_deere_api/request/create'
         | 
| 4 | 
            +
              autoload :Individual,           'my_john_deere_api/request/individual'
         | 
| 5 | 
            +
              autoload :Update,               'my_john_deere_api/request/update'
         | 
| 6 | 
            +
            end
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            module MyJohnDeereApi::Request::Collection
         | 
| 2 | 
            +
              autoload :Base,                       'my_john_deere_api/request/collection/base'
         | 
| 3 | 
            +
              autoload :Assets,                     'my_john_deere_api/request/collection/assets'
         | 
| 4 | 
            +
              autoload :AssetLocations,             'my_john_deere_api/request/collection/asset_locations'
         | 
| 5 | 
            +
              autoload :ContributionProducts,       'my_john_deere_api/request/collection/contribution_products'
         | 
| 6 | 
            +
              autoload :ContributionDefinitions,    'my_john_deere_api/request/collection/contribution_definitions'
         | 
| 7 | 
            +
              autoload :Organizations,              'my_john_deere_api/request/collection/organizations'
         | 
| 8 | 
            +
              autoload :Fields,                     'my_john_deere_api/request/collection/fields'
         | 
| 9 | 
            +
              autoload :Flags,                      'my_john_deere_api/request/collection/flags'
         | 
| 10 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::AssetLocations < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  "/assets/#{associations[:asset]}/locations"
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::AssetLocation
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Create a new asset location
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def create(attributes)
         | 
| 23 | 
            +
                  merged_attributes = attributes.merge(asset_id: associations[:asset])
         | 
| 24 | 
            +
                  Create::AssetLocation.new(client, merged_attributes).object
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::Assets < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  "/organizations/#{associations[:organization]}/assets"
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::Asset
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Create a new asset
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def create(attributes)
         | 
| 23 | 
            +
                  merged_attributes = attributes.merge(organization_id: associations[:organization])
         | 
| 24 | 
            +
                  Create::Asset.new(client, merged_attributes).object
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                ##
         | 
| 28 | 
            +
                # Retrieve an asset from JD
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def find(asset_id)
         | 
| 31 | 
            +
                  Individual::Asset.new(client, asset_id).object
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            module MyJohnDeereApi
         | 
| 2 | 
            +
              class Request::Collection::Base
         | 
| 3 | 
            +
                include Enumerable
         | 
| 4 | 
            +
                include Helpers::UriHelpers
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                attr_reader :client, :associations
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                ##
         | 
| 9 | 
            +
                # client is the original client instance which contains
         | 
| 10 | 
            +
                # the necessary config info.
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def initialize(client, associations = {})
         | 
| 13 | 
            +
                  @client = client
         | 
| 14 | 
            +
                  @associations = associations
         | 
| 15 | 
            +
                  @items = []
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                ##
         | 
| 19 | 
            +
                # client accessor
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def accessor
         | 
| 22 | 
            +
                  return @accessor if defined?(@accessor)
         | 
| 23 | 
            +
                  @accessor = client&.accessor
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                ##
         | 
| 27 | 
            +
                # Iterate lazily through all records in the collection, fetching
         | 
| 28 | 
            +
                # additional pages as needed.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def each(&block)
         | 
| 31 | 
            +
                  count.times do |index|
         | 
| 32 | 
            +
                    fetch if @items.size <= index
         | 
| 33 | 
            +
                    block.call(@items[index])
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                ##
         | 
| 38 | 
            +
                # Return all objects in the collection at once
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def all
         | 
| 41 | 
            +
                  return @all if defined?(@all)
         | 
| 42 | 
            +
                  @all = map { |i| i }
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                ##
         | 
| 46 | 
            +
                # Total count of records, even before pagination
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def count
         | 
| 49 | 
            +
                  @count ||= first_page['total']
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                private
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def first_page
         | 
| 55 | 
            +
                  return @first_page if defined?(@first_page)
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  @first_page = JSON.parse(accessor.get(resource, headers).body)
         | 
| 58 | 
            +
                  extract_page_contents(@first_page)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  @first_page
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def fetch
         | 
| 64 | 
            +
                  return unless @next_page
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  page = JSON.parse(accessor.get(@next_page, headers).body)
         | 
| 67 | 
            +
                  extract_page_contents(page)
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                def headers
         | 
| 71 | 
            +
                  @headers ||= {accept: 'application/vnd.deere.axiom.v3+json'}
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                def extract_page_contents(page)
         | 
| 75 | 
            +
                  add_items_from_page(page)
         | 
| 76 | 
            +
                  set_next_page(page)
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                def add_items_from_page(page)
         | 
| 80 | 
            +
                  @items += page['values'].map{|record| model.new(client, record) }
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                def set_next_page(page)
         | 
| 84 | 
            +
                  if next_page = page['links'].detect{|link| link['rel'] == 'nextPage'}
         | 
| 85 | 
            +
                    @next_page = uri_path(next_page['uri'])
         | 
| 86 | 
            +
                  else
         | 
| 87 | 
            +
                    @next_page = nil
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                end
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::ContributionDefinitions < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  "/contributionProducts/#{associations[:contribution_product]}/contributionDefinitions"
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::ContributionDefinition
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Retrieve an item from JD
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def find(item_id)
         | 
| 23 | 
            +
                  Individual::ContributionDefinition.new(client, item_id).object
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -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(client, item_id).object
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::Fields < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  "/organizations/#{associations[:organization]}/fields"
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::Field
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Retrieve a field from JD
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def find(field_id)
         | 
| 23 | 
            +
                  Individual::Field.new(client, field_id, organization: associations[:organization]).object
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::Flags < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  "/organizations/#{associations[:organization]}/fields/#{associations[:field]}/flags"
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::Flag
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Create a new flag (NOT YET IMPLEMENTED)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def create(attributes)
         | 
| 23 | 
            +
                  raise NotImplementedError
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                ##
         | 
| 27 | 
            +
                # Retrieve an flag from JD (NOT YET IMPLEMENTED)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def find(asset_id)
         | 
| 30 | 
            +
                  raise NotImplementedError
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi::Request
         | 
| 4 | 
            +
              class Collection::Organizations < Collection::Base
         | 
| 5 | 
            +
                ##
         | 
| 6 | 
            +
                # The resource path for the first page in the collection
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def resource
         | 
| 9 | 
            +
                  '/organizations'
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                ##
         | 
| 13 | 
            +
                # This is the class used to model the data
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def model
         | 
| 16 | 
            +
                  MyJohnDeereApi::Model::Organization
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                ##
         | 
| 20 | 
            +
                # Retrieve an organization from JD
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def find(organization_id)
         | 
| 23 | 
            +
                  Individual::Organization.new(client, organization_id).object
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MyJohnDeereApi
         | 
| 4 | 
            +
              class Request::Create::Asset < Request::Create::Base
         | 
| 5 | 
            +
                include Validators::Asset
         | 
| 6 | 
            +
                include Helpers::ValidateContributionDefinition
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                private
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                ##
         | 
| 11 | 
            +
                # Retrieve newly created record
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def fetch_record
         | 
| 14 | 
            +
                  path = response['location'].split('/platform').last
         | 
| 15 | 
            +
                  result = accessor.get(path, headers)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  JSON.parse(result.body)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                ##
         | 
| 21 | 
            +
                # This is the class used to model the data
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def model
         | 
| 24 | 
            +
                  Model::Asset
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                ##
         | 
| 28 | 
            +
                # Path supplied to API
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def resource
         | 
| 31 | 
            +
                  @resource ||= "/organizations/#{attributes[:organization_id]}/assets"
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                ##
         | 
| 35 | 
            +
                # Request body
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def request_body
         | 
| 38 | 
            +
                  return @body if defined?(@body)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  validate_contribution_definition
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  @body = {
         | 
| 43 | 
            +
                    title: attributes[:title],
         | 
| 44 | 
            +
                    assetCategory: attributes[:asset_category],
         | 
| 45 | 
            +
                    assetType: attributes[:asset_type],
         | 
| 46 | 
            +
                    assetSubType: attributes[:asset_sub_type],
         | 
| 47 | 
            +
                    links: [
         | 
| 48 | 
            +
                      {
         | 
| 49 | 
            +
                        '@type' => 'Link',
         | 
| 50 | 
            +
                        'rel' => 'contributionDefinition',
         | 
| 51 | 
            +
                        'uri' => "#{accessor.consumer.site}/contributionDefinitions/#{client.contribution_definition_id}"
         | 
| 52 | 
            +
                      }
         | 
| 53 | 
            +
                    ]
         | 
| 54 | 
            +
                  }
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         |