Class: MyJohnDeereApi::Request::Create::Base

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

Direct Known Subclasses

Asset, AssetLocation

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, attributes) ⇒ Base

Accepts a valid oAuth AccessToken, and a hash of attributes.



12
13
14
15
16
17
# File 'lib/my_john_deere_api/request/create/base.rb', line 12

def initialize(client, attributes)
  @client = client
  @attributes = 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/create/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/create/base.rb', line 7

def client
  @client
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#objectObject

Object created by request



31
32
33
34
35
36
37
# File 'lib/my_john_deere_api/request/create/base.rb', line 31

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

  request unless response

  @object = individual_class.new(client, record_id).object
end

#requestObject

Make the request, if the instance is valid



22
23
24
25
26
# File 'lib/my_john_deere_api/request/create/base.rb', line 22

def request
  validate!

  @response = client.post(resource, request_body)
end