Skip to content

Instantly share code, notes, and snippets.

@loe
Created February 27, 2014 18:34
Show Gist options
  • Save loe/9256190 to your computer and use it in GitHub Desktop.
Save loe/9256190 to your computer and use it in GitHub Desktop.
require 'httparty'
class LitmusTest
include HTTParty
base_uri('https://api.litmus.com/v2')
basic_auth('<YOUR API KEY>', 'x')
headers({'Content-Type' => 'application/json'})
def self.create(subject, body)
post('/emails', :body => {:email => {:name => "#{subject} @ #{Time.now.to_s(:short)}", :subject => subject, :body => body, :client_ids => self.client_ids}}.to_json)
end
# Cache the client_id list per test suite.
def self.client_ids
@@client_ids ||= get('/emails/clients')['clients'].map { |client| client['id'] }
end
end
def write_output_to_file(subject, body)
if ENV['LITMUS']
puts "Posting email to Litmus:"
test = LitmusTest.create(subject, body)
puts "Created Litmus Test: #{test.body}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment