Introducing: EmailLabsClient

David Eisinger, Development Director

Article Category: #Code

Posted on

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.

David Eisinger

David is Viget's managing development director. From our Durham, NC, office, he builds high-quality, forward-thinking software for PUMA, the World Wildlife Fund, NFLPA, and many others.

More articles by David

Related Articles