Class: SignalApi::Contact
- Inherits:
-
Object
- Object
- SignalApi::Contact
- 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
-
#attributes ⇒ Object
The user attributes associated with the contact.
Instance Method Summary collapse
-
#email_address ⇒ Object
Convenience accessor for the contact’s email address.
-
#initialize(attributes = {}) ⇒ Contact
constructor
A new instance of Contact.
-
#mobile_phone ⇒ Object
Convenience accessor for the contact’s mobile phone.
-
#save ⇒ Object
Update the contact’s data on the Signal platform.
- #save_additional_info ⇒ Object
Methods included from ApiMock
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
#attributes ⇒ Object
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_address ⇒ Object
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_phone ⇒ Object
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 |
#save ⇒ Object
Update the contact’s data on the Signal platform.
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_info ⇒ Object
9 10 11 |
# File 'lib/signal_api/mocks/contact.rb', line 9 def save_additional_info { :attributes => @attributes } end |