Class: RBET::Subscriber

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

Overview

usage:

# get an existing subscriber
subscriber = Subscriber.load!('[email protected]')
=> ET::Subscriber

# subscribe a new user to an existing list
subscriber = Subscriber.add('[email protected]',list)
=> ET::Subscriber

Instance Attribute Summary collapse

Attributes inherited from Client

#headers, #password, #username

Instance Method Summary collapse

Methods inherited from Client

#live?, #send

Methods included from Renderable

#render_template, #set_template_path, #template_path

Constructor Details

#initialize(username, password, options = {}) ⇒ Subscriber

Returns a new instance of Subscriber.



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

def initialize(username,password,options={})
  super
  @attrs = {}
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



42
43
44
# File 'lib/rbet/subscriber.rb', line 42

def attrs
  @attrs
end

#emailObject (readonly)

Returns the value of attribute email.



43
44
45
# File 'lib/rbet/subscriber.rb', line 43

def email
  @email
end

#statusObject (readonly)

Returns the value of attribute status.



43
44
45
# File 'lib/rbet/subscriber.rb', line 43

def status
  @status
end

Instance Method Details

#add(email, listid, attributes = {}) ⇒ Object

desc:

add this user as a new subscriber to the list, with a set of attributes

params:

listid: id of the e-mail list to subscribe this user to
email: E-mail address of subscriber


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rbet/subscriber.rb', line 84

def add( email, listid, attributes ={} )
  @email = email
  @subscriber_listid = listid
  @attributes = attributes
  response = send do|io|
    io << render_template('subscriber_add')
  end
  Error.check_response_error(response)
  doc = Hpricot.XML(response.read_body)
  doc.at("subscriber_description").inner_html.to_i
end

#delete(subscriberid, email, listid, attributes = {}) ⇒ Object

desc:

delete this user as a new subscriber to the list, or completely from ET

params:

listid: id of the e-mail list to unsubscribe this user from
email: E-mail address of subscriber
subscriberid: id for the subscriber to delete COMPLETELY


121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rbet/subscriber.rb', line 121

def delete(subscriberid, email, listid, attributes ={} )
  @email = email
  @subscriber_listid = listid
  @subscriberid = subscriberid

  puts render_template('subscriber_delete')
  response = send do|io|
    io << render_template('subscriber_delete')
  end
  Error.check_response_error(response)
  doc = Hpricot.XML(response.read_body)
  doc.at("subscriber_info").inner_html
end

#load!(email) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/rbet/subscriber.rb', line 50

def load!(email)
  @email = email
  response = send do|io|
    io << render_template('subscriber_retrieve')
  end
  Error.check_response_error(response)
  load_response(response.read_body)
end

#update(subscriberid, email, listid, attributes = {}) ⇒ Object

desc:

update this a subscriber

params:

listid: id of the e-mail list to subscribe this user to
email: E-mail address of subscriber
subscriberid: id for the subscriber to update


102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rbet/subscriber.rb', line 102

def update(subscriberid, email, listid, attributes ={} )
  @email = email
  @listid = listid
  @subscriberid = subscriberid
  @attributes = attributes
  response = send do|io|
    io << render_template('subscriber_update')
  end
  Error.check_response_error(response)
  doc = Hpricot.XML(response.read_body)
  doc.at("subscriber_description").inner_html.to_i
end