Class: CreateSend::Subscriber
- Inherits:
-
CreateSend
- Object
- CreateSend
- CreateSend::Subscriber
- Defined in:
- lib/createsend/subscriber.rb
Overview
Represents a subscriber and associated functionality.
Instance Attribute Summary collapse
-
#email_address ⇒ Object
readonly
Returns the value of attribute email_address.
-
#list_id ⇒ Object
readonly
Returns the value of attribute list_id.
Attributes inherited from CreateSend
Class Method Summary collapse
-
.add(auth, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders = false, mobile_number = nil, consent_to_send_sms = nil) ⇒ Object
Adds a subscriber to a subscriber list.
-
.get(auth, list_id, email_address, include_tracking_preference = false) ⇒ Object
Gets a subscriber by list ID and email address.
-
.import(auth, list_id, subscribers, resubscribe, queue_subscription_based_autoresponders = false, restart_subscription_based_autoresponders = false) ⇒ Object
Imports subscribers into a subscriber list.
Instance Method Summary collapse
-
#delete ⇒ Object
Moves this subscriber to the Deleted state in the associated list.
-
#history ⇒ Object
Gets the historical record of this subscriber’s trackable actions.
-
#initialize(auth, list_id, email_address) ⇒ Subscriber
constructor
A new instance of Subscriber.
-
#unsubscribe ⇒ Object
Unsubscribes this subscriber from the associated list.
-
#update(new_email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders = false, mobile_number = nil, consent_to_send_sms = nil) ⇒ Object
Updates any aspect of a subscriber, including email address, name, and custom field data if supplied.
Methods inherited from CreateSend
#add_auth_details_to_options, #administrators, #auth, authorize_url, #billing_details, #clients, #countries, exchange_token, #external_session_url, #get, #get_primary_contact, #handle_response, #post, #put, refresh_access_token, #refresh_token, #set_primary_contact, #systemdate, #timezones, user_agent
Constructor Details
#initialize(auth, list_id, email_address) ⇒ Subscriber
Returns a new instance of Subscriber.
7 8 9 10 11 |
# File 'lib/createsend/subscriber.rb', line 7 def initialize(auth, list_id, email_address) @list_id = list_id @email_address = email_address super end |
Instance Attribute Details
#email_address ⇒ Object (readonly)
Returns the value of attribute email_address.
5 6 7 |
# File 'lib/createsend/subscriber.rb', line 5 def email_address @email_address end |
#list_id ⇒ Object (readonly)
Returns the value of attribute list_id.
4 5 6 |
# File 'lib/createsend/subscriber.rb', line 4 def list_id @list_id end |
Class Method Details
.add(auth, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders = false, mobile_number = nil, consent_to_send_sms = nil) ⇒ Object
Adds a subscriber to a subscriber list.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/createsend/subscriber.rb', line 25 def self.add(auth, list_id, email_address, name, custom_fields, resubscribe, , restart_subscription_based_autoresponders=false, mobile_number=nil, =nil) = { :body => { :EmailAddress => email_address, :Name => name, :MobileNumber => mobile_number, :CustomFields => custom_fields, :Resubscribe => resubscribe, :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders, :ConsentToTrack => , :ConsentToSendSms => }.to_json } cs = CreateSend.new auth response = cs.post "/subscribers/#{list_id}.json", response.parsed_response end |
.get(auth, list_id, email_address, include_tracking_preference = false) ⇒ Object
Gets a subscriber by list ID and email address.
14 15 16 17 18 19 20 21 22 |
# File 'lib/createsend/subscriber.rb', line 14 def self.get(auth, list_id, email_address, include_tracking_preference=false) = { :query => { :email => email_address, :includetrackingpreference => include_tracking_preference } } cs = CreateSend.new auth response = cs.get "/subscribers/#{list_id}.json", Hashie::Mash.new(response) end |
.import(auth, list_id, subscribers, resubscribe, queue_subscription_based_autoresponders = false, restart_subscription_based_autoresponders = false) ⇒ Object
Imports subscribers into a subscriber list.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/createsend/subscriber.rb', line 43 def self.import(auth, list_id, subscribers, resubscribe, queue_subscription_based_autoresponders=false, restart_subscription_based_autoresponders=false) = { :body => { :Subscribers => subscribers, :Resubscribe => resubscribe, :QueueSubscriptionBasedAutoresponders => queue_subscription_based_autoresponders, :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json } begin cs = CreateSend.new auth response = cs.post( "/subscribers/#{list_id}/import.json", ) rescue BadRequest => br # Subscriber import will throw BadRequest if some subscribers are not # imported successfully. If this occurs, we want to return the # ResultData property of the BadRequest exception (which is of the # same "form" as the response we would receive upon a completely # successful import). if br.data.ResultData return br.data.ResultData else raise br # Just raise other Bad Request errors end end Hashie::Mash.new(response) end |
Instance Method Details
#delete ⇒ Object
Moves this subscriber to the Deleted state in the associated list.
108 109 110 111 |
# File 'lib/createsend/subscriber.rb', line 108 def delete = { :query => { :email => @email_address } } super "/subscribers/#{@list_id}.json", end |
#history ⇒ Object
Gets the historical record of this subscriber’s trackable actions.
101 102 103 104 105 |
# File 'lib/createsend/subscriber.rb', line 101 def history = { :query => { :email => @email_address } } response = cs_get "/subscribers/#{@list_id}/history.json", response.map{|item| Hashie::Mash.new(item)} end |
#unsubscribe ⇒ Object
Unsubscribes this subscriber from the associated list.
94 95 96 97 98 |
# File 'lib/createsend/subscriber.rb', line 94 def unsubscribe = { :body => { :EmailAddress => @email_address }.to_json } post "/subscribers/#{@list_id}/unsubscribe.json", end |
#update(new_email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders = false, mobile_number = nil, consent_to_send_sms = nil) ⇒ Object
Updates any aspect of a subscriber, including email address, name, and custom field data if supplied.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/createsend/subscriber.rb', line 74 def update(new_email_address, name, custom_fields, resubscribe, , restart_subscription_based_autoresponders=false, mobile_number=nil, =nil) = { :query => { :email => @email_address }, :body => { :EmailAddress => new_email_address, :Name => name, :MobileNumber => mobile_number, :CustomFields => custom_fields, :Resubscribe => resubscribe, :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders, :ConsentToTrack => , :ConsentToSendSms => }.to_json } put "/subscribers/#{@list_id}.json", # Update @email_address, so this object can continue to be used reliably @email_address = new_email_address end |