-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module CreateSend | ||
module Transactional | ||
class SmartEmail < CreateSend | ||
attr_reader :smart_email_id | ||
|
||
def self.list(auth, options = nil) | ||
cs = CreateSend.new auth | ||
response = cs.get "/transactional/smartemail", :query => options | ||
response.map{|item| Hashie::Mash.new(item)} | ||
end | ||
|
||
def initialize(auth, smart_email_id) | ||
@auth = auth | ||
@smart_email_id = smart_email_id | ||
super | ||
end | ||
|
||
def details | ||
response = get "/transactional/smartemail/#{@smart_email_id}" | ||
Hashie::Mash.new(response) | ||
end | ||
|
||
def send(options) | ||
response = post "/transactional/smartemail/#{@smart_email_id}/send", { :body => options.to_json } | ||
response.map{|item| Hashie::Mash.new(item)} | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"SmartEmailID": "bb4a6ebb-663d-42a0-bdbe-60512cf30a01", | ||
"Name": "Reset Password", | ||
"CreatedAt": "2015-03-31T16:06:35+11:00", | ||
"Status": "active", | ||
"Properties": { | ||
"From": "\"Team\" <[email protected]>", | ||
"ReplyTo": "[email protected]", | ||
"Subject": "[username], your password has been reset!", | ||
"Content": { | ||
"HTML": "Content managed in Email Builder", | ||
"Text": "Content managed in Email Builder", | ||
"EmailVariables": [ | ||
"username", | ||
"reset_token" | ||
], | ||
"InlineCss": true | ||
}, | ||
"TextPreviewUrl": "https://philoye.devcreatesend.com/t/r-9A7A28EE76054977/T", | ||
"HtmlPreviewUrl": "https://philoye.devcreatesend.com/t/r-9A7A28EE76054977/" | ||
}, | ||
"AddRecipientsToList": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"ID": "1e654df2-f484-11e4-970c-6c4008bc7468", | ||
"Name": "Welcome email", | ||
"CreatedAt": "2015-05-15T16:09:19-05:00", | ||
"Status": "Active" | ||
}, | ||
{ | ||
"ID": "21dab350-f484-11e4-ad38-6c4008bc7468", | ||
"Name": "Order shipped", | ||
"CreatedAt": "2015-05-15T13:29:49-05:00", | ||
"Status": "Active" | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require File.dirname(__FILE__) + '/helper' | ||
|
||
class TransactionalSmartEmailTest < Test::Unit::TestCase | ||
multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do | ||
setup do | ||
@client_id = "87y8d7qyw8d7yq8w7ydwqwd" | ||
@smart_email_id = "bcf40510-f968-11e4-ab73-bf67677cc1f4" | ||
@email = CreateSend::Transactional::SmartEmail.new @auth, @smart_email_id | ||
end | ||
|
||
should "get the list of smart emails" do | ||
stub_get(@auth, "transactional/smartemail", "tx_smartemails.json") | ||
response = CreateSend::Transactional::SmartEmail.list(@auth) | ||
response.length.should == 2 | ||
response[0].ID.should == "1e654df2-f484-11e4-970c-6c4008bc7468" | ||
response[0].Name.should == "Welcome email" | ||
response[0].Status.should == "Active" | ||
end | ||
|
||
should "get the list of active smart emails using a client ID" do | ||
stub_get(@auth, "transactional/smartemail?status=active&client=#{@client_id}", "tx_smartemails.json") | ||
response = CreateSend::Transactional::SmartEmail.list(@auth, { :client => @client_id, :status => 'active'} ) | ||
response.length.should == 2 | ||
response[0].ID.should == "1e654df2-f484-11e4-970c-6c4008bc7468" | ||
response[0].Name.should == "Welcome email" | ||
response[0].Status.should == "Active" | ||
end | ||
|
||
should "get the details of smart email" do | ||
stub_get(@auth, "transactional/smartemail/#{@smart_email_id}", "tx_smartemail_details.json") | ||
response = CreateSend::Transactional::SmartEmail.new(@auth, @smart_email_id).details | ||
response.Name.should == "Reset Password" | ||
response.Status.should == "active" | ||
response.Properties.ReplyTo.should == "[email protected]" | ||
end | ||
|
||
should "send smart email to one recipient" do | ||
stub_post(@auth, "transactional/smartemail/#{@smart_email_id}/send", "tx_send_single.json") | ||
email = { | ||
"To" => "Bob Sacamano <[email protected]>", | ||
"Data" => { | ||
"anEmailVariable" => 'foo', | ||
"anotherEmailVariable" => 'bar' | ||
} | ||
} | ||
response = CreateSend::Transactional::SmartEmail.new(@auth, @smart_email_id).send(email) | ||
response.length.should == 1 | ||
response[0].MessageID.should == "0cfe150d-d507-11e4-84a7-c31e5b59881d" | ||
response[0].Recipient.should == "\"Bob Sacamano\" <[email protected]>" | ||
response[0].Status.should == "Received" | ||
end | ||
|
||
should "send smart email to multiple recipients with all the options" do | ||
stub_post(@auth, "transactional/smartemail/#{@smart_email_id}/send", "tx_send_multiple.json") | ||
email = { | ||
"To" => [ | ||
"Bob Sacamano <[email protected]>", | ||
"Newman <[email protected]>", | ||
], | ||
"CC" => [], | ||
"BCC" => [], | ||
"Data" => { | ||
"anEmailVariable" => 'foo', | ||
"anotherEmailVariable" => 'bar' | ||
}, | ||
"Attachments" => [ | ||
"Name" => "filename.gif", | ||
"Type" => "image/gif", | ||
"Content" => "R0lGODlhIAAgAKIAAP8AAJmZADNmAMzMAP//AAAAAP///wAAACH/C1hNUCBE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/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAAAAAAAsAAAAACAAIAAAA5loutz+MKpSpIWU3r1KCBW3eYQmWgWhmiemEgPbNqk6xDOd1XGYV77UzTfbTWC4nAHYQRKLu1VSuXxlpsodAFDAZrfcIbXDFXqhNacoQ3vZpuxHSJZ2zufyTqcunugdd00vQ0F4chQCAgYCaTcxiYuMMhGJFG89kYpFl5MzkoRPnpJskFSaDqctRoBxHEQsdGs0f7Qjq3utDwkAOw==" | ||
], | ||
"AddRecipientsToListID" => true | ||
} | ||
response = CreateSend::Transactional::SmartEmail.new(@auth, @smart_email_id).send(email) | ||
response.length.should == 2 | ||
response[1].MessageID.should == "0cfe150d-d507-11e4-b579-a64eb0d9c74d" | ||
response[1].Recipient.should == "\"Newman\" <[email protected]>" | ||
response[1].Status.should == "Received" | ||
end | ||
|
||
end | ||
end | ||
|
||
|