Class: GetResponse::Contact
- Inherits:
-
Object
- Object
- GetResponse::Contact
- Defined in:
- lib/get_response/contact.rb
Overview
GetResponse contact
Instance Attribute Summary collapse
-
#campaign ⇒ Object
Returns the value of attribute campaign.
-
#created_on ⇒ Object
Returns the value of attribute created_on.
-
#customs ⇒ Object
Get list of custom attributes.
-
#cycle_day ⇒ Object
Returns the value of attribute cycle_day.
-
#deleted_on ⇒ Object
Returns the value of attribute deleted_on.
-
#duplicated ⇒ Object
Returns the value of attribute duplicated.
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reason ⇒ Object
Returns the value of attribute reason.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns setted attributes as Hash.
-
#destroy ⇒ Object
Delete contact.
-
#geoip ⇒ Object
Get contact geo location based on IP address from which the subscription was processed.
-
#initialize(params, connection) ⇒ Contact
constructor
A new instance of Contact.
-
#move(new_campaign_id) ⇒ Object
Move contact from one campaign (current) to another.
-
#opens ⇒ Object
List dates when the messages were opened by contact.
-
#save ⇒ Object
Save contact object.
-
#set_cycle(value) ⇒ Object
Place a contact on a desired day of the follow-up cycle or deactivate a contact.
-
#update(new_attrs) ⇒ Object
Update contact with passed attributes set.
Constructor Details
#initialize(params, connection) ⇒ Contact
Returns a new instance of Contact.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/get_response/contact.rb', line 9 def initialize(params, connection) @campaign = params["campaign"] @name = params["name"] @email = params["email"] @cycle_day = params["cycle_day"] @ip = params["ip"] @customs = parse_customs(params["customs"]) @id = params["id"] @created_on = params["created_on"] @deleted_on = params["deleted_on"] @reason = params["reason"] @connection = connection @duplicated = false end |
Instance Attribute Details
#campaign ⇒ Object
Returns the value of attribute campaign.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def campaign @campaign end |
#created_on ⇒ Object
Returns the value of attribute created_on.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def created_on @created_on end |
#customs ⇒ Object
Get list of custom attributes. It performs additional API request to fetch attributes. By default new contacts has en empty custom attributes list.
- returns
-
Hash
117 118 119 |
# File 'lib/get_response/contact.rb', line 117 def customs @customs end |
#cycle_day ⇒ Object
Returns the value of attribute cycle_day.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def cycle_day @cycle_day end |
#deleted_on ⇒ Object
Returns the value of attribute deleted_on.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def deleted_on @deleted_on end |
#duplicated ⇒ Object
Returns the value of attribute duplicated.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def duplicated @duplicated end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def email @email end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/get_response/contact.rb', line 6 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def name @name end |
#reason ⇒ Object
Returns the value of attribute reason.
5 6 7 |
# File 'lib/get_response/contact.rb', line 5 def reason @reason end |
Instance Method Details
#attributes ⇒ Object
Returns setted attributes as Hash.
- returns
-
Hash
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/get_response/contact.rb', line 39 def attributes attrs = { "campaign" => @campaign, "email" => @email } attrs["ip"] = @ip if @ip attrs["cycle_day"] = @cycle_day if @cycle_day attrs["customs"] = @customs if @customs attrs["name"] = @name if @name attrs end |
#destroy ⇒ Object
Delete contact. If deleting contact was successfull method returns true
. If contact object hasn’t id
attribute GetResponseError
exception is raised. Exception is raised when try to delete already deleted contact.
- returns
-
Boolean
59 60 61 62 63 64 |
# File 'lib/get_response/contact.rb', line 59 def destroy raise GetResponse::GetResponseError.new("Can't delete contact without id") unless @id resp = @connection.send_request("delete_contact", { "contact" => @id }) resp["result"]["deleted"].to_i == 1 end |
#geoip ⇒ Object
Get contact geo location based on IP address from which the subscription was processed.
- returns
-
Hash
96 97 98 99 |
# File 'lib/get_response/contact.rb', line 96 def geoip param = { "contact" => @id } @connection.send_request("get_contact_geoip", param)["result"] end |
#move(new_campaign_id) ⇒ Object
Move contact from one campaign (current) to another. If move contact fails (for example: no campaign with passed id) GetResponseError
exception is raised, otherwise method returns true
.
- new_campaign_id
-
String - identifier of new camapign
- returns
-
Boolean
86 87 88 89 90 |
# File 'lib/get_response/contact.rb', line 86 def move(new_campaign_id) param = { "contact" => @id, "campaign" => new_campaign_id } result = @connection.send_request("move_contact", param) result["result"]["updated"].to_i == 1 end |
#opens ⇒ Object
List dates when the messages were opened by contact. If a contact opened the same message multiple times, only the oldest date is listed.
- returns
-
Hash
134 135 136 137 |
# File 'lib/get_response/contact.rb', line 134 def opens param = {"contact" => @id} @connection.send_request("get_contact_opens", param)["result"] end |
#save ⇒ Object
Save contact object. When object can’t be saved than GetResponseError
is raised, otherwise returns true
.
- returns
-
Boolean
29 30 31 32 33 |
# File 'lib/get_response/contact.rb', line 29 def save result = @connection.send_request(:add_contact, self.attributes) self.duplicated = true unless result["result"]["duplicated"].nil? result["error"].nil? end |
#set_cycle(value) ⇒ Object
Place a contact on a desired day of the follow-up cycle or deactivate a contact. Method raises a GetResponseError
exception when fails otherwise returns true.
- value
-
String || Fixnum
- returns
-
true
107 108 109 110 |
# File 'lib/get_response/contact.rb', line 107 def set_cycle(value) param = { "contact" => @id, "cycle_day" => value } @connection.send_request("set_contact_cycle", param)["result"]["updated"].to_i == 1 end |
#update(new_attrs) ⇒ Object
Update contact with passed attributes set. When object can’t be saved than GetResponseError
is raised, otherwise returns true
.
- net_attrs
-
Hash
71 72 73 74 75 76 77 |
# File 'lib/get_response/contact.rb', line 71 def update(new_attrs) # Don't save immediately changes @lazy_save = true new_attrs.each_pair { |key, value| self.send(key + "=", value) } self.save end |