Class: RelateIq::ListItem
- Inherits:
-
Object
- Object
- RelateIq::ListItem
- Defined in:
- lib/relateiq/list_item.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#contact_ids ⇒ Object
Returns the value of attribute contact_ids.
-
#field_values ⇒ Object
Returns the value of attribute field_values.
-
#id ⇒ Object
Returns the value of attribute id.
-
#list_id ⇒ Object
Returns the value of attribute list_id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .create(attrs) ⇒ Object
- .find_by_contact(list_id, contact_id) ⇒ Object
- .from_json(json_string) ⇒ Object
- .resource(list_id) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ ListItem
constructor
field values always contains decoded values for example { ‘Status’ => ‘Application Submitted’ }.
- #initialize_by_user(attrs) ⇒ Object
- #initialize_from_api(attrs) ⇒ Object
- #save ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ ListItem
field values always contains decoded values for example { ‘Status’ => ‘Application Submitted’ }
13 14 15 16 17 18 19 |
# File 'lib/relateiq/list_item.rb', line 13 def initialize(attrs = {}) if attrs.key? :listId initialize_from_api(attrs) else initialize_by_user(attrs) end end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def account_id @account_id end |
#contact_ids ⇒ Object
Returns the value of attribute contact_ids.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def contact_ids @contact_ids end |
#field_values ⇒ Object
Returns the value of attribute field_values.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def field_values @field_values end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def id @id end |
#list_id ⇒ Object
Returns the value of attribute list_id.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def list_id @list_id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/relateiq/list_item.rb', line 3 def name @name end |
Class Method Details
.create(attrs) ⇒ Object
53 54 55 |
# File 'lib/relateiq/list_item.rb', line 53 def self.create(attrs) ListItem.new(attrs).save end |
.find_by_contact(list_id, contact_id) ⇒ Object
57 58 59 |
# File 'lib/relateiq/list_item.rb', line 57 def self.find_by_contact(list_id, contact_id) from_json(resource(list_id)["?contactIds=#{contact_id}"].get) end |
.from_json(json_string) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/relateiq/list_item.rb', line 44 def self.from_json(json_string) list_item_hash = JSON.parse(json_string, symbolize_names: true) if list_item_hash.key? :objects list_item_hash[:objects].map { |li| ListItem.new(li) } else ListItem.new(list_item_hash) end end |
.resource(list_id) ⇒ Object
39 40 41 42 |
# File 'lib/relateiq/list_item.rb', line 39 def self.resource(list_id) @resource ||= ServiceFactory.get_endpoint('lists') @resource["#{list_id}/listitems"] end |
Instance Method Details
#initialize_by_user(attrs) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/relateiq/list_item.rb', line 21 def initialize_by_user(attrs) @list_id = attrs.fetch(:list_id) @id = attrs.fetch(:id, nil) @name = attrs.fetch(:name, nil) @account_id = attrs.fetch(:account_id, nil) @contact_ids = attrs.fetch(:contact_ids, []) @field_values = attrs.fetch(:field_values, []) end |
#initialize_from_api(attrs) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/relateiq/list_item.rb', line 30 def initialize_from_api(attrs) @list_id = attrs.fetch(:listId) @id = attrs.fetch(:id, nil) @name = attrs.fetch(:name, nil) @account_id = attrs.fetch(:accountId, nil) @contact_ids = attrs.fetch(:contactIds, []) @field_values = decode_field_values(attrs.fetch(:fieldValues, nil)) end |
#save ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/relateiq/list_item.rb', line 61 def save if id ListItem.from_json(ListItem.resource(list_id)["#{id}"].put to_json) else ListItem.from_json(ListItem.resource(list_id).post to_json) end end |
#to_json ⇒ Object
69 70 71 |
# File 'lib/relateiq/list_item.rb', line 69 def to_json to_hash.to_json end |