Class: Sendly::Contact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Contact

Returns a new instance of Contact.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sendly/contacts_resource.rb', line 10

def initialize(data)
  @id = data["id"]
  @phone_number = data["phone_number"] || data["phoneNumber"]
  @name = data["name"]
  @email = data["email"]
  @metadata = data["metadata"] || {}
  @opted_out = data["opted_out"] || data["optedOut"] || false
  @line_type = data["line_type"] || data["lineType"]
  @carrier_name = data["carrier_name"] || data["carrierName"]
  @line_type_checked_at = parse_time(data["line_type_checked_at"] || data["lineTypeCheckedAt"])
  @invalid_reason = data["invalid_reason"] || data["invalidReason"]
  @invalidated_at = parse_time(data["invalidated_at"] || data["invalidatedAt"])
  @user_marked_valid_at = parse_time(data["user_marked_valid_at"] || data["userMarkedValidAt"])
  @created_at = parse_time(data["created_at"] || data["createdAt"])
  @updated_at = parse_time(data["updated_at"] || data["updatedAt"])
  @lists = data["lists"]&.map { |l| { id: l["id"], name: l["name"] } }
end

Instance Attribute Details

#carrier_nameObject (readonly)

Returns the value of attribute carrier_name.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def carrier_name
  @carrier_name
end

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def created_at
  @created_at
end

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def id
  @id
end

#invalid_reasonObject (readonly)

Returns the value of attribute invalid_reason.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def invalid_reason
  @invalid_reason
end

#invalidated_atObject (readonly)

Returns the value of attribute invalidated_at.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def invalidated_at
  @invalidated_at
end

#line_typeObject (readonly)

Returns the value of attribute line_type.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def line_type
  @line_type
end

#line_type_checked_atObject (readonly)

Returns the value of attribute line_type_checked_at.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def line_type_checked_at
  @line_type_checked_at
end

#listsObject (readonly)

Returns the value of attribute lists.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def lists
  @lists
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def name
  @name
end

#opted_outObject (readonly)

Returns the value of attribute opted_out.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def opted_out
  @opted_out
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def phone_number
  @phone_number
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def updated_at
  @updated_at
end

#user_marked_valid_atObject (readonly)

Returns the value of attribute user_marked_valid_at.



5
6
7
# File 'lib/sendly/contacts_resource.rb', line 5

def user_marked_valid_at
  @user_marked_valid_at
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/sendly/contacts_resource.rb', line 32

def invalid?
  !invalid_reason.nil?
end

#opted_out?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/sendly/contacts_resource.rb', line 28

def opted_out?
  opted_out
end

#to_hObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sendly/contacts_resource.rb', line 36

def to_h
  {
    id: id, phone_number: phone_number, name: name, email: email,
    metadata: , opted_out: opted_out,
    line_type: line_type, carrier_name: carrier_name,
    line_type_checked_at: line_type_checked_at&.iso8601,
    invalid_reason: invalid_reason,
    invalidated_at: invalidated_at&.iso8601,
    user_marked_valid_at: user_marked_valid_at&.iso8601,
    created_at: created_at&.iso8601, updated_at: updated_at&.iso8601,
    lists: lists
  }.compact
end