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



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rbet/subscriber.rb', line 84

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

  data = ""
  xml = Builder::XmlMarkup.new(:target => data, :indent => 2)
  xml.system do
    xml.system_name "subscriber"
    xml.action "add"
    xml.search_type "listid"
    xml.search_value @subscriber_listid
    xml.search_value2 nil
    xml.values do
      xml.email__address @email
      xml.status "active"
      @attributes.each do|name,value|
        eval "xml.#{name} '#{(value.is_a?(Array)) ? value.join(',') : value}'"
      end
    end

  end

  response = send do|io|
    # io << render_template('subscriber_add')
    io << data
  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


141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rbet/subscriber.rb', line 141

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

  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


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

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