Class: RelateIq::List

Inherits:
Object
  • Object
show all
Defined in:
lib/relateiq/list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#fieldsObject

Returns the value of attribute fields.



3
4
5
# File 'lib/relateiq/list.rb', line 3

def fields
  @fields
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/relateiq/list.rb', line 3

def id
  @id
end

#list_typeObject

Returns the value of attribute list_type.



3
4
5
# File 'lib/relateiq/list.rb', line 3

def list_type
  @list_type
end

#modified_dateObject

Returns the value of attribute modified_date.



3
4
5
# File 'lib/relateiq/list.rb', line 3

def modified_date
  @modified_date
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/relateiq/list.rb', line 3

def title
  @title
end

Class Method Details

.allObject



21
22
23
# File 'lib/relateiq/list.rb', line 21

def self.all
  @all ||= from_json(resource.get)
end

.clean_cacheObject



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

.resourceObject



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