Class: RIQ::ListItem
Overview
A List Item is a row in a List.
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#contact_ids ⇒ Object
Returns the value of attribute contact_ids.
-
#created_date ⇒ Object
readonly
Returns the value of attribute created_date.
-
#field_values ⇒ Object
Returns the value of attribute field_values.
-
#list_id ⇒ Object
Returns the value of attribute list_id.
-
#modified_date ⇒ Object
readonly
Returns the value of attribute modified_date.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from RIQObject
Class Method Summary collapse
Instance Method Summary collapse
-
#data ⇒ Hash
All relevant stored data.
- #field_value(key, value = nil) ⇒ Object
-
#initialize(id = nil, lid: nil) ⇒ ListItem
constructor
A new instance of ListItem.
-
#node ⇒ String
Endpoint.
-
#payload ⇒ String
The JSON representation of #data.
Methods inherited from RIQObject
Constructor Details
#initialize(id = nil, lid: nil) ⇒ ListItem
Returns a new instance of ListItem.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/riq/list_item.rb', line 21 def initialize(id = nil, lid: nil) if id.is_a? Hash # init with data super(id) elsif id.nil? # vanilla object super(nil) # maybe init with lid @list_id = lid unless lid.nil? elsif lid.nil? # has id, but not lid, that's an error raise RIQError, 'ObjectID and List ID are required' else # grabbing a specific listitem, fetch it super("#{lid}/listitems/#{id}") end end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
9 10 11 |
# File 'lib/riq/list_item.rb', line 9 def account_id @account_id end |
#contact_ids ⇒ Object
Returns the value of attribute contact_ids.
10 11 12 |
# File 'lib/riq/list_item.rb', line 10 def contact_ids @contact_ids end |
#created_date ⇒ Object (readonly)
Returns the value of attribute created_date.
14 15 16 |
# File 'lib/riq/list_item.rb', line 14 def created_date @created_date end |
#field_values ⇒ Object
Returns the value of attribute field_values.
8 9 10 |
# File 'lib/riq/list_item.rb', line 8 def field_values @field_values end |
#list_id ⇒ Object
Returns the value of attribute list_id.
11 12 13 |
# File 'lib/riq/list_item.rb', line 11 def list_id @list_id end |
#modified_date ⇒ Object (readonly)
Returns the value of attribute modified_date.
13 14 15 |
# File 'lib/riq/list_item.rb', line 13 def modified_date @modified_date end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/riq/list_item.rb', line 7 def name @name end |
Class Method Details
.node(lid = nil, oid = nil) ⇒ Object
this is the only object for which you have to include two params
47 48 49 50 51 52 53 54 |
# File 'lib/riq/list_item.rb', line 47 def self.node(lid = nil, oid = nil) # weird workaround for fetching node on init if lid.nil? && !oid.nil? "lists/#{oid}" else "lists/#{lid || @list_id}/listitems/#{oid}" end end |
Instance Method Details
#data ⇒ Hash
Returns all relevant stored data.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/riq/list_item.rb', line 57 def data { name: @name, account_id: @account_id, contact_ids: @contact_ids.flatten, id: @id, list_id: @list_id, field_values: @field_values, modified_date: @modified_date } end |
#field_value(key) ⇒ String, Array #field_value(key, value) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/riq/list_item.rb', line 91 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 unless value.is_a? Array value = value.to_s end @field_values[key.to_sym] = value {key.to_sym => value} end end |
#node ⇒ String
Returns endpoint.
40 41 42 |
# File 'lib/riq/list_item.rb', line 40 def node self.class.node(@list_id, @id) end |
#payload ⇒ String
Returns the JSON representation of #data.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/riq/list_item.rb', line 70 def payload pld = {} data.each do |k, v| if k == :field_values pld['fieldValues'] = @field_values.to_raw elsif k['_'] pld[k.to_cam] = v else pld[k] = v end end pld.to_json end |