createsend 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/README.md +6 -6
- data/Rakefile +1 -1
- data/createsend.gemspec +1 -1
- data/lib/campaign.rb +131 -129
- data/lib/client.rb +134 -132
- data/lib/createsend.rb +94 -80
- data/lib/list.rb +179 -180
- data/lib/segment.rb +67 -65
- data/lib/subscriber.rb +56 -54
- data/lib/template.rb +35 -33
- data/test/campaign_test.rb +2 -2
- data/test/client_test.rb +2 -2
- data/test/createsend_test.rb +8 -8
- data/test/fixtures/list_webhooks.json +1 -4
- data/test/list_test.rb +4 -4
- data/test/segment_test.rb +2 -2
- data/test/subscriber_test.rb +6 -6
- data/test/template_test.rb +2 -2
- metadata +5 -5
data/lib/segment.rb
CHANGED
@@ -1,83 +1,85 @@
|
|
1
1
|
require 'createsend'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module CreateSend
|
5
|
+
# Represents a subscriber list segment and associated functionality.
|
6
|
+
class Segment
|
7
|
+
attr_reader :segment_id
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(segment_id)
|
10
|
+
@segment_id = segment_id
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
# Creates a new segment.
|
14
|
+
def self.create(list_id, title, rules)
|
15
|
+
options = { :body => {
|
16
|
+
:Title => title,
|
17
|
+
:Rules => rules }.to_json }
|
18
|
+
response = CreateSend.post "/segments/#{list_id}.json", options
|
19
|
+
response.parsed_response
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
# Updates this segment.
|
23
|
+
def update(title, rules)
|
24
|
+
options = { :body => {
|
25
|
+
:Title => title,
|
26
|
+
:Rules => rules }.to_json }
|
27
|
+
response = CreateSend.put "/segments/#{segment_id}.json", options
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
# Adds a rule to this segment.
|
31
|
+
def add_rule(subject, clauses)
|
32
|
+
options = { :body => {
|
33
|
+
:Subject => subject,
|
34
|
+
:Clauses => clauses }.to_json }
|
35
|
+
response = CreateSend.post "/segments/#{segment_id}/rules.json", options
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
# Gets the active subscribers in this segment.
|
39
|
+
def subscribers(date, page=1, page_size=1000, order_field="email", order_direction="asc")
|
40
|
+
options = { :query => {
|
41
|
+
:date => date,
|
42
|
+
:page => page,
|
43
|
+
:pagesize => page_size,
|
44
|
+
:orderfield => order_field,
|
45
|
+
:orderdirection => order_direction } }
|
46
|
+
response = get "active", options
|
47
|
+
Hashie::Mash.new(response)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
# Gets the details of this segment
|
51
|
+
def details
|
52
|
+
response = CreateSend.get "/segments/#{segment_id}.json", {}
|
53
|
+
Hashie::Mash.new(response)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
# Clears all rules of this segment.
|
57
|
+
def clear_rules
|
58
|
+
response = CreateSend.delete "/segments/#{segment_id}/rules.json", {}
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
# Deletes this segment.
|
62
|
+
def delete
|
63
|
+
response = CreateSend.delete "/segments/#{segment_id}.json", {}
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
+
private
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def get(action, options = {})
|
69
|
+
CreateSend.get uri_for(action), options
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def post(action, options = {})
|
73
|
+
CreateSend.post uri_for(action), options
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def put(action, options = {})
|
77
|
+
CreateSend.put uri_for(action), options
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
def uri_for(action)
|
81
|
+
"/segments/#{segment_id}/#{action}.json"
|
82
|
+
end
|
82
83
|
|
84
|
+
end
|
83
85
|
end
|
data/lib/subscriber.rb
CHANGED
@@ -1,67 +1,69 @@
|
|
1
1
|
require 'createsend'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module CreateSend
|
5
|
+
# Represents a subscriber and associated functionality.
|
6
|
+
class Subscriber
|
7
|
+
attr_reader :list_id
|
8
|
+
attr_reader :email_address
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(list_id, email_address)
|
11
|
+
@list_id = list_id
|
12
|
+
@email_address = email_address
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
# Gets a subscriber by list ID and email address.
|
16
|
+
def self.get(list_id, email_address)
|
17
|
+
options = { :query => { :email => email_address } }
|
18
|
+
response = CreateSend.get "/subscribers/#{list_id}.json", options
|
19
|
+
Hashie::Mash.new(response)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
# Adds a subscriber to a subscriber list.
|
23
|
+
def self.add(list_id, email_address, name, custom_fields, resubscribe)
|
24
|
+
options = { :body => {
|
25
|
+
:EmailAddress => email_address,
|
26
|
+
:Name => name,
|
27
|
+
:CustomFields => custom_fields,
|
28
|
+
:Resubscribe => resubscribe }.to_json }
|
29
|
+
response = CreateSend.post "/subscribers/#{list_id}.json", options
|
30
|
+
response.parsed_response
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
# Imports subscribers into a subscriber list.
|
34
|
+
def self.import(list_id, subscribers, resubscribe)
|
35
|
+
options = { :body => {
|
36
|
+
:Subscribers => subscribers,
|
37
|
+
:Resubscribe => resubscribe }.to_json }
|
38
|
+
begin
|
39
|
+
response = CreateSend.post "/subscribers/#{list_id}/import.json", options
|
40
|
+
rescue BadRequest => br
|
41
|
+
# Subscriber import will throw BadRequest if some subscribers are not imported
|
42
|
+
# successfully. If this occurs, we want to return the ResultData property of
|
43
|
+
# the BadRequest exception (which is of the same "form" as the response we'd
|
44
|
+
# receive upon a completely successful import)
|
45
|
+
if br.data.ResultData
|
46
|
+
return br.data.ResultData
|
47
|
+
else
|
48
|
+
raise br
|
49
|
+
end
|
48
50
|
end
|
51
|
+
Hashie::Mash.new(response)
|
49
52
|
end
|
50
|
-
Hashie::Mash.new(response)
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
# Unsubscribes this subscriber from the associated list.
|
55
|
+
def unsubscribe
|
56
|
+
options = { :body => {
|
57
|
+
:EmailAddress => @email_address }.to_json }
|
58
|
+
CreateSend.post "/subscribers/#{@list_id}/unsubscribe.json", options
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
# Gets the historical record of this subscriber's trackable actions.
|
62
|
+
def history
|
63
|
+
options = { :query => { :email => @email_address } }
|
64
|
+
response = CreateSend.get "/subscribers/#{@list_id}/history.json", options
|
65
|
+
response.map{|item| Hashie::Mash.new(item)}
|
66
|
+
end
|
66
67
|
|
68
|
+
end
|
67
69
|
end
|
data/lib/template.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
1
|
require 'createsend'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module CreateSend
|
5
|
+
# Represents an email template and associated functionality.
|
6
|
+
class Template
|
7
|
+
attr_reader :template_id
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(template_id)
|
10
|
+
@template_id = template_id
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
# Creates a new email template.
|
14
|
+
def self.create(client_id, name, html_url, zip_url, screenshot_url)
|
15
|
+
options = { :body => {
|
16
|
+
:Name => name,
|
17
|
+
:HtmlPageURL => html_url,
|
18
|
+
:ZipFileURL => zip_url,
|
19
|
+
:ScreenshotURL => screenshot_url }.to_json }
|
20
|
+
response = CreateSend.post "/templates/#{client_id}.json", options
|
21
|
+
response.parsed_response
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# Gets the details of this email template.
|
25
|
+
def details
|
26
|
+
response = CreateSend.get "/templates/#{template_id}.json", {}
|
27
|
+
Hashie::Mash.new(response)
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
# Updates this email template.
|
31
|
+
def update(name, html_url, zip_url, screenshot_url)
|
32
|
+
options = { :body => {
|
33
|
+
:Name => name,
|
34
|
+
:HtmlPageURL => html_url,
|
35
|
+
:ZipFileURL => zip_url,
|
36
|
+
:ScreenshotURL => screenshot_url }.to_json }
|
37
|
+
response = CreateSend.put "/templates/#{template_id}.json", options
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
# Deletes this email template.
|
41
|
+
def delete
|
42
|
+
response = CreateSend.delete "/templates/#{template_id}.json", {}
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
data/test/campaign_test.rb
CHANGED
@@ -5,13 +5,13 @@ class CampaignTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
@api_key = '123123123123123123123'
|
7
7
|
CreateSend.api_key @api_key
|
8
|
-
@campaign = Campaign.new(:campaign_id => '787y87y87y87y87y87y87')
|
8
|
+
@campaign = CreateSend::Campaign.new(:campaign_id => '787y87y87y87y87y87y87')
|
9
9
|
end
|
10
10
|
|
11
11
|
should "create a campaign" do
|
12
12
|
client_id = '87y8d7qyw8d7yq8w7ydwqwd'
|
13
13
|
stub_post(@api_key, "campaigns/#{client_id}.json", "create_campaign.json")
|
14
|
-
campaign_id = Campaign.create client_id, "subject", "name", "g'day", "good.day@example.com", "good.day@example.com",
|
14
|
+
campaign_id = CreateSend::Campaign.create client_id, "subject", "name", "g'day", "good.day@example.com", "good.day@example.com",
|
15
15
|
"http://example.com/campaign.html", "http://example.com/campaign.txt", [ '7y12989e82ue98u2e', 'dh9w89q8w98wudwd989' ],
|
16
16
|
[ 'y78q9w8d9w8ud9q8uw', 'djw98quw9duqw98uwd98' ]
|
17
17
|
campaign_id.should == "787y87y87y87y87y87y87"
|
data/test/client_test.rb
CHANGED
@@ -5,12 +5,12 @@ class ClientTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
@api_key = '123123123123123123123'
|
7
7
|
CreateSend.api_key @api_key
|
8
|
-
@client = Client.new(:client_id => '321iuhiuhi1u23hi2u3')
|
8
|
+
@client = CreateSend::Client.new(:client_id => '321iuhiuhi1u23hi2u3')
|
9
9
|
end
|
10
10
|
|
11
11
|
should "create a client" do
|
12
12
|
stub_post(@api_key, "clients.json", "create_client.json")
|
13
|
-
client_id = Client.create "Client Company Name", "Client Contact Name", "client@example.com", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
|
13
|
+
client_id = CreateSend::Client.create "Client Company Name", "Client Contact Name", "client@example.com", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
|
14
14
|
client_id.should == "32a381c49a2df99f1d0c6f3c112352b9"
|
15
15
|
end
|
16
16
|
|
data/test/createsend_test.rb
CHANGED
@@ -6,7 +6,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
6
6
|
@api_key = '123123123123123123123'
|
7
7
|
@base_uri = 'http://api.createsend.com/api/v3'
|
8
8
|
CreateSend.api_key @api_key
|
9
|
-
@cs = CreateSend.new
|
9
|
+
@cs = CreateSend::CreateSend.new
|
10
10
|
end
|
11
11
|
|
12
12
|
should "get api key" do
|
@@ -53,14 +53,14 @@ class CreateSendTest < Test::Unit::TestCase
|
|
53
53
|
@api_key = '123123123123123123123'
|
54
54
|
@base_uri = 'http://api.createsend.com/api/v3'
|
55
55
|
CreateSend.api_key @api_key
|
56
|
-
@cs = CreateSend.new
|
57
|
-
@template = Template.new(:template_id => '98y2e98y289dh89h938389')
|
56
|
+
@cs = CreateSend::CreateSend.new
|
57
|
+
@template = CreateSend::Template.new(:template_id => '98y2e98y289dh89h938389')
|
58
58
|
end
|
59
59
|
|
60
|
-
{ ["400", "Bad Request"] => BadRequest,
|
61
|
-
["401", "Unauthorized"] => Unauthorized,
|
62
|
-
["404", "Not Found"] => NotFound,
|
63
|
-
["500", "Server Error"] => ServerError
|
60
|
+
{ ["400", "Bad Request"] => CreateSend::BadRequest,
|
61
|
+
["401", "Unauthorized"] => CreateSend::Unauthorized,
|
62
|
+
["404", "Not Found"] => CreateSend::NotFound,
|
63
|
+
["500", "Server Error"] => CreateSend::ServerError
|
64
64
|
}.each do |status, exception|
|
65
65
|
context "#{status.first}, a get" do
|
66
66
|
should "raise a #{exception.name} error" do
|
@@ -72,7 +72,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
72
72
|
context "#{status.first}, a post" do
|
73
73
|
should "raise a #{exception.name} error" do
|
74
74
|
stub_post(@api_key, "clients.json", (status.first == '400' or status.first == '401') ? 'custom_api_error.json' : nil, status)
|
75
|
-
lambda { Client.create "Client Company Name", "Client Contact Name", "client@example.com",
|
75
|
+
lambda { CreateSend::Client.create "Client Company Name", "Client Contact Name", "client@example.com",
|
76
76
|
"(GMT+10:00) Canberra, Melbourne, Sydney", "Australia" }.should raise_error(exception)
|
77
77
|
end
|
78
78
|
end
|
data/test/list_test.rb
CHANGED
@@ -7,12 +7,12 @@ class ListTest < Test::Unit::TestCase
|
|
7
7
|
CreateSend.api_key @api_key
|
8
8
|
@client_id = "87y8d7qyw8d7yq8w7ydwqwd"
|
9
9
|
@list_id = "e3c5f034d68744f7881fdccf13c2daee"
|
10
|
-
@list = List.new @list_id
|
10
|
+
@list = CreateSend::List.new @list_id
|
11
11
|
end
|
12
12
|
|
13
13
|
should "create a list" do
|
14
14
|
stub_post(@api_key, "lists/#{@client_id}.json", "create_list.json")
|
15
|
-
list_id = List.create @client_id, "List One", "", false, ""
|
15
|
+
list_id = CreateSend::List.create @client_id, "List One", "", false, ""
|
16
16
|
list_id.should == "e3c5f034d68744f7881fdccf13c2daee"
|
17
17
|
end
|
18
18
|
|
@@ -148,8 +148,8 @@ class ListTest < Test::Unit::TestCase
|
|
148
148
|
hooks = @list.webhooks
|
149
149
|
hooks.size.should == 2
|
150
150
|
hooks.first.WebhookID.should == "943678317049bc13"
|
151
|
-
hooks.first.Events.size.should ==
|
152
|
-
hooks.first.Events.first.should == "
|
151
|
+
hooks.first.Events.size.should == 1
|
152
|
+
hooks.first.Events.first.should == "Deactivate"
|
153
153
|
hooks.first.Url.should == "http://www.postbin.org/d9w8ud9wud9w"
|
154
154
|
hooks.first.Status.should == "Active"
|
155
155
|
hooks.first.PayloadFormat.should == "Json"
|