Class: RIQ::Account

Inherits:
RIQObject show all
Defined in:
lib/riq/account.rb

Overview

Accounts represent companies (or other entities).

Instance Attribute Summary collapse

Attributes inherited from RIQObject

#id, #modified_date

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RIQObject

#delete, #initialize, #save

Constructor Details

This class inherits a constructor from RIQ::RIQObject

Instance Attribute Details

#field_valuesObject

Returns the value of attribute field_values.



8
9
10
# File 'lib/riq/account.rb', line 8

def field_values
  @field_values
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/riq/account.rb', line 7

def name
  @name
end

Class Method Details

.node(arg = nil) ⇒ Object



16
17
18
# File 'lib/riq/account.rb', line 16

def self.node(arg = nil)
  "accounts"
end

Instance Method Details

#dataHash

Returns all relevant stored data.

Returns:

  • (Hash)

    all relevant stored data



21
22
23
24
25
26
27
# File 'lib/riq/account.rb', line 21

def data
  {
    id: @id,
    name: @name,
    field_values: @field_values
  }
end

#field_value(key) ⇒ Array #field_value(key, value) ⇒ Object

Overloads:

  • #field_value(key) ⇒ Array

    Returns Value of key.

    Parameters:

    • key (String, Integer)

    Returns:

    • (Array)

      Value of key

  • #field_value(key, value) ⇒ Object

    Sets key to value

    Parameters:

    • key (String, Integer)

      Key to set

    • value (#to_s)

      Sets key to value



45
46
47
48
49
50
51
52
53
54
# File 'lib/riq/account.rb', line 45

def field_value(key, value = nil)
  # TODO: double check that this works with arrays of stuff
  # or, have a format function that casts ints to string on save
  if value.nil?
    @field_values.fetch(key.to_sym, nil)
  else
    @field_values[key.to_sym] = value.to_s
    {key.to_sym => value.to_s}
  end
end

#nodeString

Returns endpoint.

Returns:

  • (String)

    endpoint



11
12
13
# File 'lib/riq/account.rb', line 11

def node
  "accounts/#{@id}"
end

#payloadString

Returns the JSON representation of #data.

Returns:

  • (String)

    the JSON representation of #data



30
31
32
33
34
35
36
# File 'lib/riq/account.rb', line 30

def payload
  # TODO: find more elegant way to do this
  pld = data
  pld['fieldValues'] = @field_values.to_raw
  pld.delete(:field_values)
  pld.to_json
end