Files
davideisinger.com/content/elsewhere/introducing-email-labs-client/index.md
2023-10-22 23:52:56 -04:00

1.3 KiB

title, date, draft, needs_review, canonical_url
title date draft needs_review canonical_url
Introducing: EmailLabsClient 2008-07-31T00:00:00+00:00 false true https://www.viget.com/articles/introducing-email-labs-client/

On my latest project, the client is using EmailLabs to manage their mailing lists. To simplify interaction with their system, we've created EmailLabsClient, a small Ruby client for the EmailLabs API. The core of the program is the send_request method:

def self.send_request(request_type, activity) xml = Builder::XmlMarkup.new :target => (input = '') xml.instruct! xml.DATASET do xml.SITE_ID SITE_ID yield xml end Net::HTTP.post_form(URI.parse(ENDPOINT), :type => request_type, :activity => activity, :input => input) end 

Then you can make API requests like this:

def self.subscribe_user(mailing_list, email_address) send_request('record', 'add') do |body| body.MLID mailing_list body.DATA email_address, :type => 'email' end end 

If you find yourself needing to work with an EmailLabs mailing list, check it out. At the very least, you should get a decent idea of how to interact with their API. It's up on GitHub, so if you add any functionality, send those patches our way.