class RelateIq::List

Attributes

fields[RW]
id[RW]
list_type[RW]
modified_date[RW]
title[RW]

Public Class Methods

all() click to toggle source
# File lib/relateiq/list.rb, line 21
def self.all
  @all ||= from_json(resource.get)
end
clean_cache() click to toggle source
# File lib/relateiq/list.rb, line 33
def self.clean_cache
  @all = nil
end
find(id) click to toggle source
# File lib/relateiq/list.rb, line 29
def self.find(id)
  all.find { |l| l.id == id }
end
find_by_title(title) click to toggle source
# 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) click to toggle source
# 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
new(attrs = {}) click to toggle source
# 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
resource() click to toggle source
# File lib/relateiq/list.rb, line 17
def self.resource
  @resource ||= ServiceFactory.get_endpoint('lists')
end

Public Instance Methods

items_by_contact_id(contact_id) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

initialize_from_api(attrs) click to toggle source
# File lib/relateiq/list.rb, line 61
def initialize_from_api(attrs)
  @id = attrs.fetch(:id)
  @title = attrs.fetch(:title)
  @fields = attrs.fetch(:fields)
  @list_type = attrs.fetch(:listType)
  @modified_date = attrs.fetch(:modifiedDate)
end
initialize_from_user(attrs) click to toggle source
# File lib/relateiq/list.rb, line 69
def initialize_from_user(attrs)
  @id = attrs.fetch(:id, nil)
  @title = attrs.fetch(:title, nil)
  @list_type = attrs.fetch(:list_type, nil)
  @modified_date = attrs.fetch(:modified_date, nil)
  @fields = attrs.fetch(:fields, nil)
end
list_item_class() click to toggle source
# File lib/relateiq/list.rb, line 57
def list_item_class
  @list_item_class ||= ListItem
end