createsend 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/createsend/campaign.rb +6 -0
- data/lib/createsend/list.rb +12 -0
- data/lib/createsend/subscriber.rb +8 -2
- data/lib/createsend/version.rb +1 -1
- data/test/campaign_test.rb +8 -0
- data/test/fixtures/campaign_summary.json +3 -0
- data/test/fixtures/deleted_subscribers.json +51 -0
- data/test/list_test.rb +20 -1
- data/test/subscriber_test.rb +43 -0
- metadata +6 -4
data/README.md
CHANGED
data/lib/createsend/campaign.rb
CHANGED
@@ -43,6 +43,12 @@ module CreateSend
|
|
43
43
|
response = post "send", options
|
44
44
|
end
|
45
45
|
|
46
|
+
# Unschedules this campaign if it is currently scheduled.
|
47
|
+
def unschedule
|
48
|
+
options = { :body => "" }
|
49
|
+
response = post "unschedule", options
|
50
|
+
end
|
51
|
+
|
46
52
|
# Deletes this campaign.
|
47
53
|
def delete
|
48
54
|
response = CreateSend.delete "/campaigns/#{campaign_id}.json", {}
|
data/lib/createsend/list.rb
CHANGED
@@ -111,6 +111,18 @@ module CreateSend
|
|
111
111
|
Hashie::Mash.new(response)
|
112
112
|
end
|
113
113
|
|
114
|
+
# Gets the deleted subscribers for this list.
|
115
|
+
def deleted(date, page=1, page_size=1000, order_field="email", order_direction="asc")
|
116
|
+
options = { :query => {
|
117
|
+
:date => date,
|
118
|
+
:page => page,
|
119
|
+
:pagesize => page_size,
|
120
|
+
:orderfield => order_field,
|
121
|
+
:orderdirection => order_direction } }
|
122
|
+
response = get "deleted", options
|
123
|
+
Hashie::Mash.new(response)
|
124
|
+
end
|
125
|
+
|
114
126
|
# Updates this list.
|
115
127
|
def update(title, unsubscribe_page, confirmed_opt_in, confirmation_success_page)
|
116
128
|
options = { :body => {
|
@@ -31,10 +31,11 @@ module CreateSend
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Imports subscribers into a subscriber list.
|
34
|
-
def self.import(list_id, subscribers, resubscribe)
|
34
|
+
def self.import(list_id, subscribers, resubscribe, queue_subscription_based_autoresponders=false)
|
35
35
|
options = { :body => {
|
36
36
|
:Subscribers => subscribers,
|
37
|
-
:Resubscribe => resubscribe
|
37
|
+
:Resubscribe => resubscribe,
|
38
|
+
:QueueSubscriptionBasedAutoresponders => queue_subscription_based_autoresponders }.to_json }
|
38
39
|
begin
|
39
40
|
response = CreateSend.post "/subscribers/#{list_id}/import.json", options
|
40
41
|
rescue BadRequest => br
|
@@ -80,5 +81,10 @@ module CreateSend
|
|
80
81
|
response.map{|item| Hashie::Mash.new(item)}
|
81
82
|
end
|
82
83
|
|
84
|
+
# Moves this subscriber to the Deleted state in the associated list.
|
85
|
+
def delete
|
86
|
+
options = { :query => { :email => @email_address } }
|
87
|
+
CreateSend.delete "/subscribers/#{@list_id}.json", options
|
88
|
+
end
|
83
89
|
end
|
84
90
|
end
|
data/lib/createsend/version.rb
CHANGED
data/test/campaign_test.rb
CHANGED
@@ -26,6 +26,11 @@ class CampaignTest < Test::Unit::TestCase
|
|
26
26
|
stub_post(@api_key, "campaigns/#{@campaign.campaign_id}/send.json", nil)
|
27
27
|
@campaign.send "confirmation@example.com"
|
28
28
|
end
|
29
|
+
|
30
|
+
should "unschedule a campaign" do
|
31
|
+
stub_post(@api_key, "campaigns/#{@campaign.campaign_id}/unschedule.json", nil)
|
32
|
+
@campaign.unschedule
|
33
|
+
end
|
29
34
|
|
30
35
|
should "delete a campaign" do
|
31
36
|
stub_delete(@api_key, "campaigns/#{@campaign.campaign_id}.json", nil)
|
@@ -41,6 +46,9 @@ class CampaignTest < Test::Unit::TestCase
|
|
41
46
|
summary.Unsubscribed.should == 0
|
42
47
|
summary.Bounced.should == 0
|
43
48
|
summary.UniqueOpened.should == 5
|
49
|
+
summary.Mentions.should == 23
|
50
|
+
summary.Forwards.should == 11
|
51
|
+
summary.Likes.should == 32
|
44
52
|
summary.WebVersionURL.should == "http://createsend.com/t/r-3A433FC72FFE3B8B"
|
45
53
|
end
|
46
54
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
{
|
2
|
+
"Results": [
|
3
|
+
{
|
4
|
+
"EmailAddress": "subscriber@example.com",
|
5
|
+
"Name": "Deleted One",
|
6
|
+
"Date": "2010-10-25 13:11:00",
|
7
|
+
"State": "Deleted",
|
8
|
+
"CustomFields": []
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"EmailAddress": "subscriberone@example.com",
|
12
|
+
"Name": "Subscriber",
|
13
|
+
"Date": "2010-10-25 13:04:00",
|
14
|
+
"State": "Deleted",
|
15
|
+
"CustomFields": [
|
16
|
+
{
|
17
|
+
"Key": "website",
|
18
|
+
"Value": "http://google.com"
|
19
|
+
}
|
20
|
+
]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"EmailAddress": "example+1@example.com",
|
24
|
+
"Name": "Example One",
|
25
|
+
"Date": "2010-10-26 10:56:00",
|
26
|
+
"State": "Deleted",
|
27
|
+
"CustomFields": []
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"EmailAddress": "example+2@example.com",
|
31
|
+
"Name": "Example Two",
|
32
|
+
"Date": "2010-10-26 10:56:00",
|
33
|
+
"State": "Deleted",
|
34
|
+
"CustomFields": []
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"EmailAddress": "example+3@example.com",
|
38
|
+
"Name": "Example Three",
|
39
|
+
"Date": "2010-10-26 10:56:00",
|
40
|
+
"State": "Deleted",
|
41
|
+
"CustomFields": []
|
42
|
+
}
|
43
|
+
],
|
44
|
+
"ResultsOrderedBy": "email",
|
45
|
+
"OrderDirection": "asc",
|
46
|
+
"PageNumber": 1,
|
47
|
+
"PageSize": 1000,
|
48
|
+
"RecordsOnThisPage": 5,
|
49
|
+
"TotalNumberOfRecords": 5,
|
50
|
+
"NumberOfPages": 1
|
51
|
+
}
|
data/test/list_test.rb
CHANGED
@@ -123,6 +123,26 @@ class ListTest < Test::Unit::TestCase
|
|
123
123
|
res.Results.first.CustomFields.size.should == 0
|
124
124
|
end
|
125
125
|
|
126
|
+
should "get the deleted subscribers for a list" do
|
127
|
+
min_date = "2010-01-01"
|
128
|
+
stub_get(@api_key, "lists/#{@list.list_id}/deleted.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
|
129
|
+
"deleted_subscribers.json")
|
130
|
+
res = @list.deleted min_date
|
131
|
+
res.ResultsOrderedBy.should == "email"
|
132
|
+
res.OrderDirection.should == "asc"
|
133
|
+
res.PageNumber.should == 1
|
134
|
+
res.PageSize.should == 1000
|
135
|
+
res.RecordsOnThisPage.should == 5
|
136
|
+
res.TotalNumberOfRecords.should == 5
|
137
|
+
res.NumberOfPages.should == 1
|
138
|
+
res.Results.size.should == 5
|
139
|
+
res.Results.first.EmailAddress.should == "subscriber@example.com"
|
140
|
+
res.Results.first.Name.should == "Deleted One"
|
141
|
+
res.Results.first.Date.should == "2010-10-25 13:11:00"
|
142
|
+
res.Results.first.State.should == "Deleted"
|
143
|
+
res.Results.first.CustomFields.size.should == 0
|
144
|
+
end
|
145
|
+
|
126
146
|
should "get the bounced subscribers for a list" do
|
127
147
|
min_date = "2010-01-01"
|
128
148
|
stub_get(@api_key, "lists/#{@list.list_id}/bounced.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
|
@@ -184,6 +204,5 @@ class ListTest < Test::Unit::TestCase
|
|
184
204
|
stub_put(@api_key, "lists/#{@list.list_id}/webhooks/#{webhook_id}/deactivate.json", nil)
|
185
205
|
@list.deactivate_webhook webhook_id
|
186
206
|
end
|
187
|
-
|
188
207
|
end
|
189
208
|
end
|
data/test/subscriber_test.rb
CHANGED
@@ -52,6 +52,15 @@ class SubscriberTest < Test::Unit::TestCase
|
|
52
52
|
@subscriber.update new_email, "Subscriber", custom_fields, true
|
53
53
|
@subscriber.email_address.should == new_email
|
54
54
|
end
|
55
|
+
|
56
|
+
should "update a subscriber with custom fields including the clear option" do
|
57
|
+
email = "subscriber@example.com"
|
58
|
+
new_email = "new_email_address@example.com"
|
59
|
+
stub_put(@api_key, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil)
|
60
|
+
custom_fields = [ { :Key => 'website', :Value => '', :Clear => true } ]
|
61
|
+
@subscriber.update new_email, "Subscriber", custom_fields, true
|
62
|
+
@subscriber.email_address.should == new_email
|
63
|
+
end
|
55
64
|
|
56
65
|
should "import many subscribers at once" do
|
57
66
|
stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json")
|
@@ -68,6 +77,36 @@ class SubscriberTest < Test::Unit::TestCase
|
|
68
77
|
import_result.DuplicateEmailsInSubmission.size.should == 0
|
69
78
|
end
|
70
79
|
|
80
|
+
should "import many subscribers at once, and start subscription-based autoresponders" do
|
81
|
+
stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json")
|
82
|
+
subscribers = [
|
83
|
+
{ :EmailAddress => "example+1@example.com", :Name => "Example One" },
|
84
|
+
{ :EmailAddress => "example+2@example.com", :Name => "Example Two" },
|
85
|
+
{ :EmailAddress => "example+3@example.com", :Name => "Example Three" },
|
86
|
+
]
|
87
|
+
import_result = CreateSend::Subscriber.import @list_id, subscribers, true, true
|
88
|
+
import_result.FailureDetails.size.should == 0
|
89
|
+
import_result.TotalUniqueEmailsSubmitted.should == 3
|
90
|
+
import_result.TotalExistingSubscribers.should == 0
|
91
|
+
import_result.TotalNewSubscribers.should == 3
|
92
|
+
import_result.DuplicateEmailsInSubmission.size.should == 0
|
93
|
+
end
|
94
|
+
|
95
|
+
should "import many subscribers at once with custom fields, including the clear option" do
|
96
|
+
stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json")
|
97
|
+
subscribers = [
|
98
|
+
{ :EmailAddress => "example+1@example.com", :Name => "Example One", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => true } ] },
|
99
|
+
{ :EmailAddress => "example+2@example.com", :Name => "Example Two", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => false } ] },
|
100
|
+
{ :EmailAddress => "example+3@example.com", :Name => "Example Three", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => false } ] },
|
101
|
+
]
|
102
|
+
import_result = CreateSend::Subscriber.import @list_id, subscribers, true
|
103
|
+
import_result.FailureDetails.size.should == 0
|
104
|
+
import_result.TotalUniqueEmailsSubmitted.should == 3
|
105
|
+
import_result.TotalExistingSubscribers.should == 0
|
106
|
+
import_result.TotalNewSubscribers.should == 3
|
107
|
+
import_result.DuplicateEmailsInSubmission.size.should == 0
|
108
|
+
end
|
109
|
+
|
71
110
|
should "import many subscribers at once with partial success" do
|
72
111
|
# Stub request with 400 Bad Request as the expected response status
|
73
112
|
stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers_partial_success.json", 400)
|
@@ -106,5 +145,9 @@ class SubscriberTest < Test::Unit::TestCase
|
|
106
145
|
history.first.Actions.first.Detail.should == ""
|
107
146
|
end
|
108
147
|
|
148
|
+
should "delete a subscriber" do
|
149
|
+
stub_delete(@api_key, "subscribers/#{@subscriber.list_id}.json?email=#{CGI.escape(@subscriber.email_address)}", nil)
|
150
|
+
@subscriber.delete
|
151
|
+
end
|
109
152
|
end
|
110
153
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: createsend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Dennes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-31 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- test/fixtures/create_template.json
|
175
175
|
- test/fixtures/custom_api_error.json
|
176
176
|
- test/fixtures/custom_fields.json
|
177
|
+
- test/fixtures/deleted_subscribers.json
|
177
178
|
- test/fixtures/drafts.json
|
178
179
|
- test/fixtures/import_subscribers.json
|
179
180
|
- test/fixtures/import_subscribers_partial_success.json
|
@@ -262,6 +263,7 @@ test_files:
|
|
262
263
|
- test/fixtures/create_template.json
|
263
264
|
- test/fixtures/custom_api_error.json
|
264
265
|
- test/fixtures/custom_fields.json
|
266
|
+
- test/fixtures/deleted_subscribers.json
|
265
267
|
- test/fixtures/drafts.json
|
266
268
|
- test/fixtures/import_subscribers.json
|
267
269
|
- test/fixtures/import_subscribers_partial_success.json
|