Class: EROI::Client
- Inherits:
-
Object
- Object
- EROI::Client
- Defined in:
- lib/eroi/client.rb
Instance Attribute Summary collapse
-
#api_password ⇒ Object
readonly
Returns the value of attribute api_password.
-
#user_token ⇒ Object
readonly
Returns the value of attribute user_token.
Class Method Summary collapse
Instance Method Summary collapse
- #add_contact(fields) ⇒ Object (also: #update_contact)
- #add_contacts(records) ⇒ Object (also: #update_contacts)
- #change_contact_email(current_email, new_email) ⇒ Object
- #contact(email, options = {}) ⇒ Object
- #define_list(list, emails) ⇒ Object
-
#initialize(user_token, api_password) ⇒ Client
constructor
A new instance of Client.
- #remove_contact(email) ⇒ Object
-
#send_list_edition(list, edition, who) ⇒ Object
Sends a list edition to specified broadcast.
Constructor Details
#initialize(user_token, api_password) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/eroi/client.rb', line 14 def initialize(user_token, api_password) @user_token = user_token @api_password = api_password end |
Instance Attribute Details
#api_password ⇒ Object (readonly)
Returns the value of attribute api_password.
7 8 9 |
# File 'lib/eroi/client.rb', line 7 def api_password @api_password end |
#user_token ⇒ Object (readonly)
Returns the value of attribute user_token.
7 8 9 |
# File 'lib/eroi/client.rb', line 7 def user_token @user_token end |
Class Method Details
.api_available? ⇒ Boolean
9 10 11 12 |
# File 'lib/eroi/client.rb', line 9 def self.api_available? Request::Post.api_available? && Request::Get.api_available? end |
Instance Method Details
#add_contact(fields) ⇒ Object Also known as: update_contact
24 25 26 |
# File 'lib/eroi/client.rb', line 24 def add_contact(fields) Request::Post.send(self, build_contact_record(fields)) end |
#add_contacts(records) ⇒ Object Also known as: update_contacts
30 31 32 33 |
# File 'lib/eroi/client.rb', line 30 def add_contacts(records) records = records.collect { |r| build_contact_record(r) } Request::Post.send(self, records) end |
#change_contact_email(current_email, new_email) ⇒ Object
37 38 39 40 41 |
# File 'lib/eroi/client.rb', line 37 def change_contact_email(current_email, new_email) Request::Post.send(self, build_contact_record( :email => current_email, :change_email => new_email)) end |
#contact(email, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/eroi/client.rb', line 19 def contact(email, = {}) Request::Get.send(self, { :contact => email }.merge()) end |
#define_list(list, emails) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/eroi/client.rb', line 49 def define_list(list, emails) xml = Builder::XmlMarkup.new xml.tag!('DefineMailingList', 'list' => list) do |x| emails.each do |email| x.tag!('Email', email) end end Request::Post.send(self, xml) end |
#remove_contact(email) ⇒ Object
43 44 45 46 47 |
# File 'lib/eroi/client.rb', line 43 def remove_contact(email) Request::Post.send(self, build_contact_record( :email => email, :clear_record => 1 )) end |
#send_list_edition(list, edition, who) ⇒ Object
Sends a list edition to specified broadcast.
Who can consist of the following:
* Broadcast All - sends to all members of the list, regardless of whether they have already received this edition
* Broadcast Unsent - sends to all members of the list who have not yet received this edition
* Broadcast ### - sends to ### random recipients who have not yet received this edition
* A comma seperated list of emails.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/eroi/client.rb', line 67 def send_list_edition(list, edition, who) xml = Builder::XmlMarkup.new xml.tag!( 'Send', ((who.is_a?(String)) ? [ who ] : who).join(','), 'List' => list, 'Edition' => edition) Request::Post.send(self, xml) end |