createsend 5.1.1 → 6.1.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.
- checksums.yaml +4 -4
- data/HISTORY.md +30 -0
- data/README.md +2 -2
- data/createsend.gemspec +1 -1
- data/lib/createsend/client.rb +19 -3
- data/lib/createsend/createsend.rb +1 -1
- data/lib/createsend/list.rb +13 -12
- data/lib/createsend/subscriber.rb +8 -4
- data/lib/createsend/version.rb +1 -1
- data/samples/authentication_sample.rb +64 -0
- data/samples/clients_sample.rb +79 -0
- data/samples/journey_sample.rb +3 -2
- data/samples/lists_sample.rb +51 -0
- data/samples/segments_sample.rb +21 -0
- data/samples/subscribers_sample.rb +51 -0
- data/test/administrator_test.rb +5 -5
- data/test/campaign_test.rb +114 -113
- data/test/client_test.rb +121 -98
- data/test/createsend_test.rb +47 -47
- data/test/fixtures/active_subscribers.json +5 -0
- data/test/fixtures/bounced_subscribers.json +1 -0
- data/test/fixtures/campaign_summary.json +2 -1
- data/test/fixtures/campaigns.json +37 -26
- data/test/fixtures/deleted_subscribers.json +5 -0
- data/test/fixtures/drafts.json +4 -2
- data/test/fixtures/scheduled_campaigns.json +4 -2
- data/test/fixtures/segment_subscribers.json +2 -0
- data/test/fixtures/subscriber_details.json +2 -0
- data/test/fixtures/{subscriber_details_with_track_pref.json → subscriber_details_with_track_and_sms_pref.json} +4 -1
- data/test/fixtures/tags.json +10 -0
- data/test/fixtures/unconfirmed_subscribers.json +6 -2
- data/test/fixtures/unsubscribed_subscribers.json +6 -1
- data/test/helper.rb +1 -1
- data/test/journey_test.rb +86 -86
- data/test/list_test.rb +130 -123
- data/test/person_test.rb +6 -6
- data/test/segment_test.rb +23 -22
- data/test/subscriber_test.rb +55 -51
- data/test/template_test.rb +5 -5
- data/test/transactional_classic_email_test.rb +6 -6
- data/test/transactional_smart_email_test.rb +19 -19
- data/test/transactional_timeline_test.rb +25 -25
- metadata +16 -113
data/test/client_test.rb
CHANGED
@@ -4,166 +4,189 @@ class ClientTest < Test::Unit::TestCase
|
|
4
4
|
multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do
|
5
5
|
setup do
|
6
6
|
@client = CreateSend::Client.new(@auth, '321iuhiuhi1u23hi2u3')
|
7
|
-
@client.client_id.should == '321iuhiuhi1u23hi2u3'
|
7
|
+
@client.client_id.should be == '321iuhiuhi1u23hi2u3'
|
8
8
|
end
|
9
9
|
|
10
10
|
should "create a client" do
|
11
11
|
stub_post(@auth, "clients.json", "create_client.json")
|
12
12
|
client_id = CreateSend::Client.create @auth, "Client Company Name", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
|
13
|
-
client_id.parsed_response.should == "32a381c49a2df99f1d0c6f3c112352b9"
|
13
|
+
client_id.parsed_response.should be == "32a381c49a2df99f1d0c6f3c112352b9"
|
14
14
|
end
|
15
15
|
|
16
16
|
should "get details of a client" do
|
17
17
|
stub_get(@auth, "clients/#{@client.client_id}.json", "client_details.json")
|
18
18
|
cl = @client.details
|
19
|
-
cl.ApiKey.should == "639d8cc27198202f5fe6037a8b17a29a59984b86d3289bc9"
|
20
|
-
cl.BasicDetails.ClientID.should == "4a397ccaaa55eb4e6aa1221e1e2d7122"
|
21
|
-
cl.BasicDetails.ContactName.should == "Client One (contact)"
|
22
|
-
cl.AccessDetails.Username.should == "clientone"
|
23
|
-
cl.AccessDetails.AccessLevel.should == 23
|
24
|
-
cl.BillingDetails.MonthlyScheme.should == "Basic"
|
25
|
-
cl.BillingDetails.Credits.should == 500
|
19
|
+
cl.ApiKey.should be == "639d8cc27198202f5fe6037a8b17a29a59984b86d3289bc9"
|
20
|
+
cl.BasicDetails.ClientID.should be == "4a397ccaaa55eb4e6aa1221e1e2d7122"
|
21
|
+
cl.BasicDetails.ContactName.should be == "Client One (contact)"
|
22
|
+
cl.AccessDetails.Username.should be == "clientone"
|
23
|
+
cl.AccessDetails.AccessLevel.should be == 23
|
24
|
+
cl.BillingDetails.MonthlyScheme.should be == "Basic"
|
25
|
+
cl.BillingDetails.Credits.should be == 500
|
26
26
|
end
|
27
27
|
|
28
28
|
should "get all campaigns" do
|
29
|
-
stub_get(@auth, "clients/#{@client.client_id}/campaigns.json", "campaigns.json")
|
29
|
+
stub_get(@auth, "clients/#{@client.client_id}/campaigns.json?page=1&pagesize=1000&orderdirection=desc&sentfromdate=&senttodate=&tags=", "campaigns.json")
|
30
30
|
campaigns = @client.campaigns
|
31
|
-
campaigns.size.should == 2
|
32
|
-
campaigns.
|
33
|
-
campaigns.
|
34
|
-
campaigns.
|
35
|
-
campaigns.
|
36
|
-
campaigns.
|
37
|
-
campaigns.
|
38
|
-
campaigns.
|
39
|
-
|
40
|
-
campaigns.first
|
41
|
-
|
31
|
+
campaigns.Results.size.should be == 2
|
32
|
+
campaigns.ResultsOrderedBy be == 'sentdate'
|
33
|
+
campaigns.OrderDirection be == 'desc'
|
34
|
+
campaigns.PageNumber be == 1
|
35
|
+
campaigns.PageSize be == 1000
|
36
|
+
campaigns.RecordsOnThisPage be == 2
|
37
|
+
campaigns.TotalNumberOfRecords be == 2
|
38
|
+
campaigns.NumberOfPages be == 1
|
39
|
+
|
40
|
+
campaign = campaigns.Results.first
|
41
|
+
campaign.CampaignID.should be == 'fc0ce7105baeaf97f47c99be31d02a91'
|
42
|
+
campaign.WebVersionURL.should be == 'http://createsend.com/t/r-765E86829575EE2C'
|
43
|
+
campaign.WebVersionTextURL.should be == 'http://createsend.com/t/r-765E86829575EE2C/t'
|
44
|
+
campaign.Subject.should be == 'Campaign One'
|
45
|
+
campaign.Name.should be == 'Campaign One'
|
46
|
+
campaign.SentDate.should be == '2010-10-12 12:58:00'
|
47
|
+
campaign.TotalRecipients.should be == 2245
|
48
|
+
campaign.FromName.should be == 'My Name'
|
49
|
+
campaign.FromEmail.should be == 'myemail@example.com'
|
50
|
+
campaign.ReplyTo.should be == 'myemail@example.com'
|
51
|
+
campaign.Tags.should be == []
|
42
52
|
end
|
43
53
|
|
44
54
|
should "get scheduled campaigns" do
|
45
55
|
stub_get(@auth, "clients/#{@client.client_id}/scheduled.json", "scheduled_campaigns.json")
|
46
56
|
campaigns = @client.scheduled
|
47
|
-
campaigns.size.should == 2
|
48
|
-
campaigns.first
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
campaigns.size.should be == 2
|
58
|
+
campaign = campaigns.first
|
59
|
+
campaign.DateScheduled.should be == "2011-05-25 10:40:00"
|
60
|
+
campaign.ScheduledTimeZone.should be == "(GMT+10:00) Canberra, Melbourne, Sydney"
|
61
|
+
campaign.CampaignID.should be == "827dbbd2161ea9989fa11ad562c66937"
|
62
|
+
campaign.Name.should be == "Magic Issue One"
|
63
|
+
campaign.Subject.should be == "Magic Issue One"
|
64
|
+
campaign.DateCreated.should be == "2011-05-24 10:37:00"
|
65
|
+
campaign.PreviewURL.should be == "http://createsend.com/t/r-DD543521A87C9B8B"
|
66
|
+
campaign.PreviewTextURL.should be == "http://createsend.com/t/r-DD543521A87C9B8B/t"
|
67
|
+
campaign.FromName.should be == 'My Name'
|
68
|
+
campaign.FromEmail.should be == 'myemail@example.com'
|
69
|
+
campaign.ReplyTo.should be == 'myemail@example.com'
|
70
|
+
campaign.Tags.should be == ['tagexample']
|
59
71
|
end
|
60
72
|
|
61
73
|
should "get all drafts" do
|
62
74
|
stub_get(@auth, "clients/#{@client.client_id}/drafts.json", "drafts.json")
|
63
75
|
drafts = @client.drafts
|
64
|
-
drafts.size.should == 2
|
65
|
-
drafts.first
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
drafts.size.should be == 2
|
77
|
+
draft = drafts.first
|
78
|
+
draft.CampaignID.should be == '7c7424792065d92627139208c8c01db1'
|
79
|
+
draft.Name.should be == 'Draft One'
|
80
|
+
draft.Subject.should be == 'Draft One'
|
81
|
+
draft.DateCreated.should be == '2010-08-19 16:08:00'
|
82
|
+
draft.PreviewURL.should be == 'http://createsend.com/t/r-E97A7BB2E6983DA1'
|
83
|
+
draft.PreviewTextURL.should be == 'http://createsend.com/t/r-E97A7BB2E6983DA1/t'
|
84
|
+
draft.FromName.should be == 'My Name'
|
85
|
+
draft.FromEmail.should be == 'myemail@example.com'
|
86
|
+
draft.ReplyTo.should be == 'myemail@example.com'
|
87
|
+
draft.Tags.should be == ['tagexample']
|
88
|
+
end
|
89
|
+
|
90
|
+
should "get all client tags" do
|
91
|
+
stub_get(@auth, "clients/#{@client.client_id}/tags.json", "tags.json")
|
92
|
+
tags = @client.tags
|
93
|
+
tags.size.should be == 2
|
94
|
+
tag = tags.first
|
95
|
+
tag.Name.should be == 'Tag One'
|
96
|
+
tag.NumberOfCampaigns.should be == '120'
|
74
97
|
end
|
75
98
|
|
76
99
|
should "get all lists" do
|
77
100
|
stub_get(@auth, "clients/#{@client.client_id}/lists.json", "lists.json")
|
78
101
|
lists = @client.lists
|
79
|
-
lists.size.should == 2
|
80
|
-
lists.first.ListID.should == 'a58ee1d3039b8bec838e6d1482a8a965'
|
81
|
-
lists.first.Name.should == 'List One'
|
102
|
+
lists.size.should be == 2
|
103
|
+
lists.first.ListID.should be == 'a58ee1d3039b8bec838e6d1482a8a965'
|
104
|
+
lists.first.Name.should be == 'List One'
|
82
105
|
end
|
83
106
|
|
84
107
|
should "get all lists to which a subscriber with a particular email address belongs" do
|
85
108
|
email = "valid@example.com"
|
86
109
|
stub_get(@auth, "clients/#{@client.client_id}/listsforemail.json?email=#{ERB::Util.url_encode(email)}", "listsforemail.json")
|
87
110
|
lists = @client.lists_for_email(email)
|
88
|
-
lists.size.should == 2
|
89
|
-
lists.first.ListID.should == 'ab4a2b57c7c8f1ba62f898a1af1a575b'
|
90
|
-
lists.first.ListName.should == 'List Number One'
|
91
|
-
lists.first.SubscriberState.should == 'Active'
|
92
|
-
lists.first.DateSubscriberAdded.should == '2012-08-20 22:32:00'
|
111
|
+
lists.size.should be == 2
|
112
|
+
lists.first.ListID.should be == 'ab4a2b57c7c8f1ba62f898a1af1a575b'
|
113
|
+
lists.first.ListName.should be == 'List Number One'
|
114
|
+
lists.first.SubscriberState.should be == 'Active'
|
115
|
+
lists.first.DateSubscriberAdded.should be == '2012-08-20 22:32:00'
|
93
116
|
end
|
94
117
|
|
95
118
|
should "get all segments for a client" do
|
96
119
|
stub_get(@auth, "clients/#{@client.client_id}/segments.json", "segments.json")
|
97
120
|
segments = @client.segments
|
98
|
-
segments.size.should == 2
|
99
|
-
segments.first.ListID.should == 'a58ee1d3039b8bec838e6d1482a8a965'
|
100
|
-
segments.first.SegmentID.should == '46aa5e01fd43381863d4e42cf277d3a9'
|
101
|
-
segments.first.Title.should == 'Segment One'
|
121
|
+
segments.size.should be == 2
|
122
|
+
segments.first.ListID.should be == 'a58ee1d3039b8bec838e6d1482a8a965'
|
123
|
+
segments.first.SegmentID.should be == '46aa5e01fd43381863d4e42cf277d3a9'
|
124
|
+
segments.first.Title.should be == 'Segment One'
|
102
125
|
end
|
103
126
|
|
104
127
|
should "get suppression list" do
|
105
128
|
stub_get(@auth, "clients/#{@client.client_id}/suppressionlist.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc", "suppressionlist.json")
|
106
129
|
res = @client.suppressionlist
|
107
|
-
res.ResultsOrderedBy.should == "email"
|
108
|
-
res.OrderDirection.should == "asc"
|
109
|
-
res.PageNumber.should == 1
|
110
|
-
res.PageSize.should == 1000
|
111
|
-
res.RecordsOnThisPage.should == 5
|
112
|
-
res.TotalNumberOfRecords.should == 5
|
113
|
-
res.NumberOfPages.should == 1
|
114
|
-
res.Results.size.should == 5
|
115
|
-
res.Results.first.SuppressionReason.should == "Unsubscribed"
|
116
|
-
res.Results.first.EmailAddress.should == "example+1@example.com"
|
117
|
-
res.Results.first.Date.should == "2010-10-26 10:55:31"
|
118
|
-
res.Results.first.State.should == "Suppressed"
|
130
|
+
res.ResultsOrderedBy.should be == "email"
|
131
|
+
res.OrderDirection.should be == "asc"
|
132
|
+
res.PageNumber.should be == 1
|
133
|
+
res.PageSize.should be == 1000
|
134
|
+
res.RecordsOnThisPage.should be == 5
|
135
|
+
res.TotalNumberOfRecords.should be == 5
|
136
|
+
res.NumberOfPages.should be == 1
|
137
|
+
res.Results.size.should be == 5
|
138
|
+
res.Results.first.SuppressionReason.should be == "Unsubscribed"
|
139
|
+
res.Results.first.EmailAddress.should be == "example+1@example.com"
|
140
|
+
res.Results.first.Date.should be == "2010-10-26 10:55:31"
|
141
|
+
res.Results.first.State.should be == "Suppressed"
|
119
142
|
end
|
120
143
|
|
121
144
|
should "suppress a single email address" do
|
122
145
|
email = "example@example.com"
|
123
146
|
stub_post(@auth, "clients/#{@client.client_id}/suppress.json", nil)
|
124
|
-
|
147
|
+
@client.suppress email
|
125
148
|
end
|
126
149
|
|
127
150
|
should "suppress multiple email address" do
|
128
151
|
stub_post(@auth, "clients/#{@client.client_id}/suppress.json", nil)
|
129
|
-
|
152
|
+
@client.suppress [ "one@example.com", "two@example.com" ]
|
130
153
|
end
|
131
154
|
|
132
155
|
should "unsuppress an email address" do
|
133
156
|
email = "example@example.com"
|
134
157
|
stub_put(@auth, "clients/#{@client.client_id}/unsuppress.json?email=#{ERB::Util.url_encode(email)}", nil)
|
135
|
-
|
158
|
+
@client.unsuppress email
|
136
159
|
end
|
137
160
|
|
138
161
|
should "get all people" do
|
139
162
|
stub_get(@auth, "clients/#{@client.client_id}/people.json", "people.json")
|
140
163
|
people = @client.people
|
141
|
-
people.size.should == 2
|
142
|
-
people.first.EmailAddress.should == "person1@blackhole.com"
|
143
|
-
people.first.Name.should == "Person One"
|
144
|
-
people.first.Status.should == "Active"
|
145
|
-
people.first.AccessLevel.should == 31
|
164
|
+
people.size.should be == 2
|
165
|
+
people.first.EmailAddress.should be == "person1@blackhole.com"
|
166
|
+
people.first.Name.should be == "Person One"
|
167
|
+
people.first.Status.should be == "Active"
|
168
|
+
people.first.AccessLevel.should be == 31
|
146
169
|
end
|
147
170
|
|
148
171
|
should "get all templates" do
|
149
172
|
stub_get(@auth, "clients/#{@client.client_id}/templates.json", "templates.json")
|
150
173
|
templates = @client.templates
|
151
|
-
templates.size.should == 2
|
152
|
-
templates.first.TemplateID.should == '5cac213cf061dd4e008de5a82b7a3621'
|
153
|
-
templates.first.Name.should == 'Template One'
|
174
|
+
templates.size.should be == 2
|
175
|
+
templates.first.TemplateID.should be == '5cac213cf061dd4e008de5a82b7a3621'
|
176
|
+
templates.first.Name.should be == 'Template One'
|
154
177
|
end
|
155
178
|
|
156
179
|
should "set primary contact" do
|
157
180
|
email = 'person@blackhole.com'
|
158
181
|
stub_put(@auth, "clients/#{@client.client_id}/primarycontact.json?email=#{ERB::Util.url_encode(email)}", 'client_set_primary_contact.json')
|
159
182
|
result = @client.set_primary_contact email
|
160
|
-
result.EmailAddress.should == email
|
183
|
+
result.EmailAddress.should be == email
|
161
184
|
end
|
162
185
|
|
163
186
|
should "get primary contact" do
|
164
187
|
stub_get(@auth, "clients/#{@client.client_id}/primarycontact.json", 'client_get_primary_contact.json')
|
165
188
|
result = @client.get_primary_contact
|
166
|
-
result.EmailAddress.should == 'person@blackhole.com'
|
189
|
+
result.EmailAddress.should be == 'person@blackhole.com'
|
167
190
|
end
|
168
191
|
|
169
192
|
should "set basics" do
|
@@ -180,37 +203,37 @@ class ClientTest < Test::Unit::TestCase
|
|
180
203
|
stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
|
181
204
|
@client.set_monthly_billing "CAD", true, 150
|
182
205
|
request = FakeWeb.last_request.body
|
183
|
-
request.include?("\"Currency\":\"CAD\"").should == true
|
184
|
-
request.include?("\"ClientPays\":true").should == true
|
185
|
-
request.include?("\"MarkupPercentage\":150").should == true
|
186
|
-
request.include?("\"MonthlyScheme\":null").should == true
|
206
|
+
request.include?("\"Currency\":\"CAD\"").should be == true
|
207
|
+
request.include?("\"ClientPays\":true").should be == true
|
208
|
+
request.include?("\"MarkupPercentage\":150").should be == true
|
209
|
+
request.include?("\"MonthlyScheme\":null").should be == true
|
187
210
|
end
|
188
211
|
|
189
212
|
should "set monthly billing (basic)" do
|
190
213
|
stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
|
191
214
|
@client.set_monthly_billing "CAD", true, 150, "Basic"
|
192
215
|
request = FakeWeb.last_request.body
|
193
|
-
request.include?("\"Currency\":\"CAD\"").should == true
|
194
|
-
request.include?("\"ClientPays\":true").should == true
|
195
|
-
request.include?("\"MarkupPercentage\":150").should == true
|
196
|
-
request.include?("\"MonthlyScheme\":\"Basic\"").should == true
|
216
|
+
request.include?("\"Currency\":\"CAD\"").should be == true
|
217
|
+
request.include?("\"ClientPays\":true").should be == true
|
218
|
+
request.include?("\"MarkupPercentage\":150").should be == true
|
219
|
+
request.include?("\"MonthlyScheme\":\"Basic\"").should be == true
|
197
220
|
end
|
198
221
|
|
199
222
|
should "set monthly billing (unlimited)" do
|
200
223
|
stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
|
201
224
|
@client.set_monthly_billing "CAD", false, 120, "Unlimited"
|
202
225
|
request = FakeWeb.last_request.body
|
203
|
-
request.include?("\"Currency\":\"CAD\"").should == true
|
204
|
-
request.include?("\"ClientPays\":false").should == true
|
205
|
-
request.include?("\"MarkupPercentage\":120").should == true
|
206
|
-
request.include?("\"MonthlyScheme\":\"Unlimited\"").should == true
|
226
|
+
request.include?("\"Currency\":\"CAD\"").should be == true
|
227
|
+
request.include?("\"ClientPays\":false").should be == true
|
228
|
+
request.include?("\"MarkupPercentage\":120").should be == true
|
229
|
+
request.include?("\"MonthlyScheme\":\"Unlimited\"").should be == true
|
207
230
|
end
|
208
231
|
|
209
232
|
should "transfer credits to a client" do
|
210
233
|
stub_post(@auth, "clients/#{@client.client_id}/credits.json", "transfer_credits.json")
|
211
234
|
result = @client.transfer_credits 200, false
|
212
|
-
result.AccountCredits.should == 800
|
213
|
-
result.ClientCredits.should == 200
|
235
|
+
result.AccountCredits.should be == 800
|
236
|
+
result.ClientCredits.should be == 200
|
214
237
|
end
|
215
238
|
|
216
239
|
should "delete a client" do
|
@@ -221,10 +244,10 @@ class ClientTest < Test::Unit::TestCase
|
|
221
244
|
should "get all journeys" do
|
222
245
|
stub_get(@auth, "clients/#{@client.client_id}/journeys.json", "journeys.json")
|
223
246
|
lists = @client.journeys
|
224
|
-
lists.size.should == 3
|
225
|
-
lists.first.ListID.should == 'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a'
|
226
|
-
lists.first.Name.should == 'Journey One'
|
227
|
-
lists.first.Status.should == 'Not started'
|
247
|
+
lists.size.should be == 3
|
248
|
+
lists.first.ListID.should be == 'a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a'
|
249
|
+
lists.first.Name.should be == 'Journey One'
|
250
|
+
lists.first.Status.should be == 'Not started'
|
228
251
|
end
|
229
252
|
end
|
230
253
|
end
|
data/test/createsend_test.rb
CHANGED
@@ -15,13 +15,13 @@ class CreateSendTest < Test::Unit::TestCase
|
|
15
15
|
:refresh_token => @refresh_token
|
16
16
|
}
|
17
17
|
cs = CreateSend::CreateSend.new auth
|
18
|
-
cs.auth_details.should == auth
|
18
|
+
cs.auth_details.should be == auth
|
19
19
|
end
|
20
20
|
|
21
21
|
should "authenticate using an api key" do
|
22
22
|
auth = {:api_key => @api_key}
|
23
23
|
cs = CreateSend::CreateSend.new auth
|
24
|
-
cs.auth_details.should == auth
|
24
|
+
cs.auth_details.should be == auth
|
25
25
|
end
|
26
26
|
|
27
27
|
should "get the authorization url without state included" do
|
@@ -29,7 +29,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
29
29
|
redirect_uri = 'http://example.com/auth'
|
30
30
|
scope = 'ViewReports,CreateCampaigns,SendCampaigns'
|
31
31
|
url = CreateSend::CreateSend.authorize_url(client_id, redirect_uri, scope)
|
32
|
-
url.should == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns"
|
32
|
+
url.should be == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns"
|
33
33
|
end
|
34
34
|
|
35
35
|
should "get the authorization url with state included" do
|
@@ -38,7 +38,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
38
38
|
scope = 'ViewReports,CreateCampaigns,SendCampaigns'
|
39
39
|
state = 89879287
|
40
40
|
url = CreateSend::CreateSend.authorize_url(client_id, redirect_uri, scope, state)
|
41
|
-
url.should == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns&state=89879287"
|
41
|
+
url.should be == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns&state=89879287"
|
42
42
|
end
|
43
43
|
|
44
44
|
should "exchange an OAuth token for an access token, 'expires in' value, and refresh token" do
|
@@ -53,10 +53,10 @@ class CreateSendTest < Test::Unit::TestCase
|
|
53
53
|
access_token, expires_in, refresh_token = CreateSend::CreateSend.exchange_token(
|
54
54
|
client_id, client_secret, redirect_uri, code)
|
55
55
|
|
56
|
-
FakeWeb.last_request.body.should == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=jdiwouo8uowi9o9o"
|
57
|
-
access_token.should == "SlAV32hkKG"
|
58
|
-
expires_in.should == 1209600
|
59
|
-
refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
|
56
|
+
FakeWeb.last_request.body.should be == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=jdiwouo8uowi9o9o"
|
57
|
+
access_token.should be == "SlAV32hkKG"
|
58
|
+
expires_in.should be == 1209600
|
59
|
+
refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
|
60
60
|
end
|
61
61
|
|
62
62
|
should "raise an error when an attempt to exchange an OAuth token for an access token fails" do
|
@@ -68,10 +68,10 @@ class CreateSendTest < Test::Unit::TestCase
|
|
68
68
|
:body => fixture_file("oauth_exchange_token_error.json"),
|
69
69
|
:content_type => "application/json; charset=utf-8" }
|
70
70
|
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
|
71
|
-
lambda {
|
71
|
+
lambda { CreateSend::CreateSend.exchange_token(
|
72
72
|
client_id, client_secret, redirect_uri, code) }.should raise_error(
|
73
73
|
Exception, 'Error exchanging code for access token: invalid_grant - Specified code was invalid or expired')
|
74
|
-
FakeWeb.last_request.body.should == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=invalidcode"
|
74
|
+
FakeWeb.last_request.body.should be == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=invalidcode"
|
75
75
|
end
|
76
76
|
|
77
77
|
should "refresh an access token given a refresh token" do
|
@@ -82,10 +82,10 @@ class CreateSendTest < Test::Unit::TestCase
|
|
82
82
|
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
|
83
83
|
new_access_token, new_expires_in, new_refresh_token = CreateSend::CreateSend.refresh_access_token refresh_token
|
84
84
|
|
85
|
-
FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
|
86
|
-
new_access_token.should == "SlAV32hkKG2e12e"
|
87
|
-
new_expires_in.should == 1209600
|
88
|
-
new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
|
85
|
+
FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
|
86
|
+
new_access_token.should be == "SlAV32hkKG2e12e"
|
87
|
+
new_expires_in.should be == 1209600
|
88
|
+
new_refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
|
89
89
|
end
|
90
90
|
|
91
91
|
should "raise an error when an attempt to refresh an access token fails" do
|
@@ -94,10 +94,10 @@ class CreateSendTest < Test::Unit::TestCase
|
|
94
94
|
:body => fixture_file("oauth_refresh_token_error.json"),
|
95
95
|
:content_type => "application/json; charset=utf-8" }
|
96
96
|
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
|
97
|
-
lambda {
|
97
|
+
lambda { CreateSend::CreateSend.refresh_access_token(
|
98
98
|
refresh_token) }.should raise_error(
|
99
99
|
Exception, 'Error refreshing access token: invalid_grant - Specified refresh_token was invalid or expired')
|
100
|
-
FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
|
100
|
+
FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
@@ -120,11 +120,11 @@ class CreateSendTest < Test::Unit::TestCase
|
|
120
120
|
cs = CreateSend::CreateSend.new @auth
|
121
121
|
new_access_token, new_expires_in, new_refresh_token = cs.refresh_token
|
122
122
|
|
123
|
-
FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(@auth[:refresh_token])}"
|
124
|
-
new_access_token.should == "SlAV32hkKG2e12e"
|
125
|
-
new_expires_in.should == 1209600
|
126
|
-
new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
|
127
|
-
cs.auth_details.should == {
|
123
|
+
FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(@auth[:refresh_token])}"
|
124
|
+
new_access_token.should be == "SlAV32hkKG2e12e"
|
125
|
+
new_expires_in.should be == 1209600
|
126
|
+
new_refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
|
127
|
+
cs.auth_details.should be == {
|
128
128
|
:access_token => new_access_token,
|
129
129
|
:refresh_token => new_refresh_token
|
130
130
|
}
|
@@ -132,19 +132,19 @@ class CreateSendTest < Test::Unit::TestCase
|
|
132
132
|
|
133
133
|
should "raise an error when an attempt to refresh the access token is made but refresh token is nil" do
|
134
134
|
cs = CreateSend::CreateSend.new :access_token => 'any token', :refresh_token => nil
|
135
|
-
lambda {
|
135
|
+
lambda { cs.refresh_token }.should raise_error(
|
136
136
|
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
|
137
137
|
end
|
138
138
|
|
139
139
|
should "raise an error when an attempt to refresh the access token is made but no there was no refresh token passed in" do
|
140
140
|
cs = CreateSend::CreateSend.new :access_token => 'any token'
|
141
|
-
lambda {
|
141
|
+
lambda { cs.refresh_token }.should raise_error(
|
142
142
|
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
|
143
143
|
end
|
144
144
|
|
145
145
|
should "raise an error when an attempt to refresh the access token is made but no there was no auth hash passed in" do
|
146
146
|
cs = CreateSend::CreateSend.new
|
147
|
-
lambda {
|
147
|
+
lambda { cs.refresh_token }.should raise_error(
|
148
148
|
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
|
149
149
|
end
|
150
150
|
|
@@ -155,26 +155,26 @@ class CreateSendTest < Test::Unit::TestCase
|
|
155
155
|
:body => fixture_file("oauth_refresh_token_error.json"),
|
156
156
|
:content_type => "application/json; charset=utf-8" }
|
157
157
|
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
|
158
|
-
lambda {
|
158
|
+
lambda { refresh_token = cs.refresh_token }.should raise_error(
|
159
159
|
Exception, 'Error refreshing access token: invalid_grant - Specified refresh_token was invalid or expired')
|
160
160
|
end
|
161
161
|
|
162
162
|
should "raise a CreateSend::InvalidOAuthToken error when an access token is invalid" do
|
163
163
|
cs = CreateSend::CreateSend.new @auth
|
164
164
|
stub_get(@auth, "countries.json", "invalid_oauth_token_api_error.json", ["401", "Unauthorized"])
|
165
|
-
lambda {
|
165
|
+
lambda { cs.countries }.should raise_error(CreateSend::InvalidOAuthToken)
|
166
166
|
end
|
167
167
|
|
168
168
|
should "raise a CreateSend::ExpiredOAuthToken error when an access token is expired" do
|
169
169
|
cs = CreateSend::CreateSend.new @auth
|
170
170
|
stub_get(@auth, "countries.json", "expired_oauth_token_api_error.json", ["401", "Unauthorized"])
|
171
|
-
lambda {
|
171
|
+
lambda { cs.countries }.should raise_error(CreateSend::ExpiredOAuthToken)
|
172
172
|
end
|
173
173
|
|
174
174
|
should "raise a CreateSend::RevokedOAuthToken error when an access token is revoked" do
|
175
175
|
cs = CreateSend::CreateSend.new @auth
|
176
176
|
stub_get(@auth, "countries.json", "revoked_oauth_token_api_error.json", ["401", "Unauthorized"])
|
177
|
-
lambda {
|
177
|
+
lambda { cs.countries }.should raise_error(CreateSend::RevokedOAuthToken)
|
178
178
|
end
|
179
179
|
|
180
180
|
end
|
@@ -185,76 +185,76 @@ class CreateSendTest < Test::Unit::TestCase
|
|
185
185
|
end
|
186
186
|
|
187
187
|
should "include the correct user agent string when making a call" do
|
188
|
-
CreateSend::CreateSend.headers["User-Agent"].should ==
|
188
|
+
CreateSend::CreateSend.headers["User-Agent"].should be ==
|
189
189
|
"createsend-ruby-#{CreateSend::VERSION}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}-#{RUBY_PLATFORM}"
|
190
190
|
stub_get(@auth, "clients.json", "clients.json")
|
191
191
|
clients = @cs.clients
|
192
|
-
clients.size.should == 2
|
192
|
+
clients.size.should be == 2
|
193
193
|
end
|
194
194
|
|
195
195
|
should "allow a custom user agent string to be set when making a call" do
|
196
196
|
CreateSend::CreateSend.user_agent "custom user agent"
|
197
|
-
CreateSend::CreateSend.headers["User-Agent"].should == "custom user agent"
|
197
|
+
CreateSend::CreateSend.headers["User-Agent"].should be == "custom user agent"
|
198
198
|
stub_get(@auth, "clients.json", "clients.json")
|
199
199
|
clients = @cs.clients
|
200
|
-
clients.size.should == 2
|
200
|
+
clients.size.should be == 2
|
201
201
|
CreateSend::CreateSend.user_agent nil
|
202
202
|
end
|
203
203
|
|
204
204
|
should "get all clients" do
|
205
205
|
stub_get(@auth, "clients.json", "clients.json")
|
206
206
|
clients = @cs.clients
|
207
|
-
clients.size.should == 2
|
208
|
-
clients.first.ClientID.should == '4a397ccaaa55eb4e6aa1221e1e2d7122'
|
209
|
-
clients.first.Name.should == 'Client One'
|
207
|
+
clients.size.should be == 2
|
208
|
+
clients.first.ClientID.should be == '4a397ccaaa55eb4e6aa1221e1e2d7122'
|
209
|
+
clients.first.Name.should be == 'Client One'
|
210
210
|
end
|
211
211
|
|
212
212
|
should "get billing details" do
|
213
213
|
stub_get(@auth, "billingdetails.json", "billingdetails.json")
|
214
214
|
bd = @cs.billing_details
|
215
|
-
bd.Credits.should == 3021
|
215
|
+
bd.Credits.should be == 3021
|
216
216
|
end
|
217
217
|
|
218
218
|
should "get all countries" do
|
219
219
|
stub_get(@auth, "countries.json", "countries.json")
|
220
220
|
countries = @cs.countries
|
221
|
-
countries.size.should == 245
|
221
|
+
countries.size.should be == 245
|
222
222
|
assert countries.include? "Australia"
|
223
223
|
end
|
224
224
|
|
225
225
|
should "get system date" do
|
226
226
|
stub_get(@auth, "systemdate.json", "systemdate.json")
|
227
227
|
systemdate = @cs.systemdate.SystemDate
|
228
|
-
systemdate.should == "2010-10-15 09:27:00"
|
228
|
+
systemdate.should be == "2010-10-15 09:27:00"
|
229
229
|
end
|
230
230
|
|
231
231
|
should "get all timezones" do
|
232
232
|
stub_get(@auth, "timezones.json", "timezones.json")
|
233
233
|
timezones = @cs.timezones
|
234
|
-
timezones.size.should == 97
|
234
|
+
timezones.size.should be == 97
|
235
235
|
assert timezones.include? "(GMT+12:00) Fiji"
|
236
236
|
end
|
237
237
|
|
238
238
|
should "get all administrators" do
|
239
239
|
stub_get(@auth, "admins.json", "administrators.json")
|
240
240
|
administrators = @cs.administrators
|
241
|
-
administrators.size.should == 2
|
242
|
-
administrators.first.EmailAddress.should == "admin1@blackhole.com"
|
243
|
-
administrators.first.Name.should == 'Admin One'
|
244
|
-
administrators.first.Status.should == 'Active'
|
241
|
+
administrators.size.should be == 2
|
242
|
+
administrators.first.EmailAddress.should be == "admin1@blackhole.com"
|
243
|
+
administrators.first.Name.should be == 'Admin One'
|
244
|
+
administrators.first.Status.should be == 'Active'
|
245
245
|
end
|
246
246
|
|
247
247
|
should "set primary contact" do
|
248
248
|
email = 'admin@blackhole.com'
|
249
249
|
stub_put(@auth, "primarycontact.json?email=#{ERB::Util.url_encode(email)}", 'admin_set_primary_contact.json')
|
250
250
|
result = @cs.set_primary_contact email
|
251
|
-
result.EmailAddress.should == email
|
251
|
+
result.EmailAddress.should be == email
|
252
252
|
end
|
253
253
|
|
254
254
|
should "get primary contact" do
|
255
255
|
stub_get(@auth, "primarycontact.json", 'admin_get_primary_contact.json')
|
256
256
|
result = @cs.get_primary_contact
|
257
|
-
result.EmailAddress.should == 'admin@blackhole.com'
|
257
|
+
result.EmailAddress.should be == 'admin@blackhole.com'
|
258
258
|
end
|
259
259
|
|
260
260
|
should "get an external session url" do
|
@@ -265,7 +265,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
265
265
|
client_id = "9q8uw9d8u9wud"
|
266
266
|
stub_put(@auth, "externalsession.json", "external_session.json")
|
267
267
|
result = @cs.external_session_url email, chrome, url, integrator_id, client_id
|
268
|
-
result.SessionUrl.should == "https://external1.createsend.com/cd/create/ABCDEF12/DEADBEEF?url=FEEDDAD1"
|
268
|
+
result.SessionUrl.should be == "https://external1.createsend.com/cd/create/ABCDEF12/DEADBEEF?url=FEEDDAD1"
|
269
269
|
end
|
270
270
|
|
271
271
|
end
|
@@ -287,7 +287,7 @@ class CreateSendTest < Test::Unit::TestCase
|
|
287
287
|
context "#{status.first}, a get" do
|
288
288
|
should "raise a #{exception.name} error" do
|
289
289
|
stub_get(@auth, "countries.json", (status.first == '400' or status.first == '401') ? 'custom_api_error.json' : nil, status)
|
290
|
-
lambda {
|
290
|
+
lambda { @cs.countries }.should raise_error(exception)
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|