Class: Sendly::ContactList

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/contacts_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ContactList

Returns a new instance of ContactList.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sendly/contacts_resource.rb', line 64

def initialize(data)
  @id = data["id"]
  @name = data["name"]
  @description = data["description"]
  @contact_count = data["contact_count"] || data["contactCount"] || 0
  @created_at = parse_time(data["created_at"] || data["createdAt"])
  @updated_at = parse_time(data["updated_at"] || data["updatedAt"])
  @contacts = data["contacts"]&.map do |c|
    {
      id: c["id"],
      phone_number: c["phone_number"] || c["phoneNumber"],
      name: c["name"],
      email: c["email"]
    }
  end
  @contacts_total = data["contacts_total"] || data["contactsTotal"]
end

Instance Attribute Details

#contact_countObject (readonly)

Returns the value of attribute contact_count.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def contact_count
  @contact_count
end

#contactsObject (readonly)

Returns the value of attribute contacts.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def contacts
  @contacts
end

#contacts_totalObject (readonly)

Returns the value of attribute contacts_total.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def contacts_total
  @contacts_total
end

#created_atObject (readonly)

Returns the value of attribute created_at.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def created_at
  @created_at
end

#descriptionObject (readonly)

Returns the value of attribute description.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def name
  @name
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



61
62
63
# File 'lib/sendly/contacts_resource.rb', line 61

def updated_at
  @updated_at
end

Instance Method Details

#to_hObject



82
83
84
85
86
87
88
89
# File 'lib/sendly/contacts_resource.rb', line 82

def to_h
  {
    id: id, name: name, description: description,
    contact_count: contact_count, created_at: created_at&.iso8601,
    updated_at: updated_at&.iso8601, contacts: contacts,
    contacts_total: contacts_total
  }.compact
end