Class: RelateIq::List
- Inherits:
-
Object
- Object
- RelateIq::List
- Defined in:
- lib/relateiq/list.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#id ⇒ Object
Returns the value of attribute id.
-
#list_type ⇒ Object
Returns the value of attribute list_type.
-
#modified_date ⇒ Object
Returns the value of attribute modified_date.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .all ⇒ Object
- .clean_cache ⇒ Object
- .find(id) ⇒ Object
- .find_by_title(title) ⇒ Object
- .from_json(json_string) ⇒ Object
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ List
constructor
A new instance of List.
- #items_by_contact_id(contact_id) ⇒ Object
- #upsert_item(list_item_hash) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ List
Returns a new instance of List.
9 10 11 12 13 14 15 |
# File 'lib/relateiq/list.rb', line 9 def initialize(attrs = {}) if attrs.key? :listType initialize_from_api(attrs) else initialize_from_user(attrs) end end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
3 4 5 |
# File 'lib/relateiq/list.rb', line 3 def fields @fields end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/relateiq/list.rb', line 3 def id @id end |
#list_type ⇒ Object
Returns the value of attribute list_type.
3 4 5 |
# File 'lib/relateiq/list.rb', line 3 def list_type @list_type end |
#modified_date ⇒ Object
Returns the value of attribute modified_date.
3 4 5 |
# File 'lib/relateiq/list.rb', line 3 def modified_date @modified_date end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/relateiq/list.rb', line 3 def title @title end |
Class Method Details
.all ⇒ Object
21 22 23 |
# File 'lib/relateiq/list.rb', line 21 def self.all @all ||= from_json(resource.get) end |
.clean_cache ⇒ Object
33 34 35 |
# File 'lib/relateiq/list.rb', line 33 def self.clean_cache @all = nil end |
.find(id) ⇒ Object
29 30 31 |
# File 'lib/relateiq/list.rb', line 29 def self.find(id) all.find { |l| l.id == id } end |
.find_by_title(title) ⇒ Object
25 26 27 |
# File 'lib/relateiq/list.rb', line 25 def self.find_by_title(title) all.find { |l| l.title.downcase == title.downcase } end |
.from_json(json_string) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/relateiq/list.rb', line 37 def self.from_json(json_string) lists_hash = JSON.parse(json_string, symbolize_names: true) if lists_hash.key? :objects lists_hash[:objects].map { |li| List.new(li) } else List.new(lists_hash) end end |
.resource ⇒ Object
17 18 19 |
# File 'lib/relateiq/list.rb', line 17 def self.resource @resource ||= ServiceFactory.get_endpoint('lists') end |
Instance Method Details
#items_by_contact_id(contact_id) ⇒ Object
51 52 53 |
# File 'lib/relateiq/list.rb', line 51 def items_by_contact_id(contact_id) list_item_class.find_by_contact(id, contact_id) end |
#upsert_item(list_item_hash) ⇒ Object
46 47 48 49 |
# File 'lib/relateiq/list.rb', line 46 def upsert_item(list_item_hash) list_item_hash.merge!(list_id: id) list_item_class.new(list_item_hash).save end |