Class: CreateSend::Subscriber
- Inherits:
-
Object
- Object
- 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.
Class Method Summary collapse
-
.add(list_id, email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders = false) ⇒ Object
Adds a subscriber to a subscriber list.
-
.get(list_id, email_address) ⇒ Object
Gets a subscriber by list ID and email address.
-
.import(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(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, restart_subscription_based_autoresponders = false) ⇒ Object
Updates any aspect of a subscriber, including email address, name, and custom field data if supplied.
Constructor Details
#initialize(list_id, email_address) ⇒ Subscriber
Returns a new instance of Subscriber.
10 11 12 13 |
# File 'lib/createsend/subscriber.rb', line 10 def initialize(list_id, email_address) @list_id = list_id @email_address = email_address end |
Instance Attribute Details
#email_address ⇒ Object (readonly)
Returns the value of attribute email_address.
8 9 10 |
# File 'lib/createsend/subscriber.rb', line 8 def email_address @email_address end |
#list_id ⇒ Object (readonly)
Returns the value of attribute list_id.
7 8 9 |
# File 'lib/createsend/subscriber.rb', line 7 def list_id @list_id end |
Class Method Details
.add(list_id, email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders = false) ⇒ Object
Adds a subscriber to a subscriber list.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/createsend/subscriber.rb', line 23 def self.add(list_id, email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders=false) = { :body => { :EmailAddress => email_address, :Name => name, :CustomFields => custom_fields, :Resubscribe => resubscribe, :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json } response = CreateSend.post "/subscribers/#{list_id}.json", response.parsed_response end |
.get(list_id, email_address) ⇒ Object
Gets a subscriber by list ID and email address.
16 17 18 19 20 |
# File 'lib/createsend/subscriber.rb', line 16 def self.get(list_id, email_address) = { :query => { :email => email_address } } response = CreateSend.get "/subscribers/#{list_id}.json", Hashie::Mash.new(response) end |
.import(list_id, subscribers, resubscribe, queue_subscription_based_autoresponders = false, restart_subscription_based_autoresponders = false) ⇒ Object
Imports subscribers into a subscriber list.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/createsend/subscriber.rb', line 37 def self.import(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 response = CreateSend.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 end end Hashie::Mash.new(response) end |
Instance Method Details
#delete ⇒ Object
Moves this subscriber to the Deleted state in the associated list.
98 99 100 101 |
# File 'lib/createsend/subscriber.rb', line 98 def delete = { :query => { :email => @email_address } } CreateSend.delete "/subscribers/#{@list_id}.json", end |
#history ⇒ Object
Gets the historical record of this subscriber’s trackable actions.
91 92 93 94 95 |
# File 'lib/createsend/subscriber.rb', line 91 def history = { :query => { :email => @email_address } } response = CreateSend.get "/subscribers/#{@list_id}/history.json", response.map{|item| Hashie::Mash.new(item)} end |
#unsubscribe ⇒ Object
Unsubscribes this subscriber from the associated list.
84 85 86 87 88 |
# File 'lib/createsend/subscriber.rb', line 84 def unsubscribe = { :body => { :EmailAddress => @email_address }.to_json } CreateSend.post "/subscribers/#{@list_id}/unsubscribe.json", end |
#update(new_email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders = false) ⇒ Object
Updates any aspect of a subscriber, including email address, name, and custom field data if supplied.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/createsend/subscriber.rb', line 67 def update(new_email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders=false) = { :query => { :email => @email_address }, :body => { :EmailAddress => new_email_address, :Name => name, :CustomFields => custom_fields, :Resubscribe => resubscribe, :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json } CreateSend.put "/subscribers/#{@list_id}.json", # Update @email_address, so this object can continue to be used reliably @email_address = new_email_address end |