Class: Mailtrap::Contact

Inherits:
Struct
  • Object
show all
Defined in:
lib/mailtrap/contact.rb

Overview

Data Transfer Object for Contact

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Contact

Returns a new instance of Contact.



23
24
25
26
# File 'lib/mailtrap/contact.rb', line 23

def initialize(options)
  @action = options[:action]
  super(options.except(:action))
end

Instance Attribute Details

#created_atInteger (readonly)

The creation timestamp

Returns:

  • (Integer)

    the current value of created_at



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def created_at
  @created_at
end

#emailString (readonly)

The contact’s email address

Returns:

  • (String)

    the current value of email



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def email
  @email
end

#fieldsHash (readonly)

Object of fields with merge tags

Returns:

  • (Hash)

    the current value of fields



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def fields
  @fields
end

#idString (readonly)

The contact ID

Returns:

  • (String)

    the current value of id



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def id
  @id
end

#list_idsArray<Integer> (readonly)

Array of list IDs

Returns:

  • (Array<Integer>)

    the current value of list_ids



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def list_ids
  @list_ids
end

#statusString (readonly)

The contact status (subscribed/unsubscribed)

Returns:

  • (String)

    the current value of status



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def status
  @status
end

#updated_atInteger (readonly)

The last update timestamp

Returns:

  • (Integer)

    the current value of updated_at



13
14
15
# File 'lib/mailtrap/contact.rb', line 13

def updated_at
  @updated_at
end

Instance Method Details

#newly_created?Boolean

Returns Whether the contact was newly created.

Returns:

  • (Boolean)

    Whether the contact was newly created



29
30
31
# File 'lib/mailtrap/contact.rb', line 29

def newly_created?
  @action != 'updated'
end

#to_hHash

Returns The contact attributes as a hash.

Returns:

  • (Hash)

    The contact attributes as a hash



34
35
36
# File 'lib/mailtrap/contact.rb', line 34

def to_h
  super.compact
end