index.md (1389B)
1 --- 2 title: "Introducing: EmailLabsClient" 3 date: 2008-07-31T00:00:00+00:00 4 draft: false 5 canonical_url: https://www.viget.com/articles/introducing-email-labs-client/ 6 --- 7 8 On my latest project, the client is using 9 [EmailLabs](http://www.emaillabs.com/) to manage their mailing lists. To 10 simplify interaction with their system, we've created 11 [EmailLabsClient](https://github.com/vigetlabs/email_labs_client/tree/master), 12 a small Ruby client for the EmailLabs API. The core of the program is 13 the `send_request` method: 14 15 ```ruby 16 def self.send_request(request_type, activity) 17 xml = Builder::XmlMarkup.new :target => (input = '') 18 19 xml.instruct! 20 21 xml.DATASET do 22 xml.SITE_ID SITE_ID 23 yield xml 24 end 25 26 Net::HTTP.post_form( 27 URI.parse(ENDPOINT), 28 :type => request_type, 29 :activity => activity, 30 :input => input 31 ) 32 end 33 ``` 34 35 Then you can make API requests like this: 36 37 ```ruby 38 def self.subscribe_user(mailing_list, email_address) 39 send_request('record', 'add') do |body| 40 body.MLID mailing_list 41 body.DATA email_address, :type => 'email' 42 end 43 end 44 ``` 45 46 If you find yourself needing to work with an EmailLabs mailing list, 47 check it out. At the very least, you should get a decent idea of how to 48 interact with their API. It's up on 49 [GitHub](https://github.com/vigetlabs/email_labs_client/tree/master), so 50 if you add any functionality, send those patches our way.