Skip to content

Commit

Permalink
Merge pull request #41 from philoye/transactional-v1
Browse files Browse the repository at this point in the history
Transactional v1
  • Loading branch information
philoye committed Aug 4, 2015
2 parents 1a8fdda + 59a804b commit b0f0201
Show file tree
Hide file tree
Showing 22 changed files with 647 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: ruby
rvm:
- 2.2
- 2.1
- 2.0.0
- 1.9.3
Expand Down
1 change: 1 addition & 0 deletions createsend.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'shoulda-context', '~> 1.2'
s.add_development_dependency 'simplecov', '~> 0'
s.add_development_dependency 'coveralls', '~> 0'
s.add_development_dependency 'test-unit', '~>3.0'
s.name = "createsend"
s.author = "James Dennes"
s.description = %q{Implements the complete functionality of the Campaign Monitor API.}
Expand Down
3 changes: 3 additions & 0 deletions lib/createsend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
require 'createsend/template'
require 'createsend/person'
require 'createsend/administrator'
require 'createsend/transactional_classic_email'
require 'createsend/transactional_smart_email'
require 'createsend/transactional_timeline'
32 changes: 32 additions & 0 deletions lib/createsend/transactional_classic_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module CreateSend
module Transactional
class ClassicEmail < CreateSend
attr_accessor :options

def initialize(auth, client_id = nil)
@auth = auth
@client_id = client_id
super
end

def send(options)
response = post "/transactional/classicemail/send", { :body => options.to_json , :query => client_id }
response.map{|item| Hashie::Mash.new(item)}
end

def groups
response = get "/transactional/classicemail/groups", :query => client_id
response.map{|item| Hashie::Mash.new(item)}
end

private

def client_id
{:clientID => @client_id} if @client_id
end

end
end
end


31 changes: 31 additions & 0 deletions lib/createsend/transactional_smart_email.rb
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

45 changes: 45 additions & 0 deletions lib/createsend/transactional_timeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module CreateSend
module Transactional
class Timeline < CreateSend
attr_reader :client_id

def initialize(auth, client_id = nil)
@auth = auth
@client_id = client_id
super
end

def messages(options = {})
options = add_client_id(options)
response = get "/transactional/messages", { :query => options }
response.map{|item| Hashie::Mash.new(item)}
end

def statistics(options = {})
options = add_client_id(options)
response = get "/transactional/statistics", { :query => options }
Hashie::Mash.new(response)
end

def details(message_id, options = {})
options = add_client_id(options)
response = get "/transactional/messages/#{message_id}", { :query => options }
Hashie::Mash.new(response)
end

def resend(message_id)
response = post "/transactional/messages/#{message_id}/resend"
response.map{|item| Hashie::Mash.new(item)}
end

private

def add_client_id(options)
options['clientID'] = @client_id if @client_id
options
end

end
end
end

14 changes: 14 additions & 0 deletions test/fixtures/tx_classicemail_groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"Group": "Password Reset",
"CreatedAt": "2015-03-28T09:41:36+11:00"
},
{
"Group": "Credit card expired",
"CreatedAt": "2015-05-04T22:24:12+10:00"
},
{
"Group": "Order shipped",
"CreatedAt": "2015-03-29T11:11:52+11:00"
}
]
36 changes: 36 additions & 0 deletions test/fixtures/tx_message_details.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"SmartEmailID": "c0da9c4c-e7e4-11e4-a74d-6c4008bc7468",
"CanBeResent": true,
"Recipient": "Joe Smith <[email protected]>",
"Message": {
"From": "Team Webapp <[email protected]",
"Subject": "Thanks for signing up to web app 123",
"To": [
"Joe Smith <[email protected]>",
"[email protected]"
],
"CC": [
"Joe Smith <[email protected]>"
],
"BCC": "[email protected]",
"Attachments": [
{
"Name": "Invoice.pdf",
"Type": "application/pdf"
}
],
"Body": {
"Html": "...",
"Text": "..."
},
"Data": {
"new_password_url": "https://www.mywebapp.com/newpassword?uid=jguf45hf74hbf74gf"
}
},
"TotalOpens": 1,
"TotalClicks": 1
}

72 changes: 72 additions & 0 deletions test/fixtures/tx_message_details_with_statistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"SmartEmailID": "c0da9c4c-e7e4-11e4-a74d-6c4008bc7468",
"CanBeResent": true,
"Recipient": "Joe Smith <[email protected]>",
"Message": {
"From": "Team Webapp <[email protected]",
"Subject": "Thanks for signing up to web app 123",
"To": [
"Joe Smith <[email protected]>",
"[email protected]"
],
"CC": [
"Joe Smith <[email protected]>"
],
"BCC": "[email protected]",
"Attachments": [
{
"Name": "Invoice.pdf",
"Type": "application/pdf"
}
],
"Body": {
"Html": "...",
"Text": "..."
},
"Data": {
"new_password_url": "https://www.mywebapp.com/newpassword?uid=jguf45hf74hbf74gf"
}
},
"TotalOpens": 1,
"TotalClicks": 1,
"Opens": [
{
"EmailAddress": "[email protected]",
"Date": "2009-05-18 16:45:00",
"IPAddress": "192.168.0.1",
"Geolocation": {
"Latitude": -33.8683,
"Longitude": 151.2086,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
},
"MailClient": {
"Name": "Apple Mail",
"OS": "OS X",
"Device": "Desktop"
}
}
],
"Clicks": [
{
"EmailAddress": "[email protected]",
"Date": "2009-05-18 16:45:00",
"IPAddress": "192.168.0.1",
"URL": "http://www.myexammple.com/index.html",
"Geolocation": {
"Latitude": -33.8683,
"Longitude": 151.2086,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
}
}
]
}

38 changes: 38 additions & 0 deletions test/fixtures/tx_messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"Recipient": "Joe Smith <[email protected]>",
"From": "Team <[email protected]>",
"Subject": "Ungrouped message",
"TotalOpens": 2,
"TotalClicks": 4,
"CanBeResent": true
},
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"Recipient": "Joe Smith <[email protected]>",
"From": "Team <[email protected]>",
"Subject": "Your password has been reset",
"TotalOpens": 2,
"TotalClicks": 4,
"CanBeResent": true,
"Group": "Password Reset"
},
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"Recipient": "Joe Smith <[email protected]>",
"From": "Team <[email protected]>",
"Subject": "Your credit card has expired",
"TotalOpens": 2,
"TotalClicks": 4,
"CanBeResent": true,
"SmartEmailID": "21dab350-f484-11e4-ad38-6c4008bc7468"
}
]

15 changes: 15 additions & 0 deletions test/fixtures/tx_messages_classic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"Recipient": "Joe Smith <[email protected]>",
"From": "Team <[email protected]>",
"Subject": "Your password has been reset",
"TotalOpens": 2,
"TotalClicks": 4,
"CanBeResent": true,
"Group": "Password Reset"
}
]

15 changes: 15 additions & 0 deletions test/fixtures/tx_messages_smart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"MessageID": "ddc697c7-0788-4df3-a71a-a7cb935f00bd",
"Status": "Delivered",
"SentAt": "2014-01-15T16:09:19-05:00",
"Recipient": "Joe Smith <[email protected]>",
"From": "Team <[email protected]>",
"Subject": "Your credit card has expired",
"TotalOpens": 2,
"TotalClicks": 4,
"CanBeResent": true,
"SmartEmailID": "21dab350-f484-11e4-ad38-6c4008bc7468"
}
]

6 changes: 6 additions & 0 deletions test/fixtures/tx_resend_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Status": "Accepted",
"Recipient": "Joe Smith <[email protected]>",
"MessageID": "cfb5e081-ef66-4bc4-a1c0-48493b34e694"
}

12 changes: 12 additions & 0 deletions test/fixtures/tx_send_multiple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"MessageID": "0cfe150d-d507-11e4-84a7-c31e5b59881d",
"Recipient": "\"Bob Sacamano\" <[email protected]>",
"Status": "Received"
},
{
"MessageID": "0cfe150d-d507-11e4-b579-a64eb0d9c74d",
"Recipient": "\"Newman\" <[email protected]>",
"Status": "Received"
}
]
7 changes: 7 additions & 0 deletions test/fixtures/tx_send_single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"MessageID": "0cfe150d-d507-11e4-84a7-c31e5b59881d",
"Recipient": "\"Bob Sacamano\" <[email protected]>",
"Status": "Received"
}
]
23 changes: 23 additions & 0 deletions test/fixtures/tx_smartemail_details.json
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
}
15 changes: 15 additions & 0 deletions test/fixtures/tx_smartemails.json
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"
}
]

Loading

0 comments on commit b0f0201

Please sign in to comment.