Skip to content

Commit b0f0201

Browse files
committed
Merge pull request #41 from philoye/transactional-v1
Transactional v1
2 parents 1a8fdda + 59a804b commit b0f0201

22 files changed

Lines changed: 647 additions & 0 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: ruby
22
rvm:
3+
- 2.2
34
- 2.1
45
- 2.0.0
56
- 1.9.3

createsend.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
1313
s.add_development_dependency 'shoulda-context', '~> 1.2'
1414
s.add_development_dependency 'simplecov', '~> 0'
1515
s.add_development_dependency 'coveralls', '~> 0'
16+
s.add_development_dependency 'test-unit', '~>3.0'
1617
s.name = "createsend"
1718
s.author = "James Dennes"
1819
s.description = %q{Implements the complete functionality of the Campaign Monitor API.}

lib/createsend.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
require 'createsend/template'
1212
require 'createsend/person'
1313
require 'createsend/administrator'
14+
require 'createsend/transactional_classic_email'
15+
require 'createsend/transactional_smart_email'
16+
require 'createsend/transactional_timeline'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module CreateSend
2+
module Transactional
3+
class ClassicEmail < CreateSend
4+
attr_accessor :options
5+
6+
def initialize(auth, client_id = nil)
7+
@auth = auth
8+
@client_id = client_id
9+
super
10+
end
11+
12+
def send(options)
13+
response = post "/transactional/classicemail/send", { :body => options.to_json , :query => client_id }
14+
response.map{|item| Hashie::Mash.new(item)}
15+
end
16+
17+
def groups
18+
response = get "/transactional/classicemail/groups", :query => client_id
19+
response.map{|item| Hashie::Mash.new(item)}
20+
end
21+
22+
private
23+
24+
def client_id
25+
{:clientID => @client_id} if @client_id
26+
end
27+
28+
end
29+
end
30+
end
31+
32+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module CreateSend
2+
module Transactional
3+
class SmartEmail < CreateSend
4+
attr_reader :smart_email_id
5+
6+
def self.list(auth, options = nil)
7+
cs = CreateSend.new auth
8+
response = cs.get "/transactional/smartemail", :query => options
9+
response.map{|item| Hashie::Mash.new(item)}
10+
end
11+
12+
def initialize(auth, smart_email_id)
13+
@auth = auth
14+
@smart_email_id = smart_email_id
15+
super
16+
end
17+
18+
def details
19+
response = get "/transactional/smartemail/#{@smart_email_id}"
20+
Hashie::Mash.new(response)
21+
end
22+
23+
def send(options)
24+
response = post "/transactional/smartemail/#{@smart_email_id}/send", { :body => options.to_json }
25+
response.map{|item| Hashie::Mash.new(item)}
26+
end
27+
28+
end
29+
end
30+
end
31+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module CreateSend
2+
module Transactional
3+
class Timeline < CreateSend
4+
attr_reader :client_id
5+
6+
def initialize(auth, client_id = nil)
7+
@auth = auth
8+
@client_id = client_id
9+
super
10+
end
11+
12+
def messages(options = {})
13+
options = add_client_id(options)
14+
response = get "/transactional/messages", { :query => options }
15+
response.map{|item| Hashie::Mash.new(item)}
16+
end
17+
18+
def statistics(options = {})
19+
options = add_client_id(options)
20+
response = get "/transactional/statistics", { :query => options }
21+
Hashie::Mash.new(response)
22+
end
23+
24+
def details(message_id, options = {})
25+
options = add_client_id(options)
26+
response = get "/transactional/messages/#{message_id}", { :query => options }
27+
Hashie::Mash.new(response)
28+
end
29+
30+
def resend(message_id)
31+
response = post "/transactional/messages/#{message_id}/resend"
32+
response.map{|item| Hashie::Mash.new(item)}
33+
end
34+
35+
private
36+
37+
def add_client_id(options)
38+
options['clientID'] = @client_id if @client_id
39+
options
40+
end
41+
42+
end
43+
end
44+
end
45+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"Group": "Password Reset",
4+
"CreatedAt": "2015-03-28T09:41:36+11:00"
5+
},
6+
{
7+
"Group": "Credit card expired",
8+
"CreatedAt": "2015-05-04T22:24:12+10:00"
9+
},
10+
{
11+
"Group": "Order shipped",
12+
"CreatedAt": "2015-03-29T11:11:52+11:00"
13+
}
14+
]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
3+
"Status": "Delivered",
4+
"SentAt": "2014-01-15T16:09:19-05:00",
5+
"SmartEmailID": "c0da9c4c-e7e4-11e4-a74d-6c4008bc7468",
6+
"CanBeResent": true,
7+
"Recipient": "Joe Smith <joesmith@example.com>",
8+
"Message": {
9+
"From": "Team Webapp <team@webapp123.com",
10+
"Subject": "Thanks for signing up to web app 123",
11+
"To": [
12+
"Joe Smith <joesmith@example.com>",
13+
"jamesmith@example.com"
14+
],
15+
"CC": [
16+
"Joe Smith <joesmith@example.com>"
17+
],
18+
"BCC": "joesmith@example.com",
19+
"Attachments": [
20+
{
21+
"Name": "Invoice.pdf",
22+
"Type": "application/pdf"
23+
}
24+
],
25+
"Body": {
26+
"Html": "...",
27+
"Text": "..."
28+
},
29+
"Data": {
30+
"new_password_url": "https://www.mywebapp.com/newpassword?uid=jguf45hf74hbf74gf"
31+
}
32+
},
33+
"TotalOpens": 1,
34+
"TotalClicks": 1
35+
}
36+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
3+
"Status": "Delivered",
4+
"SentAt": "2014-01-15T16:09:19-05:00",
5+
"SmartEmailID": "c0da9c4c-e7e4-11e4-a74d-6c4008bc7468",
6+
"CanBeResent": true,
7+
"Recipient": "Joe Smith <joesmith@example.com>",
8+
"Message": {
9+
"From": "Team Webapp <team@webapp123.com",
10+
"Subject": "Thanks for signing up to web app 123",
11+
"To": [
12+
"Joe Smith <joesmith@example.com>",
13+
"jamesmith@example.com"
14+
],
15+
"CC": [
16+
"Joe Smith <joesmith@example.com>"
17+
],
18+
"BCC": "joesmith@example.com",
19+
"Attachments": [
20+
{
21+
"Name": "Invoice.pdf",
22+
"Type": "application/pdf"
23+
}
24+
],
25+
"Body": {
26+
"Html": "...",
27+
"Text": "..."
28+
},
29+
"Data": {
30+
"new_password_url": "https://www.mywebapp.com/newpassword?uid=jguf45hf74hbf74gf"
31+
}
32+
},
33+
"TotalOpens": 1,
34+
"TotalClicks": 1,
35+
"Opens": [
36+
{
37+
"EmailAddress": "jamesmith@example.com",
38+
"Date": "2009-05-18 16:45:00",
39+
"IPAddress": "192.168.0.1",
40+
"Geolocation": {
41+
"Latitude": -33.8683,
42+
"Longitude": 151.2086,
43+
"City": "Sydney",
44+
"Region": "New South Wales",
45+
"CountryCode": "AU",
46+
"CountryName": "Australia"
47+
},
48+
"MailClient": {
49+
"Name": "Apple Mail",
50+
"OS": "OS X",
51+
"Device": "Desktop"
52+
}
53+
}
54+
],
55+
"Clicks": [
56+
{
57+
"EmailAddress": "jamesmith@example.com",
58+
"Date": "2009-05-18 16:45:00",
59+
"IPAddress": "192.168.0.1",
60+
"URL": "http://www.myexammple.com/index.html",
61+
"Geolocation": {
62+
"Latitude": -33.8683,
63+
"Longitude": 151.2086,
64+
"City": "Sydney",
65+
"Region": "New South Wales",
66+
"CountryCode": "AU",
67+
"CountryName": "Australia"
68+
}
69+
}
70+
]
71+
}
72+

test/fixtures/tx_messages.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
4+
"Status": "Delivered",
5+
"SentAt": "2014-01-15T16:09:19-05:00",
6+
"Recipient": "Joe Smith <joesmith@example.com>",
7+
"From": "Team <team@company.com>",
8+
"Subject": "Ungrouped message",
9+
"TotalOpens": 2,
10+
"TotalClicks": 4,
11+
"CanBeResent": true
12+
},
13+
{
14+
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
15+
"Status": "Delivered",
16+
"SentAt": "2014-01-15T16:09:19-05:00",
17+
"Recipient": "Joe Smith <joesmith@example.com>",
18+
"From": "Team <team@company.com>",
19+
"Subject": "Your password has been reset",
20+
"TotalOpens": 2,
21+
"TotalClicks": 4,
22+
"CanBeResent": true,
23+
"Group": "Password Reset"
24+
},
25+
{
26+
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
27+
"Status": "Delivered",
28+
"SentAt": "2014-01-15T16:09:19-05:00",
29+
"Recipient": "Joe Smith <joesmith@example.com>",
30+
"From": "Team <team@company.com>",
31+
"Subject": "Your credit card has expired",
32+
"TotalOpens": 2,
33+
"TotalClicks": 4,
34+
"CanBeResent": true,
35+
"SmartEmailID": "21dab350-f484-11e4-ad38-6c4008bc7468"
36+
}
37+
]
38+

0 commit comments

Comments
 (0)