Class: SignalApi::Contact

Inherits:
Object
  • Object
show all
Includes:
ApiMock
Defined in:
lib/signal_api/contact.rb,
lib/signal_api/mocks/contact.rb

Overview

A Contact (person, subscriber, etc) on the Signal platform

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiMock

included

Constructor Details

#initialize(attributes = {}) ⇒ Contact

Returns a new instance of Contact.



9
10
11
# File 'lib/signal_api/contact.rb', line 9

def initialize(attributes={})
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

The user attributes associated with the contact



7
8
9
# File 'lib/signal_api/contact.rb', line 7

def attributes
  @attributes
end

Instance Method Details

#email_addressObject

Convenience accessor for the contact’s email address



19
20
21
# File 'lib/signal_api/contact.rb', line 19

def email_address
  @attributes['email-address']
end

#mobile_phoneObject

Convenience accessor for the contact’s mobile phone



14
15
16
# File 'lib/signal_api/contact.rb', line 14

def mobile_phone
  @attributes['mobile-phone']
end

#saveObject

Update the contact’s data on the Signal platform.

Returns:

  • true If the contact’s data was saved successfully.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/signal_api/contact.rb', line 26

def save
  validate_contact_update

  xml = Builder::XmlMarkup.new
  xml.user_attributes do
    attributes.each do |key, value|
      xml.tag!(key, value)
    end
  end

  contact_identifier = mobile_phone.blank? ? email_address : mobile_phone

  with_retries do
    response = put("/api/contacts/#{contact_identifier}.xml",
                   :body => xml.target!,
                   :format => :xml,
                   :headers => common_headers)

    if response.code == 200
      true
    else
      handle_api_failure(response)
    end
  end
end

#save_additional_infoObject



9
10
11
# File 'lib/signal_api/mocks/contact.rb', line 9

def save_additional_info
  { :attributes => @attributes }
end