Class: MyJohnDeereApi::Request::Create::AssetLocation

Inherits:
Base
  • Object
show all
Includes:
Helpers::UriHelpers, Validators::AssetLocation
Defined in:
lib/my_john_deere_api/request/create/asset_location.rb

Instance Attribute Summary

Attributes included from Validators::Base

#errors

Attributes inherited from Base

#attributes, #client, #response

Instance Method Summary collapse

Methods included from Validators::Base

#valid?, #validate!

Methods inherited from Base

#initialize, #request

Constructor Details

This class inherits a constructor from MyJohnDeereApi::Request::Create::Base

Instance Method Details

#objectObject

Object created by request

There is no endpoint to fetch a single location by id, so we have to override the ‘object` method from the base class.

We have to fetch locations in bulk via the asset, but there could be thousands. We limit the request to just the first record from the location list endpoint, since locations are returned newest to oldest.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/my_john_deere_api/request/create/asset_location.rb', line 18

def object
  return @object if defined?(@object)

  request unless response

  path = uri_path(response.headers['location']) + '?count=1'
  result = client.get(path)
  record = result['values'].first

  @object = Model::AssetLocation.new(client, record)
end