Class: MyJohnDeereApi::Request::Update::Base

Inherits:
Object
  • Object
show all
Includes:
Validators::Base
Defined in:
lib/my_john_deere_api/request/update/base.rb

Direct Known Subclasses

Asset

Instance Attribute Summary collapse

Attributes included from Validators::Base

#errors

Instance Method Summary collapse

Methods included from Validators::Base

#valid?, #validate!

Constructor Details

#initialize(client, item, attributes) ⇒ Base

Accepts a valid oAuth AccessToken, the item to be updated, and a hash of attributes.

category/type/subtype must be a recognized combination as defined above.



15
16
17
18
19
20
21
# File 'lib/my_john_deere_api/request/update/base.rb', line 15

def initialize(client, item, attributes)
  @client = client
  @item = item
  @attributes = item.attributes.merge(attributes)

  process_attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/my_john_deere_api/request/update/base.rb', line 7

def attributes
  @attributes
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/my_john_deere_api/request/update/base.rb', line 7

def client
  @client
end

#itemObject (readonly)

Returns the value of attribute item.



7
8
9
# File 'lib/my_john_deere_api/request/update/base.rb', line 7

def item
  @item
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/my_john_deere_api/request/update/base.rb', line 7

def response
  @response
end

Instance Method Details

#objectObject

Object, same as item for updates



35
36
37
# File 'lib/my_john_deere_api/request/update/base.rb', line 35

def object
  @object ||= item
end

#requestObject

Make the request, if the instance is valid



26
27
28
29
30
# File 'lib/my_john_deere_api/request/update/base.rb', line 26

def request
  validate!

  @response = client.put(resource, request_body.to_json)
end