Class: RBET::List

Inherits:
Client show all
Defined in:
lib/rbet/list.rb

Overview

Subscriber list usage:

# create a new subscriber list
super_list = List.add 'Super list', :type => :public
=> ET::List

# retrieve the list by name
basic_list = List.retrieve_by_name('My Super List')
=> ET::List

# retrieve by id
basic_list = List.retrieve_by_id(12322)
=> ET::List

# send an email to a list
list_id = 147000
email_template_id = 9999123
list = ET::List.new('username', 'password')
list.send_email(list_id, email_template_id, {:first_name => 'John', :last_name => 'Wayne'})

Instance Attribute Summary collapse

Attributes inherited from Client

#headers, #password, #username

Instance Method Summary collapse

Methods inherited from Client

#live?, #send, #status

Methods included from Renderable

#render_template, #set_template_path, #template_path

Constructor Details

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

Returns a new instance of List.



51
52
53
54
# File 'lib/rbet/list.rb', line 51

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



49
50
51
# File 'lib/rbet/list.rb', line 49

def attributes
  @attributes
end

Instance Method Details

#add(name, type = 'private') ⇒ Object

defaults type to private if not private or public returns the new list id



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rbet/list.rb', line 94

def add(name, type='private')
  @list_name = name
  @list_type = type
  @list_type = 'private' if type != 'public' or type != 'private'
  response = send do|io|
    io << render_template('list_add')
  end
  Error.check_response_error(response)
  doc = Hpricot.XML( response.read_body )
  doc.at("list_description").inner_html.to_i
end

#allObject

get all the lists



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rbet/list.rb', line 57

def all
  response = send do|io|
    io << render_template('list_list_all')
  end
  Error.check_response_error(response)
  doc = Hpricot.XML( response.read_body )
  listids = []
  (doc/"listid").each do|listid|
    listids << listid.inner_html.to_i
  end
  listids
end

#retrieve_by_id(id) ⇒ Object

returns a new list object by id



71
72
73
74
75
76
77
78
79
# File 'lib/rbet/list.rb', line 71

def retrieve_by_id( id )
  @search_type = "listid"
  @search_value = id
  response = send do|io|
    io << render_template('list_retrieve')
  end
  Error.check_response_error(response)
  load_list( response.read_body )
end

#retrieve_by_name(name) ⇒ Object

returns a new list object by list name



82
83
84
85
86
87
88
89
90
# File 'lib/rbet/list.rb', line 82

def retrieve_by_name( name )
  @search_type = "listname"
  @search_value = name
  response = send do|io|
    io << render_template('list_retrieve')
  end
  Error.check_response_error(response)
  load_list( response.read_body )
end

#send_email(list_id, email_id, attrs = {}) ⇒ Object

Sends an email to the list specified



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

def send_email(list_id, email_id, attrs = {})
  defaults = {:from_name => '', :from_email => '', :additional => '',
              :multipart_mime => true, :track_links => true, :send_date => 'immediate', :send_time => ''}
  @list_id, @email_id = list_id, email_id
  @extra_attrs = defaults.merge(attrs)
  response = send do|io|
    io << render_template('list_send_email')
  end
  Error.check_response_error(response)
  #puts "Response Body: #{response.read_body} \n"
  doc = Hpricot.XML( response.read_body )
  doc.at("job_description").inner_html.to_i rescue nil
end

#subscriber_emails(list_id) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/rbet/list.rb', line 106

def subscriber_emails(list_id)
  @list_id = list_id
  response = send do|io|
    io << render_template('list_retrieve_subscribers')
  end
  Error.check_response_error(response)
  body = response.read_body
  doc = Hpricot.XML( body )
  emails = []
  (doc/"Email__Address").each do |row|
    emails << row.inner_html
  end
  emails
end