Class: MyJohnDeereApi::Model::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers::CaseConversion, Helpers::UriHelpers
Defined in:
lib/my_john_deere_api/model/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, record) ⇒ Base

arguments:

client

the client, because it contains all the config info. The alternative would be a true Config block, but then settings would be app-wide. This allows one app to have multiple clients with different settings.

record

a JSON object of type ‘Field’, returned from the API.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/my_john_deere_api/model/base.rb', line 18

def initialize(client, record)
  verify_record_type(record['@type'])

  @id = record['id']
  @record = record
  @record_type = record['@type']
  @client = client
  @unsaved = false

  map_attributes(record)

  @links = {}

  record['links'].each do |association|
    @links[underscore(association['rel'])] = uri_path(association['uri'])
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/my_john_deere_api/model/base.rb', line 6

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/my_john_deere_api/model/base.rb', line 6

def id
  @id
end

Returns the value of attribute links.



6
7
8
# File 'lib/my_john_deere_api/model/base.rb', line 6

def links
  @links
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/my_john_deere_api/model/base.rb', line 6

def record
  @record
end

#record_typeObject (readonly)

Returns the value of attribute record_type.



6
7
8
# File 'lib/my_john_deere_api/model/base.rb', line 6

def record_type
  @record_type
end

Instance Method Details

#accessorObject

The client accessor



39
40
41
42
# File 'lib/my_john_deere_api/model/base.rb', line 39

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