createsend-sendowlfork 6.1.0.pre.hashie5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +7 -0
  5. data/CONTRIBUTING.md +8 -0
  6. data/Gemfile +3 -0
  7. data/HISTORY.md +299 -0
  8. data/LICENSE +19 -0
  9. data/README.md +220 -0
  10. data/RELEASE.md +53 -0
  11. data/Rakefile +24 -0
  12. data/createsend.gemspec +31 -0
  13. data/lib/createsend/administrator.rb +49 -0
  14. data/lib/createsend/cacert.pem +3849 -0
  15. data/lib/createsend/campaign.rb +202 -0
  16. data/lib/createsend/client.rb +224 -0
  17. data/lib/createsend/createsend.rb +291 -0
  18. data/lib/createsend/journey.rb +58 -0
  19. data/lib/createsend/list.rb +258 -0
  20. data/lib/createsend/person.rb +59 -0
  21. data/lib/createsend/segment.rb +81 -0
  22. data/lib/createsend/subscriber.rb +113 -0
  23. data/lib/createsend/template.rb +42 -0
  24. data/lib/createsend/transactional_classic_email.rb +32 -0
  25. data/lib/createsend/transactional_smart_email.rb +31 -0
  26. data/lib/createsend/transactional_timeline.rb +45 -0
  27. data/lib/createsend/version.rb +3 -0
  28. data/lib/createsend.rb +17 -0
  29. data/samples/authentication_sample.rb +64 -0
  30. data/samples/clients_sample.rb +79 -0
  31. data/samples/journey_sample.rb +87 -0
  32. data/samples/lists_sample.rb +51 -0
  33. data/samples/segments_sample.rb +21 -0
  34. data/samples/subscribers_sample.rb +51 -0
  35. data/test/administrator_test.rb +37 -0
  36. data/test/campaign_test.rb +296 -0
  37. data/test/client_test.rb +253 -0
  38. data/test/createsend_test.rb +321 -0
  39. data/test/fixtures/active_subscribers.json +87 -0
  40. data/test/fixtures/add_admin.json +3 -0
  41. data/test/fixtures/add_person.json +3 -0
  42. data/test/fixtures/add_subscriber.json +1 -0
  43. data/test/fixtures/admin_details.json +5 -0
  44. data/test/fixtures/admin_get_primary_contact.json +3 -0
  45. data/test/fixtures/admin_set_primary_contact.json +3 -0
  46. data/test/fixtures/administrators.json +12 -0
  47. data/test/fixtures/billingdetails.json +3 -0
  48. data/test/fixtures/bounced_subscribers.json +20 -0
  49. data/test/fixtures/campaign_bounces.json +25 -0
  50. data/test/fixtures/campaign_clicks.json +50 -0
  51. data/test/fixtures/campaign_listsandsegments.json +15 -0
  52. data/test/fixtures/campaign_opens.json +71 -0
  53. data/test/fixtures/campaign_recipients.json +91 -0
  54. data/test/fixtures/campaign_spam.json +16 -0
  55. data/test/fixtures/campaign_summary.json +16 -0
  56. data/test/fixtures/campaign_unsubscribes.json +17 -0
  57. data/test/fixtures/campaigns.json +37 -0
  58. data/test/fixtures/client_details.json +28 -0
  59. data/test/fixtures/client_get_primary_contact.json +3 -0
  60. data/test/fixtures/client_set_primary_contact.json +3 -0
  61. data/test/fixtures/clients.json +10 -0
  62. data/test/fixtures/countries.json +247 -0
  63. data/test/fixtures/create_campaign.json +1 -0
  64. data/test/fixtures/create_client.json +1 -0
  65. data/test/fixtures/create_custom_field.json +1 -0
  66. data/test/fixtures/create_list.json +1 -0
  67. data/test/fixtures/create_list_webhook.json +1 -0
  68. data/test/fixtures/create_segment.json +1 -0
  69. data/test/fixtures/create_template.json +1 -0
  70. data/test/fixtures/custom_api_error.json +4 -0
  71. data/test/fixtures/custom_fields.json +23 -0
  72. data/test/fixtures/deleted_subscribers.json +61 -0
  73. data/test/fixtures/drafts.json +26 -0
  74. data/test/fixtures/email_client_usage.json +38 -0
  75. data/test/fixtures/expired_oauth_token_api_error.json +4 -0
  76. data/test/fixtures/external_session.json +3 -0
  77. data/test/fixtures/import_subscribers.json +7 -0
  78. data/test/fixtures/import_subscribers_partial_success.json +17 -0
  79. data/test/fixtures/invalid_oauth_token_api_error.json +4 -0
  80. data/test/fixtures/journey_bounces.json +35 -0
  81. data/test/fixtures/journey_clicks.json +35 -0
  82. data/test/fixtures/journey_opens.json +55 -0
  83. data/test/fixtures/journey_recipients.json +27 -0
  84. data/test/fixtures/journey_summary.json +18 -0
  85. data/test/fixtures/journey_unsubscribes.json +26 -0
  86. data/test/fixtures/journeys.json +20 -0
  87. data/test/fixtures/list_details.json +8 -0
  88. data/test/fixtures/list_stats.json +26 -0
  89. data/test/fixtures/list_webhooks.json +18 -0
  90. data/test/fixtures/lists.json +10 -0
  91. data/test/fixtures/listsforemail.json +14 -0
  92. data/test/fixtures/oauth_exchange_token.json +5 -0
  93. data/test/fixtures/oauth_exchange_token_error.json +4 -0
  94. data/test/fixtures/oauth_refresh_token_error.json +4 -0
  95. data/test/fixtures/people.json +14 -0
  96. data/test/fixtures/person_details.json +6 -0
  97. data/test/fixtures/refresh_oauth_token.json +5 -0
  98. data/test/fixtures/revoked_oauth_token_api_error.json +4 -0
  99. data/test/fixtures/scheduled_campaigns.json +30 -0
  100. data/test/fixtures/segment_details.json +24 -0
  101. data/test/fixtures/segment_subscribers.json +27 -0
  102. data/test/fixtures/segments.json +12 -0
  103. data/test/fixtures/subscriber_details.json +23 -0
  104. data/test/fixtures/subscriber_details_with_track_and_sms_pref.json +25 -0
  105. data/test/fixtures/subscriber_history.json +45 -0
  106. data/test/fixtures/suppressionlist.json +41 -0
  107. data/test/fixtures/systemdate.json +3 -0
  108. data/test/fixtures/tags.json +10 -0
  109. data/test/fixtures/template_details.json +6 -0
  110. data/test/fixtures/templates.json +14 -0
  111. data/test/fixtures/timezones.json +99 -0
  112. data/test/fixtures/transfer_credits.json +4 -0
  113. data/test/fixtures/tx_classicemail_groups.json +14 -0
  114. data/test/fixtures/tx_message_details.json +36 -0
  115. data/test/fixtures/tx_message_details_with_statistics.json +72 -0
  116. data/test/fixtures/tx_messages.json +38 -0
  117. data/test/fixtures/tx_messages_classic.json +15 -0
  118. data/test/fixtures/tx_messages_smart.json +15 -0
  119. data/test/fixtures/tx_resend_message.json +6 -0
  120. data/test/fixtures/tx_send_multiple.json +12 -0
  121. data/test/fixtures/tx_send_single.json +7 -0
  122. data/test/fixtures/tx_smartemail_details.json +23 -0
  123. data/test/fixtures/tx_smartemails.json +15 -0
  124. data/test/fixtures/tx_statistics_classic.json +14 -0
  125. data/test/fixtures/tx_statistics_smart.json +14 -0
  126. data/test/fixtures/unconfirmed_subscribers.json +43 -0
  127. data/test/fixtures/unsubscribed_subscribers.json +61 -0
  128. data/test/fixtures/update_custom_field.json +1 -0
  129. data/test/helper.rb +79 -0
  130. data/test/journey_test.rb +156 -0
  131. data/test/list_test.rb +288 -0
  132. data/test/person_test.rb +39 -0
  133. data/test/segment_test.rb +74 -0
  134. data/test/subscriber_test.rb +177 -0
  135. data/test/template_test.rb +36 -0
  136. data/test/transactional_classic_email_test.rb +60 -0
  137. data/test/transactional_smart_email_test.rb +83 -0
  138. data/test/transactional_timeline_test.rb +110 -0
  139. metadata +431 -0
@@ -0,0 +1,51 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'createsend'
3
+
4
+ class SubscribersSample
5
+ def initialize
6
+ raise 'CREATESEND_ACCESS_TOKEN env var missing' if ENV['CREATESEND_ACCESS_TOKEN'].nil?
7
+ raise 'CREATESEND_REFRESH_TOKEN env var missing' if ENV['CREATESEND_REFRESH_TOKEN'].nil?
8
+ raise 'CREATESEND_LIST_ID env var missing' if ENV['CREATESEND_LIST_ID'].nil?
9
+
10
+ @auth = {:access_token => ENV['CREATESEND_ACCESS_TOKEN'], :refresh_token => ENV['CREATESEND_REFRESH_TOKEN']}
11
+ end
12
+
13
+ def add_subscriber_without_mobile
14
+ @subscriberAdded = CreateSend::Subscriber.add @auth, ENV['CREATESEND_LIST_ID'], "subscriberNoMobile@example.com", "Subscriber", [], true, "Yes", false
15
+ end
16
+
17
+ def add_subscriber_with_mobile
18
+ @subscriberAdded = CreateSend::Subscriber.add @auth, ENV['CREATESEND_LIST_ID'], "subscriberWithMobile@example.com", "SubscriberWithMobile", [], true, "Yes", false, "+61423152523"
19
+ end
20
+
21
+ def add_subscriber_with_mobile_and_consent
22
+ @subscriberAdded = CreateSend::Subscriber.add @auth, ENV['CREATESEND_LIST_ID'], "subscriberWithMobileAndConsent@example.com", "SubscriberWithMobileAndConsent", [], true, "Yes", false, "+61423152523", "Yes"
23
+ end
24
+
25
+ def get_subscriber
26
+ @subscriber = CreateSend::Subscriber.get @auth, ENV['CREATESEND_LIST_ID'], "subscriberNoMobile@example.com"
27
+ end
28
+
29
+ def import_subscribers
30
+ subscribers = [
31
+ {"EmailAddress":"subscriberImport11@example.com","Name":"subscriberImport11", "ConsentToTrack":"Yes"},
32
+ {"EmailAddress":"subscriberImport12@example.com","Name":"subscriberImport12", "ConsentToTrack":"No", "MobileNumber":"+1612105111", "ConsentToSendSms":"Yes"},
33
+ {"EmailAddress":"subscriberImport13@example.com","Name":"subscriberImport13", "ConsentToTrack":"Yes", "MobileNumber":"+1612105112"}
34
+ ]
35
+ @subscribersImported = CreateSend::Subscriber.import(@auth, ENV['CREATESEND_LIST_ID'], subscribers, true, false, false)
36
+ end
37
+
38
+ def update_subscribers
39
+ @subscriber = CreateSend::Subscriber.new(@auth, ENV['CREATESEND_LIST_ID'], 'subscriberWithMobileAndConsent@example.com')
40
+ @subscriberUpdated = @subscriber.update("subscriberWithMobileAndConsent@example.com", "Subscriber With Mobile And Consent", [], true, "Yes", false, "+16175551218")
41
+ end
42
+ end
43
+
44
+ sample = SubscribersSample.new
45
+
46
+ puts "add_subscriber_without_mobile: #{sample.add_subscriber_without_mobile.to_json}\n\n"
47
+ puts "add_subscriber_with_mobile: #{sample.add_subscriber_with_mobile.to_json}\n\n"
48
+ puts "add_subscriber_with_mobile_and_consent: #{sample.add_subscriber_with_mobile_and_consent.to_json}\n\n"
49
+ puts "get subscribers: #{sample.get_subscriber.to_json}\n\n"
50
+ puts "import_subscribers: #{sample.import_subscribers.to_json}\n\n"
51
+ puts "update_subscribers: #{sample.update_subscribers.to_json}\n\n"
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class AdministratorTest < Test::Unit::TestCase
4
+ multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do
5
+ setup do
6
+ @admin = CreateSend::Administrator.new @auth, "admin@example.com"
7
+ end
8
+
9
+ should "get a administrator by email address" do
10
+ email = "admin@example.com"
11
+ stub_get(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", "admin_details.json")
12
+ admin = CreateSend::Administrator.get @auth, email
13
+ admin.EmailAddress.should be == email
14
+ admin.Name.should be == "Admin One"
15
+ admin.Status.should be == "Active"
16
+ end
17
+
18
+ should "add an administrator" do
19
+ stub_post(@auth, "admins.json", "add_admin.json")
20
+ result = CreateSend::Administrator.add @auth, "admin@example.com", "Admin"
21
+ result.EmailAddress.should be == "admin@example.com"
22
+ end
23
+
24
+ should "update an administrator" do
25
+ email = "admin@example.com"
26
+ new_email = "new_email_address@example.com"
27
+ stub_put(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", nil)
28
+ @admin.update new_email, "Admin Name"
29
+ @admin.email_address.should be == new_email
30
+ end
31
+
32
+ should "delete an admin" do
33
+ stub_delete(@auth, "admins.json?email=#{ERB::Util.url_encode(@admin.email_address)}", nil)
34
+ @admin.delete
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,296 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class CampaignTest < Test::Unit::TestCase
4
+ multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do
5
+ setup do
6
+ @campaign = CreateSend::Campaign.new @auth, '787y87y87y87y87y87y87'
7
+ end
8
+
9
+ should "create a campaign" do
10
+ client_id = '87y8d7qyw8d7yq8w7ydwqwd'
11
+ stub_post(@auth, "campaigns/#{client_id}.json", "create_campaign.json")
12
+ campaign_id = CreateSend::Campaign.create @auth, client_id, "subject", "name", "g'day", "good.day@example.com", "good.day@example.com",
13
+ "http://example.com/campaign.html", "http://example.com/campaign.txt", [ '7y12989e82ue98u2e', 'dh9w89q8w98wudwd989' ],
14
+ [ 'y78q9w8d9w8ud9q8uw', 'djw98quw9duqw98uwd98' ]
15
+ request = FakeWeb.last_request.body
16
+ request.include?("\"TextUrl\":\"http://example.com/campaign.txt\"").should be == true
17
+ campaign_id.should be == "787y87y87y87y87y87y87"
18
+ end
19
+
20
+ should "create a campaign with a nil text_url param" do
21
+ client_id = '87y8d7qyw8d7yq8w7ydwqwd'
22
+ stub_post(@auth, "campaigns/#{client_id}.json", "create_campaign.json")
23
+ campaign_id = CreateSend::Campaign.create @auth, client_id, "subject", "name", "g'day", "good.day@example.com", "good.day@example.com",
24
+ "http://example.com/campaign.html", nil, [ '7y12989e82ue98u2e', 'dh9w89q8w98wudwd989' ],
25
+ [ 'y78q9w8d9w8ud9q8uw', 'djw98quw9duqw98uwd98' ]
26
+ request = FakeWeb.last_request.body
27
+ request.include?("\"TextUrl\":null").should be == true
28
+ campaign_id.should be == "787y87y87y87y87y87y87"
29
+ end
30
+
31
+ should "create a campaign from a template" do
32
+ template_content = {
33
+ :Singlelines => [
34
+ {
35
+ :Content => "This is a heading",
36
+ :Href => "http://example.com/"
37
+ }
38
+ ],
39
+ :Multilines => [
40
+ {
41
+ :Content => "<p>This is example</p><p>multiline \
42
+ <a href=\"http://example.com\">content</a>...</p>"
43
+ }
44
+ ],
45
+ :Images => [
46
+ {
47
+ :Content => "http://example.com/image.png",
48
+ :Alt => "This is alt text for an image",
49
+ :Href => "http://example.com/"
50
+ }
51
+ ],
52
+ :Repeaters => [
53
+ {
54
+ :Items => [
55
+ {
56
+ :Layout => "My layout",
57
+ :Singlelines => [
58
+ {
59
+ :Content => "This is a repeater heading",
60
+ :Href => "http://example.com/"
61
+ }
62
+ ],
63
+ :Multilines => [
64
+ {
65
+ :Content => "<p>This is example</p><p>multiline \
66
+ <a href=\"http://example.com\">content</a>...</p>"
67
+ }
68
+ ],
69
+ :Images => [
70
+ {
71
+ :Content => "http://example.com/repeater-image.png",
72
+ :Alt => "This is alt text for a repeater image",
73
+ :Href => "http://example.com/"
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ }
79
+ ]
80
+ }
81
+
82
+ # template_content as defined above would be used to fill the content of
83
+ # a template with markup similar to the following:
84
+ #
85
+ # <html>
86
+ # <head><title>My Template</title></head>
87
+ # <body>
88
+ # <p><singleline>Enter heading...</singleline></p>
89
+ # <div><multiline>Enter description...</multiline></div>
90
+ # <img id="header-image" editable="true" width="500" />
91
+ # <repeater>
92
+ # <layout label="My layout">
93
+ # <div class="repeater-item">
94
+ # <p><singleline></singleline></p>
95
+ # <div><multiline></multiline></div>
96
+ # <img editable="true" width="500" />
97
+ # </div>
98
+ # </layout>
99
+ # </repeater>
100
+ # <p><unsubscribe>Unsubscribe</unsubscribe></p>
101
+ # </body>
102
+ # </html>
103
+
104
+ client_id = '87y8d7qyw8d7yq8w7ydwqwd'
105
+ stub_post(@auth, "campaigns/#{client_id}/fromtemplate.json", "create_campaign.json")
106
+ campaign_id = CreateSend::Campaign.create_from_template @auth, client_id, "subject", "name", "g'day", "good.day@example.com", "good.day@example.com",
107
+ [ '7y12989e82ue98u2e', 'dh9w89q8w98wudwd989' ], [ 'y78q9w8d9w8ud9q8uw', 'djw98quw9duqw98uwd98' ],
108
+ "7j8uw98udowy12989e8298u2e", template_content
109
+ campaign_id.should be == "787y87y87y87y87y87y87"
110
+ end
111
+
112
+ should "send a preview of a draft campaign to a single recipient" do
113
+ stub_post(@auth, "campaigns/#{@campaign.campaign_id}/sendpreview.json", nil)
114
+ @campaign.send_preview "test+89898u9@example.com", "random"
115
+ end
116
+
117
+ should "send a preview of a draft campaign to multiple recipients" do
118
+ stub_post(@auth, "campaigns/#{@campaign.campaign_id}/sendpreview.json", nil)
119
+ @campaign.send_preview [ "test+89898u9@example.com", "test+787y8y7y8@example.com" ], "random"
120
+ end
121
+
122
+ should "send a campaign" do
123
+ stub_post(@auth, "campaigns/#{@campaign.campaign_id}/send.json", nil)
124
+ @campaign.send "confirmation@example.com"
125
+ end
126
+
127
+ should "unschedule a campaign" do
128
+ stub_post(@auth, "campaigns/#{@campaign.campaign_id}/unschedule.json", nil)
129
+ @campaign.unschedule
130
+ end
131
+
132
+ should "delete a campaign" do
133
+ stub_delete(@auth, "campaigns/#{@campaign.campaign_id}.json", nil)
134
+ @campaign.delete
135
+ end
136
+
137
+ should "get the summary for a campaign" do
138
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/summary.json", "campaign_summary.json")
139
+ summary = @campaign.summary
140
+ summary.Name.should be == "Campaign Name"
141
+ summary.Recipients.should be == 5
142
+ summary.TotalOpened.should be == 10
143
+ summary.Clicks.should be == 0
144
+ summary.Unsubscribed.should be == 0
145
+ summary.Bounced.should be == 0
146
+ summary.UniqueOpened.should be == 5
147
+ summary.Mentions.should be == 23
148
+ summary.Forwards.should be == 11
149
+ summary.Likes.should be == 32
150
+ summary.WebVersionURL.should be == "http://createsend.com/t/r-3A433FC72FFE3B8B"
151
+ summary.WebVersionTextURL.should be == "http://createsend.com/t/r-3A433FC72FFE3B8B/t"
152
+ summary.WorldviewURL.should be == "http://client.createsend.com/reports/wv/r/3A433FC72FFE3B8B"
153
+ summary.SpamComplaints.should be == 23
154
+ end
155
+
156
+ should "get the email client usage for a campaign" do
157
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/emailclientusage.json", "email_client_usage.json")
158
+ ecu = @campaign.email_client_usage
159
+ ecu.size.should be == 6
160
+ ecu.first.Client.should be == "iOS Devices"
161
+ ecu.first.Version.should be == "iPhone"
162
+ ecu.first.Percentage.should be == 19.83
163
+ ecu.first.Subscribers.should be == 7056
164
+ end
165
+
166
+ should "get the lists and segments for a campaign" do
167
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/listsandsegments.json", "campaign_listsandsegments.json")
168
+ ls = @campaign.lists_and_segments
169
+ ls.Lists.size.should be == 1
170
+ ls.Segments.size.should be == 1
171
+ ls.Lists.first.Name.should be == "List One"
172
+ ls.Lists.first.ListID.should be == "a58ee1d3039b8bec838e6d1482a8a965"
173
+ ls.Segments.first.Title.should be == "Segment for campaign"
174
+ ls.Segments.first.ListID.should be == "2bea949d0bf96148c3e6a209d2e82060"
175
+ ls.Segments.first.SegmentID.should be == "dba84a225d5ce3d19105d7257baac46f"
176
+ end
177
+
178
+ should "get the recipients for a campaign" do
179
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/recipients.json?pagesize=20&orderfield=email&page=1&orderdirection=asc", "campaign_recipients.json")
180
+ res = @campaign.recipients page=1, page_size=20
181
+ res.ResultsOrderedBy.should be == "email"
182
+ res.OrderDirection.should be == "asc"
183
+ res.PageNumber.should be == 1
184
+ res.PageSize.should be == 20
185
+ res.RecordsOnThisPage.should be == 20
186
+ res.TotalNumberOfRecords.should be == 2200
187
+ res.NumberOfPages.should be == 110
188
+ res.Results.size.should be == 20
189
+ res.Results.first.EmailAddress.should be == "subs+6g76t7t0@example.com"
190
+ res.Results.first.ListID.should be == "a994a3caf1328a16af9a69a730eaa706"
191
+ end
192
+
193
+ should "get the opens for a campaign" do
194
+ min_date = "2010-01-01"
195
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/opens.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{ERB::Util.url_encode(min_date)}", "campaign_opens.json")
196
+ opens = @campaign.opens min_date
197
+ opens.Results.size.should be == 5
198
+ opens.Results.first.EmailAddress.should be == "subs+6576576576@example.com"
199
+ opens.Results.first.ListID.should be == "512a3bc577a58fdf689c654329b50fa0"
200
+ opens.Results.first.Date.should be == "2010-10-11 08:29:00"
201
+ opens.Results.first.IPAddress.should be == "192.168.126.87"
202
+ opens.Results.first.Latitude.should be == -33.8683
203
+ opens.Results.first.Longitude.should be == 151.2086
204
+ opens.Results.first.City.should be == "Sydney"
205
+ opens.Results.first.Region.should be == "New South Wales"
206
+ opens.Results.first.CountryCode.should be == "AU"
207
+ opens.Results.first.CountryName.should be == "Australia"
208
+ opens.ResultsOrderedBy.should be == "date"
209
+ opens.OrderDirection.should be == "asc"
210
+ opens.PageNumber.should be == 1
211
+ opens.PageSize.should be == 1000
212
+ opens.RecordsOnThisPage.should be == 5
213
+ opens.TotalNumberOfRecords.should be == 5
214
+ opens.NumberOfPages.should be == 1
215
+ end
216
+
217
+ should "get the subscriber clicks for a campaign" do
218
+ min_date = "2010-01-01"
219
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/clicks.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{ERB::Util.url_encode(min_date)}", "campaign_clicks.json")
220
+ clicks = @campaign.clicks min_date
221
+ clicks.Results.size.should be == 3
222
+ clicks.Results.first.EmailAddress.should be == "subs+6576576576@example.com"
223
+ clicks.Results.first.URL.should be == "http://video.google.com.au/?hl=en&tab=wv"
224
+ clicks.Results.first.ListID.should be == "512a3bc577a58fdf689c654329b50fa0"
225
+ clicks.Results.first.Date.should be == "2010-10-11 08:29:00"
226
+ clicks.Results.first.IPAddress.should be == "192.168.126.87"
227
+ clicks.Results.first.Latitude.should be == -33.8683
228
+ clicks.Results.first.Longitude.should be == 151.2086
229
+ clicks.Results.first.City.should be == "Sydney"
230
+ clicks.Results.first.Region.should be == "New South Wales"
231
+ clicks.Results.first.CountryCode.should be == "AU"
232
+ clicks.Results.first.CountryName.should be == "Australia"
233
+ clicks.ResultsOrderedBy.should be == "date"
234
+ clicks.OrderDirection.should be == "asc"
235
+ clicks.PageNumber.should be == 1
236
+ clicks.PageSize.should be == 1000
237
+ clicks.RecordsOnThisPage.should be == 3
238
+ clicks.TotalNumberOfRecords.should be == 3
239
+ clicks.NumberOfPages.should be == 1
240
+ end
241
+
242
+ should "get the unsubscribes for a campaign" do
243
+ min_date = "2010-01-01"
244
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/unsubscribes.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{ERB::Util.url_encode(min_date)}", "campaign_unsubscribes.json")
245
+ unsubscribes = @campaign.unsubscribes min_date
246
+ unsubscribes.Results.size.should be == 1
247
+ unsubscribes.Results.first.EmailAddress.should be == "subs+6576576576@example.com"
248
+ unsubscribes.Results.first.ListID.should be == "512a3bc577a58fdf689c654329b50fa0"
249
+ unsubscribes.Results.first.Date.should be == "2010-10-11 08:29:00"
250
+ unsubscribes.Results.first.IPAddress.should be == "192.168.126.87"
251
+ unsubscribes.ResultsOrderedBy.should be == "date"
252
+ unsubscribes.OrderDirection.should be == "asc"
253
+ unsubscribes.PageNumber.should be == 1
254
+ unsubscribes.PageSize.should be == 1000
255
+ unsubscribes.RecordsOnThisPage.should be == 1
256
+ unsubscribes.TotalNumberOfRecords.should be == 1
257
+ unsubscribes.NumberOfPages.should be == 1
258
+ end
259
+
260
+ should "get the spam complaints for a campaign" do
261
+ min_date = "2010-01-01"
262
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/spam.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{ERB::Util.url_encode(min_date)}", "campaign_spam.json")
263
+ spam = @campaign.spam min_date
264
+ spam.Results.size.should be == 1
265
+ spam.Results.first.EmailAddress.should be == "subs+6576576576@example.com"
266
+ spam.Results.first.ListID.should be == "512a3bc577a58fdf689c654329b50fa0"
267
+ spam.Results.first.Date.should be == "2010-10-11 08:29:00"
268
+ spam.ResultsOrderedBy.should be == "date"
269
+ spam.OrderDirection.should be == "asc"
270
+ spam.PageNumber.should be == 1
271
+ spam.PageSize.should be == 1000
272
+ spam.RecordsOnThisPage.should be == 1
273
+ spam.TotalNumberOfRecords.should be == 1
274
+ spam.NumberOfPages.should be == 1
275
+ end
276
+
277
+ should "get the bounces for a campaign" do
278
+ min_date = "2010-01-01"
279
+ stub_get(@auth, "campaigns/#{@campaign.campaign_id}/bounces.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{ERB::Util.url_encode(min_date)}", "campaign_bounces.json")
280
+ bounces = @campaign.bounces min_date
281
+ bounces.Results.size.should be == 2
282
+ bounces.Results.first.EmailAddress.should be == "asdf@softbouncemyemail.com"
283
+ bounces.Results.first.ListID.should be == "654523a5855b4a440bae3fb295641546"
284
+ bounces.Results.first.BounceType.should be == "Soft"
285
+ bounces.Results.first.Date.should be == "2010-07-02 16:46:00"
286
+ bounces.Results.first.Reason.should be == "Bounce - But No Email Address Returned "
287
+ bounces.ResultsOrderedBy.should be == "date"
288
+ bounces.OrderDirection.should be == "asc"
289
+ bounces.PageNumber.should be == 1
290
+ bounces.PageSize.should be == 1000
291
+ bounces.RecordsOnThisPage.should be == 2
292
+ bounces.TotalNumberOfRecords.should be == 2
293
+ bounces.NumberOfPages.should be == 1
294
+ end
295
+ end
296
+ end
@@ -0,0 +1,253 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ClientTest < Test::Unit::TestCase
4
+ multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do
5
+ setup do
6
+ @client = CreateSend::Client.new(@auth, '321iuhiuhi1u23hi2u3')
7
+ @client.client_id.should be == '321iuhiuhi1u23hi2u3'
8
+ end
9
+
10
+ should "create a client" do
11
+ stub_post(@auth, "clients.json", "create_client.json")
12
+ client_id = CreateSend::Client.create @auth, "Client Company Name", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
13
+ client_id.parsed_response.should be == "32a381c49a2df99f1d0c6f3c112352b9"
14
+ end
15
+
16
+ should "get details of a client" do
17
+ stub_get(@auth, "clients/#{@client.client_id}.json", "client_details.json")
18
+ cl = @client.details
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
+ end
27
+
28
+ should "get all campaigns" do
29
+ stub_get(@auth, "clients/#{@client.client_id}/campaigns.json?page=1&pagesize=1000&orderdirection=desc&sentfromdate=&senttodate=&tags=", "campaigns.json")
30
+ campaigns = @client.campaigns
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 == []
52
+ end
53
+
54
+ should "get scheduled campaigns" do
55
+ stub_get(@auth, "clients/#{@client.client_id}/scheduled.json", "scheduled_campaigns.json")
56
+ campaigns = @client.scheduled
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']
71
+ end
72
+
73
+ should "get all drafts" do
74
+ stub_get(@auth, "clients/#{@client.client_id}/drafts.json", "drafts.json")
75
+ drafts = @client.drafts
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'
97
+ end
98
+
99
+ should "get all lists" do
100
+ stub_get(@auth, "clients/#{@client.client_id}/lists.json", "lists.json")
101
+ lists = @client.lists
102
+ lists.size.should be == 2
103
+ lists.first.ListID.should be == 'a58ee1d3039b8bec838e6d1482a8a965'
104
+ lists.first.Name.should be == 'List One'
105
+ end
106
+
107
+ should "get all lists to which a subscriber with a particular email address belongs" do
108
+ email = "valid@example.com"
109
+ stub_get(@auth, "clients/#{@client.client_id}/listsforemail.json?email=#{ERB::Util.url_encode(email)}", "listsforemail.json")
110
+ lists = @client.lists_for_email(email)
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'
116
+ end
117
+
118
+ should "get all segments for a client" do
119
+ stub_get(@auth, "clients/#{@client.client_id}/segments.json", "segments.json")
120
+ segments = @client.segments
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'
125
+ end
126
+
127
+ should "get suppression list" do
128
+ stub_get(@auth, "clients/#{@client.client_id}/suppressionlist.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc", "suppressionlist.json")
129
+ res = @client.suppressionlist
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"
142
+ end
143
+
144
+ should "suppress a single email address" do
145
+ email = "example@example.com"
146
+ stub_post(@auth, "clients/#{@client.client_id}/suppress.json", nil)
147
+ @client.suppress email
148
+ end
149
+
150
+ should "suppress multiple email address" do
151
+ stub_post(@auth, "clients/#{@client.client_id}/suppress.json", nil)
152
+ @client.suppress [ "one@example.com", "two@example.com" ]
153
+ end
154
+
155
+ should "unsuppress an email address" do
156
+ email = "example@example.com"
157
+ stub_put(@auth, "clients/#{@client.client_id}/unsuppress.json?email=#{ERB::Util.url_encode(email)}", nil)
158
+ @client.unsuppress email
159
+ end
160
+
161
+ should "get all people" do
162
+ stub_get(@auth, "clients/#{@client.client_id}/people.json", "people.json")
163
+ people = @client.people
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
169
+ end
170
+
171
+ should "get all templates" do
172
+ stub_get(@auth, "clients/#{@client.client_id}/templates.json", "templates.json")
173
+ templates = @client.templates
174
+ templates.size.should be == 2
175
+ templates.first.TemplateID.should be == '5cac213cf061dd4e008de5a82b7a3621'
176
+ templates.first.Name.should be == 'Template One'
177
+ end
178
+
179
+ should "set primary contact" do
180
+ email = 'person@blackhole.com'
181
+ stub_put(@auth, "clients/#{@client.client_id}/primarycontact.json?email=#{ERB::Util.url_encode(email)}", 'client_set_primary_contact.json')
182
+ result = @client.set_primary_contact email
183
+ result.EmailAddress.should be == email
184
+ end
185
+
186
+ should "get primary contact" do
187
+ stub_get(@auth, "clients/#{@client.client_id}/primarycontact.json", 'client_get_primary_contact.json')
188
+ result = @client.get_primary_contact
189
+ result.EmailAddress.should be == 'person@blackhole.com'
190
+ end
191
+
192
+ should "set basics" do
193
+ stub_put(@auth, "clients/#{@client.client_id}/setbasics.json", nil)
194
+ @client.set_basics "Client Company Name", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
195
+ end
196
+
197
+ should "set payg billing" do
198
+ stub_put(@auth, "clients/#{@client.client_id}/setpaygbilling.json", nil)
199
+ @client.set_payg_billing "CAD", true, true, 150
200
+ end
201
+
202
+ should "set monthly billing (implicit)" do
203
+ stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
204
+ @client.set_monthly_billing "CAD", true, 150
205
+ request = FakeWeb.last_request.body
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
210
+ end
211
+
212
+ should "set monthly billing (basic)" do
213
+ stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
214
+ @client.set_monthly_billing "CAD", true, 150, "Basic"
215
+ request = FakeWeb.last_request.body
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
220
+ end
221
+
222
+ should "set monthly billing (unlimited)" do
223
+ stub_put(@auth, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
224
+ @client.set_monthly_billing "CAD", false, 120, "Unlimited"
225
+ request = FakeWeb.last_request.body
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
230
+ end
231
+
232
+ should "transfer credits to a client" do
233
+ stub_post(@auth, "clients/#{@client.client_id}/credits.json", "transfer_credits.json")
234
+ result = @client.transfer_credits 200, false
235
+ result.AccountCredits.should be == 800
236
+ result.ClientCredits.should be == 200
237
+ end
238
+
239
+ should "delete a client" do
240
+ stub_delete(@auth, "clients/#{@client.client_id}.json", nil)
241
+ @client.delete
242
+ end
243
+
244
+ should "get all journeys" do
245
+ stub_get(@auth, "clients/#{@client.client_id}/journeys.json", "journeys.json")
246
+ lists = @client.journeys
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'
251
+ end
252
+ end
253
+ end