Class: EmailDirect::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/emaildirect/subscriber.rb

Overview

Represents a subscriber and associated functionality

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Subscriber

Returns a new instance of Subscriber.



46
47
48
# File 'lib/emaildirect/subscriber.rb', line 46

def initialize(email)
  @email = email
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



44
45
46
# File 'lib/emaildirect/subscriber.rb', line 44

def email
  @email
end

Class Method Details

.active(options = {}) ⇒ Object



8
9
10
11
# File 'lib/emaildirect/subscriber.rb', line 8

def active(options = {})
  response = EmailDirect.get '/Subscribers', :query => options
  Hashie::Mash.new(response)
end

.bounces(options = {}) ⇒ Object



18
19
20
21
# File 'lib/emaildirect/subscriber.rb', line 18

def bounces(options = {})
  response = EmailDirect.get '/Subscribers/Bounces', :query => options
  Hashie::Mash.new(response)
end

.complaints(options = {}) ⇒ Object



23
24
25
26
# File 'lib/emaildirect/subscriber.rb', line 23

def complaints(options = {})
  response = EmailDirect.get '/Subscribers/Complaints', :query => options
  Hashie::Mash.new(response)
end

.create(email, options = {}) ⇒ Object



28
29
30
31
32
33
# File 'lib/emaildirect/subscriber.rb', line 28

def create(email, options = {})
  options.merge! :EmailAddress => email
  self.convert_custom_fields options
  response = EmailDirect.post '/Subscribers', :body => options.to_json
  Hashie::Mash.new(response)
end

.removes(options = {}) ⇒ Object



13
14
15
16
# File 'lib/emaildirect/subscriber.rb', line 13

def removes(options = {})
  response = EmailDirect.get '/Subscribers/Removes', :query => options
  Hashie::Mash.new(response)
end

Instance Method Details

#change_email(new_email) ⇒ Object



91
92
93
94
95
# File 'lib/emaildirect/subscriber.rb', line 91

def change_email(new_email)
  options = { :EmailAddress => new_email }
  response = EmailDirect.post uri_for('ChangeEmail'), :body => options.to_json
  Hashie::Mash.new(response)
end

#deleteObject



80
81
82
83
# File 'lib/emaildirect/subscriber.rb', line 80

def delete
  response = EmailDirect.delete uri_for, {}
  Hashie::Mash.new(response)
end

#detailsObject



50
51
52
53
# File 'lib/emaildirect/subscriber.rb', line 50

def details
  response = get
  Hashie::Mash.new(response)
end

#historyObject



60
61
62
63
# File 'lib/emaildirect/subscriber.rb', line 60

def history
  response = get 'History'
  Hashie::Mash.new(response)
end

#propertiesObject



55
56
57
58
# File 'lib/emaildirect/subscriber.rb', line 55

def properties
  response = get 'Properties'
  Hashie::Mash.new(response)
end

#removeObject



85
86
87
88
89
# File 'lib/emaildirect/subscriber.rb', line 85

def remove
  options = { :EmailAddress => email }
  response = EmailDirect.post '/Subscribers/Remove', :body => options.to_json
  Hashie::Mash.new(response)
end

#update(options) ⇒ Object



65
66
67
68
69
70
# File 'lib/emaildirect/subscriber.rb', line 65

def update(options)
  options.merge! :EmailAddress => email
  self.class.convert_custom_fields options
  response = EmailDirect.put uri_for, :body => options.to_json
  Hashie::Mash.new(response)
end

#update_custom_field(attribute, value) ⇒ Object



72
73
74
# File 'lib/emaildirect/subscriber.rb', line 72

def update_custom_field(attribute, value)
  self.class.create email, :CustomFields => [ { :FieldName => attribute, :Value => value } ]
end

#update_custom_fields(attributes) ⇒ Object



76
77
78
# File 'lib/emaildirect/subscriber.rb', line 76

def update_custom_fields(attributes)
  self.class.create email, :CustomFields => attributes
end