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

#accessorObject

client accessor



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

def accessor
  return @accessor if defined?(@accessor)
  @accessor = client&.accessor
end

#objectObject

Object created by request



39
40
41
42
43
44
45
# File 'lib/my_john_deere_api/request/create/base.rb', line 39

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

  request unless response

  @object = model.new(client, fetch_record)
end

#requestObject

Make the request, if the instance is valid



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

def request
  validate!

  @response = accessor.post(resource, request_body.to_json, headers)
end