Class: Mailflow::Contact

Inherits:
Object
  • Object
show all
Includes:
APIOperations
Defined in:
lib/mailflow-ruby/contact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations

included

Constructor Details

#initialize(attributes) ⇒ Contact

Returns a new instance of Contact.



31
32
33
34
35
36
# File 'lib/mailflow-ruby/contact.rb', line 31

def initialize(attributes)
  @id = attributes["id"]
  @email = attributes["email"]
  @created_at = attributes["created_at"]
  @confirmed = attributes["confirmed"]
end

Instance Attribute Details

#confirmedObject

Returns the value of attribute confirmed.



9
10
11
# File 'lib/mailflow-ruby/contact.rb', line 9

def confirmed
  @confirmed
end

#created_atObject

Returns the value of attribute created_at.



9
10
11
# File 'lib/mailflow-ruby/contact.rb', line 9

def created_at
  @created_at
end

#emailObject

Returns the value of attribute email.



9
10
11
# File 'lib/mailflow-ruby/contact.rb', line 9

def email
  @email
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/mailflow-ruby/contact.rb', line 9

def id
  @id
end

Class Method Details

.create(attributes) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/mailflow-ruby/contact.rb', line 24

def create(attributes)
  response = post_request('contacts', attributes)
  raise UnprocessableError if (response.code == 422 || response.code == 404)
  Contact.new(response.parsed_response)
end

.get(options = {}) ⇒ Object



19
20
21
22
# File 'lib/mailflow-ruby/contact.rb', line 19

def get(options = {})
  response = get_request('contacts', options)
  Contact.new(response.parsed_response) if response.code == 200
end

.listObject



12
13
14
15
16
17
# File 'lib/mailflow-ruby/contact.rb', line 12

def list
  response = get_request('contacts')
  response.parsed_response.map do |attributes|
    Contact.new(attributes)
  end
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
# File 'lib/mailflow-ruby/contact.rb', line 38

def ==(other)
  self.id == other.id &&
  self.email == other.email &&
  self.confirmed == other.confirmed
end

#attributesObject



62
63
64
# File 'lib/mailflow-ruby/contact.rb', line 62

def attributes
  Mailflow::Attribute.list(contact_id: id)
end

#deleteObject



44
45
46
# File 'lib/mailflow-ruby/contact.rb', line 44

def delete
  Mailflow::Contact.delete_request('contacts', {contact_id: id}).parsed_response
end

#set_attributes(attributes) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/mailflow-ruby/contact.rb', line 66

def set_attributes(attributes)
  attributes = attributes.map do |key, value|
    {key: key.to_s, label: key.to_s, value: value}
  end

  Mailflow::Attribute.update(attributes, {contact_id: id})
  self
end

#tag(tags, trigger = false) ⇒ Object



52
53
54
55
# File 'lib/mailflow-ruby/contact.rb', line 52

def tag(tags, trigger = false)
  Mailflow::Tag.create(tags, {contact_id: id}, trigger)
  self
end

#tagsObject



48
49
50
# File 'lib/mailflow-ruby/contact.rb', line 48

def tags
  Mailflow::Tag.list(contact_id: id)
end

#untag(tags) ⇒ Object



57
58
59
60
# File 'lib/mailflow-ruby/contact.rb', line 57

def untag(tags)
  Mailflow::Tag.untag(tags, {contact_id: id})
  self
end