createsend 4.1.1 → 5.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cf7d3f1ef06c9845b206a5a5440abe87f9982c7f
4
- data.tar.gz: 39e71bc8e300c0a240065664d70b9342edaafb0b
2
+ SHA256:
3
+ metadata.gz: a9e3ed5e50f1be54bdb680b399675fef8e72fc1e09d41264ec35d85de005b0ea
4
+ data.tar.gz: 1b39dc69dcb31589101712316897771aa15ba48c8ddd5c6bd6255c2352337db3
5
5
  SHA512:
6
- metadata.gz: 9bade68e29f34aed204378b7e9dae1873ec754d083f71424535113d34fdbf4c70bede35555b576e0916b62c77df53fcb9f1c1884b83e616a537625b0b1a5a355
7
- data.tar.gz: 6dd857001b8afd09e28d9659e1c807fb4b17ca2a12471b3563f3204fbd595246898f7f00f8b5b9b5203d0bf58dc1f4846b226cda0300f9010a66d2b1f0eed9a7
6
+ metadata.gz: c9d44f747b5d4e64692686c47a0ca56f13d55fe97a0674cfc20659e05b8a518df3ac45f33ab8b575945b1ac9dd69fa503c0884cfb74abdbc3c0f306a0642f7a7
7
+ data.tar.gz: 68987336af46b08f9693bf65a1a6fc29af99ee81a044b1468b7a410084191a2e6973595ba1db86406be7c0c7cdace14a968e46e1f83754950bf3ef3a4c5e76a2
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.4.0
4
+ - 2.3
3
5
  - 2.2
4
6
  - 2.1
5
7
  - 2.0.0
data/HISTORY.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # createsend-ruby history
2
2
 
3
+ ## v5.1.1 - 8 Oct, 2021
4
+ * increased default timeout for HTTP requests to 120secs
5
+
6
+ ## v5.1.0 - 3 Sep, 2019
7
+ * Added support for [Journeys API](https://www.campaignmonitor.com/api/journeys/)
8
+
9
+ ## v5.0.0 - 19 Jun, 2018
10
+ * Upgrades to Createsend API v3.2 which includes new breaking changes
11
+ * Breaking: 'Consent to track' field is now mandatory for sending smart and classic transactionl emails
12
+ * Breaking: 'Consent to track' field is now mandatory when adding or updating subscribers
13
+ * Optional 'Include tracking preference' field when retrieving lists of subscribers
14
+
15
+ ## v4.1.2 - 27 Nov, 2017
16
+ * Fix for the GZip compression issue: https://github.com/jnunemaker/httparty/issues/562
17
+
3
18
  ## v4.1.1 - 14 Jan, 2016
4
19
 
5
20
  * Drop support for Ruby 1.9.3 ([#49](https://github.com/campaignmonitor/createsend-ruby/pull/49))
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # createsend
1
+ # createsend [![Build Status](https://app.travis-ci.com/campaignmonitor/createsend-ruby.svg?branch=master)](https://app.travis-ci.com/campaignmonitor/createsend-ruby)
2
2
 
3
3
  A Ruby library which implements the complete functionality of the [Campaign Monitor API](http://www.campaignmonitor.com/api/). Requires Ruby >= 2.0.0.
4
4
 
@@ -193,7 +193,7 @@ For example, if you wanted to find out how to call the `CreateSend::Subscriber.a
193
193
  should "add a subscriber with custom fields" do
194
194
  stub_post(@auth, "subscribers/#{@list_id}.json", "add_subscriber.json")
195
195
  custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ]
196
- email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true
196
+ email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true, "Yes"
197
197
  email_address.should == "subscriber@example.com"
198
198
  end
199
199
  ```
@@ -212,7 +212,7 @@ Please check the [instructions for releasing](https://github.com/campaignmonitor
212
212
 
213
213
  ## This stuff should be green
214
214
 
215
- [![Build Status](https://secure.travis-ci.org/campaignmonitor/createsend-ruby.png)][travis] [![Coverage Status](https://coveralls.io/repos/campaignmonitor/createsend-ruby/badge.png?branch=master)][coveralls] [![Dependency Status](https://gemnasium.com/campaignmonitor/createsend-ruby.png)][gemnasium] [![Gem Version](https://badge.fury.io/rb/createsend.png)][gembadge]
215
+ [![Build Status](https://app.travis-ci.com/campaignmonitor/createsend-ruby.svg?branch=master)](https://app.travis-ci.com/campaignmonitor/createsend-ruby) [![Coverage Status](https://coveralls.io/repos/campaignmonitor/createsend-ruby/badge.png?branch=master)][coveralls] [![Dependency Status](https://gemnasium.com/campaignmonitor/createsend-ruby.png)][gemnasium] [![Gem Version](https://badge.fury.io/rb/createsend.png)][gembadge]
216
216
 
217
217
  [travis]: http://travis-ci.org/campaignmonitor/createsend-ruby
218
218
  [coveralls]: https://coveralls.io/r/campaignmonitor/createsend-ruby
data/RELEASE.md CHANGED
@@ -32,7 +32,7 @@
32
32
  git push origin master --tags
33
33
  ```
34
34
 
35
- - Ensure that all [tests](https://travis-ci.org/campaignmonitor/createsend-ruby) pass, and that [coverage](https://coveralls.io/r/campaignmonitor/createsend-ruby) is maintained or improved.
35
+ - Ensure that all [tests](https://app.travis-ci.com/github/campaignmonitor/createsend-ruby) pass, and that [coverage](https://coveralls.io/r/campaignmonitor/createsend-ruby) is maintained or improved.
36
36
 
37
37
  - Add a new [GitHub Release](https://github.com/campaignmonitor/createsend-ruby/releases) using the newly created tag.
38
38
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require "./lib/createsend"
5
5
 
6
6
  desc "Run tests"
7
7
  Rake::TestTask.new(:test) do |test|
8
- test.ruby_opts = ["-rubygems"] if defined? Gem
8
+ test.ruby_opts = ["-rrubygems"] if defined? Gem
9
9
  test.libs << "lib" << "test"
10
10
  test.pattern = "test/**/*_test.rb"
11
11
  puts "running tests."
@@ -1,5 +1,5 @@
1
1
  module CreateSend
2
- # Represents a campaign and provides associated funtionality.
2
+ # Represents a campaign and provides associated functionality.
3
3
  class Campaign < CreateSend
4
4
  attr_reader :campaign_id
5
5
 
@@ -181,6 +181,12 @@ module CreateSend
181
181
  super "/clients/#{client_id}.json", {}
182
182
  end
183
183
 
184
+ # Gets the journeys belonging to this client.
185
+ def journeys
186
+ response = get 'journeys'
187
+ response.map{|item| Hashie::Mash.new(item)}
188
+ end
189
+
184
190
  private
185
191
 
186
192
  def get(action, options = {})
@@ -44,6 +44,8 @@ module CreateSend
44
44
  # Provides high level CreateSend functionality/data you'll probably need.
45
45
  class CreateSend
46
46
  include HTTParty
47
+ default_timeout 120
48
+
47
49
  attr_reader :auth_details
48
50
 
49
51
  # Specify cert authority file for cert validation
@@ -109,13 +111,13 @@ module CreateSend
109
111
  end
110
112
  end
111
113
 
112
- @@base_uri = "https://api.createsend.com/api/v3.1"
114
+ @@base_uri = "https://api.createsend.com/api/v3.2"
113
115
  @@oauth_base_uri = "https://api.createsend.com/oauth"
114
116
  @@oauth_token_uri = "#{@@oauth_base_uri}/token"
115
117
  headers({
116
118
  'User-Agent' => USER_AGENT_STRING,
117
- 'Content-Type' => 'application/json; charset=utf-8',
118
- 'Accept-Encoding' => 'gzip, deflate' })
119
+ 'Content-Type' => 'application/json; charset=utf-8'
120
+ })
119
121
  base_uri @@base_uri
120
122
 
121
123
  # Authenticate using either OAuth or an API key.
@@ -0,0 +1,58 @@
1
+ module CreateSend
2
+ # Represents a journey and provides associated functionality
3
+ class Journey < CreateSend
4
+ attr_reader :journey_id
5
+
6
+ def initialize(auth, journey_id)
7
+ @journey_id = journey_id
8
+ super
9
+ end
10
+
11
+ # Get a full summary of a journey
12
+ def summary
13
+ response = get "/journeys/#{@journey_id}.json"
14
+ Hashie::Mash.new(response)
15
+ end
16
+
17
+ # Gets a list of all recipients of a particular email within a journey
18
+ def email_recipients(email_id="", date="", page=1, page_size=1000, order_direction='asc')
19
+ paged_result_by_date("recipients", email_id, date, page, page_size, order_direction)
20
+ end
21
+
22
+ # Gets a paged list of subscribers who opened a given journey email
23
+ def email_opens(email_id="", date="", page=1, page_size=1000, order_direction='asc')
24
+ paged_result_by_date("opens", email_id, date, page, page_size, order_direction)
25
+ end
26
+
27
+ # Gets a paged list of subscribers who clicked a given journey email
28
+ def email_clicks(email_id="", date="", page=1, page_size=1000, order_direction='asc')
29
+ paged_result_by_date("clicks", email_id, date, page, page_size, order_direction)
30
+ end
31
+
32
+ # Gets a paged result representing all subscribers who unsubscribed from a journey email
33
+ def email_unsubscribes(email_id="", date="", page=1, page_size=1000, order_direction='asc')
34
+ paged_result_by_date("unsubscribes", email_id, date, page, page_size, order_direction)
35
+ end
36
+
37
+ # Gets a paged result of all bounces for a journey email
38
+ def email_bounces(email_id="", date="", page=1, page_size=1000, order_direction='asc')
39
+ paged_result_by_date("bounces", email_id, date, page, page_size, order_direction)
40
+ end
41
+
42
+ private
43
+
44
+ def paged_result_by_date(resource, email_id, date, page, page_size, order_direction)
45
+ options = { :query => {
46
+ :date => date,
47
+ :page => page,
48
+ :pagesize => page_size,
49
+ :orderdirection => order_direction } }
50
+ response = get_journey_email_action email_id, resource, options
51
+ Hashie::Mash.new(response)
52
+ end
53
+
54
+ def get_journey_email_action(email_id, action, options = {})
55
+ get "/journeys/email/#{email_id}/#{action}.json", options
56
+ end
57
+ end
58
+ end
@@ -116,37 +116,37 @@ module CreateSend
116
116
 
117
117
  # Gets the active subscribers for this list.
118
118
  def active(date="", page=1, page_size=1000, order_field="email",
119
- order_direction="asc")
119
+ order_direction="asc", include_tracking_preference=false)
120
120
  paged_result_by_date("active", date, page, page_size, order_field,
121
- order_direction)
121
+ order_direction, include_tracking_preference)
122
122
  end
123
123
 
124
124
  # Gets the unconfirmed subscribers for this list.
125
125
  def unconfirmed(date="", page=1, page_size=1000, order_field="email",
126
- order_direction="asc")
126
+ order_direction="asc", include_tracking_preference=false)
127
127
  paged_result_by_date("unconfirmed", date, page, page_size, order_field,
128
- order_direction)
128
+ order_direction, include_tracking_preference)
129
129
  end
130
130
 
131
131
  # Gets the bounced subscribers for this list.
132
132
  def bounced(date="", page=1, page_size=1000, order_field="email",
133
- order_direction="asc")
133
+ order_direction="asc", include_tracking_preference=false)
134
134
  paged_result_by_date("bounced", date, page, page_size, order_field,
135
- order_direction)
135
+ order_direction, include_tracking_preference)
136
136
  end
137
137
 
138
138
  # Gets the unsubscribed subscribers for this list.
139
139
  def unsubscribed(date="", page=1, page_size=1000, order_field="email",
140
- order_direction="asc")
140
+ order_direction="asc", include_tracking_preference=false)
141
141
  paged_result_by_date("unsubscribed", date, page, page_size, order_field,
142
- order_direction)
142
+ order_direction, include_tracking_preference)
143
143
  end
144
144
 
145
145
  # Gets the deleted subscribers for this list.
146
146
  def deleted(date="", page=1, page_size=1000, order_field="email",
147
- order_direction="asc")
147
+ order_direction="asc", include_tracking_preference=false)
148
148
  paged_result_by_date("deleted", date, page, page_size, order_field,
149
- order_direction)
149
+ order_direction, include_tracking_preference)
150
150
  end
151
151
 
152
152
  # Updates this list.
@@ -225,13 +225,14 @@ module CreateSend
225
225
  private
226
226
 
227
227
  def paged_result_by_date(resource, date, page, page_size, order_field,
228
- order_direction)
228
+ order_direction, include_tracking_preference)
229
229
  options = { :query => {
230
230
  :date => date,
231
231
  :page => page,
232
232
  :pagesize => page_size,
233
233
  :orderfield => order_field,
234
- :orderdirection => order_direction } }
234
+ :orderdirection => order_direction,
235
+ :includetrackingpreference => include_tracking_preference } }
235
236
  response = get resource, options
236
237
  Hashie::Mash.new(response)
237
238
  end
@@ -35,13 +35,14 @@ module CreateSend
35
35
 
36
36
  # Gets the active subscribers in this segment.
37
37
  def subscribers(date="", page=1, page_size=1000, order_field="email",
38
- order_direction="asc")
38
+ order_direction="asc", include_tracking_preference=false)
39
39
  options = { :query => {
40
40
  :date => date,
41
41
  :page => page,
42
42
  :pagesize => page_size,
43
43
  :orderfield => order_field,
44
- :orderdirection => order_direction } }
44
+ :orderdirection => order_direction,
45
+ :includetrackingpreference => include_tracking_preference } }
45
46
  response = get "active", options
46
47
  Hashie::Mash.new(response)
47
48
  end
@@ -11,23 +11,27 @@ module CreateSend
11
11
  end
12
12
 
13
13
  # Gets a subscriber by list ID and email address.
14
- def self.get(auth, list_id, email_address)
15
- options = { :query => { :email => email_address } }
14
+ def self.get(auth, list_id, email_address, include_tracking_preference=false)
15
+ options = { :query => {
16
+ :email => email_address,
17
+ :includetrackingpreference => include_tracking_preference }
18
+ }
16
19
  cs = CreateSend.new auth
17
20
  response = cs.get "/subscribers/#{list_id}.json", options
18
21
  Hashie::Mash.new(response)
19
22
  end
20
23
 
21
24
  # Adds a subscriber to a subscriber list.
22
- def self.add(auth, list_id, email_address, name, custom_fields, resubscribe,
23
- restart_subscription_based_autoresponders=false)
25
+ def self.add(auth, list_id, email_address, name, custom_fields, resubscribe,
26
+ consent_to_track, restart_subscription_based_autoresponders=false)
24
27
  options = { :body => {
25
28
  :EmailAddress => email_address,
26
29
  :Name => name,
27
30
  :CustomFields => custom_fields,
28
31
  :Resubscribe => resubscribe,
29
- :RestartSubscriptionBasedAutoresponders =>
30
- restart_subscription_based_autoresponders }.to_json }
32
+ :RestartSubscriptionBasedAutoresponders =>
33
+ restart_subscription_based_autoresponders,
34
+ :ConsentToTrack => consent_to_track }.to_json }
31
35
  cs = CreateSend.new auth
32
36
  response = cs.post "/subscribers/#{list_id}.json", options
33
37
  response.parsed_response
@@ -65,8 +69,8 @@ module CreateSend
65
69
 
66
70
  # Updates any aspect of a subscriber, including email address, name, and
67
71
  # custom field data if supplied.
68
- def update(new_email_address, name, custom_fields, resubscribe,
69
- restart_subscription_based_autoresponders=false)
72
+ def update(new_email_address, name, custom_fields, resubscribe,
73
+ consent_to_track, restart_subscription_based_autoresponders=false)
70
74
  options = {
71
75
  :query => { :email => @email_address },
72
76
  :body => {
@@ -74,8 +78,9 @@ module CreateSend
74
78
  :Name => name,
75
79
  :CustomFields => custom_fields,
76
80
  :Resubscribe => resubscribe,
77
- :RestartSubscriptionBasedAutoresponders =>
78
- restart_subscription_based_autoresponders }.to_json }
81
+ :RestartSubscriptionBasedAutoresponders =>
82
+ restart_subscription_based_autoresponders,
83
+ :ConsentToTrack => consent_to_track }.to_json }
79
84
  put "/subscribers/#{@list_id}.json", options
80
85
  # Update @email_address, so this object can continue to be used reliably
81
86
  @email_address = new_email_address
@@ -1,3 +1,3 @@
1
1
  module CreateSend
2
- VERSION = "4.1.1" unless defined?(CreateSend::VERSION)
2
+ VERSION = "5.1.1" unless defined?(CreateSend::VERSION)
3
3
  end
data/lib/createsend.rb CHANGED
@@ -14,3 +14,4 @@ require 'createsend/administrator'
14
14
  require 'createsend/transactional_classic_email'
15
15
  require 'createsend/transactional_smart_email'
16
16
  require 'createsend/transactional_timeline'
17
+ require 'createsend/journey'
@@ -0,0 +1,86 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'createsend'
3
+
4
+ class JourneySample
5
+ @date = "2019-01-01 00:00"
6
+
7
+ def initialize
8
+ raise 'CREATESEND_API_KEY env var missing' if ENV['CREATESEND_API_KEY'].nil?
9
+ raise 'CREATESEND_CLIENT_ID env var missing' if ENV['CREATESEND_CLIENT_ID'].nil?
10
+ raise 'CREATESEND_JOURNEY_ID env var missing' if ENV['CREATESEND_JOURNEY_ID'].nil?
11
+ raise 'CREATESEND_EMAIL_ID env var missing' if ENV['CREATESEND_EMAIL_ID'].nil?
12
+
13
+ auth = {:api_key => ENV['CREATESEND_API_KEY']}
14
+ @client = CreateSend::Client.new auth, ENV['CREATESEND_CLIENT_ID']
15
+ @journey = CreateSend::Journey.new auth, ENV['CREATESEND_JOURNEY_ID']
16
+ end
17
+
18
+ def get_all_journeys
19
+ @client.journeys
20
+ end
21
+
22
+ def get_journey_summary
23
+ @journey.summary
24
+ end
25
+
26
+ def get_recipients_for_email
27
+ @journey.email_recipients ENV['CREATESEND_EMAIL_ID']
28
+ end
29
+
30
+ def get_email_opens
31
+ opens = []
32
+ loop do
33
+ page = @journey.email_opens email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
34
+ opens.concat(page.Results)
35
+ if page.PageNumber == page.NumberOfPages
36
+ break
37
+ end
38
+ end
39
+ opens
40
+ end
41
+
42
+ def get_email_clicks
43
+ clicks = []
44
+ loop do
45
+ page = @journey.email_clicks email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
46
+ clicks.concat(page.Results)
47
+ if page.PageNumber == page.NumberOfPages
48
+ break
49
+ end
50
+ end
51
+ clicks
52
+ end
53
+
54
+ def get_email_unsubscribes
55
+ unsubscribes = []
56
+ loop do
57
+ page = @journey.email_unsubscribes email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
58
+ unsubscribes.concat(page.Results)
59
+ if page.PageNumber == page.NumberOfPages
60
+ break
61
+ end
62
+ end
63
+ unsubscribes
64
+ end
65
+
66
+ def get_email_bounces
67
+ bounces = []
68
+ loop do
69
+ page = @journey.email_bounces email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'asc'
70
+ bounces.concat(page.Results)
71
+ if page.PageNumber == page.NumberOfPages
72
+ break
73
+ end
74
+ end
75
+ bounces
76
+ end
77
+ end
78
+
79
+ sample = JourneySample.new
80
+ puts "All journeys: #{sample.get_all_journeys.to_json}\n\n"
81
+ puts "Journey Summary: #{sample.get_journey_summary.to_json}\n\n"
82
+ puts "Email recipients : #{sample.get_recipients_for_email.to_json}\n\n"
83
+ puts "Email Opens : #{sample.get_email_opens.to_json}\n\n"
84
+ puts "Email Clicks : #{sample.get_email_clicks.to_json}\n\n"
85
+ puts "Email Unsubscribes : #{sample.get_email_unsubscribes.to_json}\n\n"
86
+ puts "Email Bounces : #{sample.get_email_bounces.to_json}\n\n"
@@ -8,7 +8,7 @@ class AdministratorTest < Test::Unit::TestCase
8
8
 
9
9
  should "get a administrator by email address" do
10
10
  email = "admin@example.com"
11
- stub_get(@auth, "admins.json?email=#{CGI.escape(email)}", "admin_details.json")
11
+ stub_get(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", "admin_details.json")
12
12
  admin = CreateSend::Administrator.get @auth, email
13
13
  admin.EmailAddress.should == email
14
14
  admin.Name.should == "Admin One"
@@ -24,13 +24,13 @@ class AdministratorTest < Test::Unit::TestCase
24
24
  should "update an administrator" do
25
25
  email = "admin@example.com"
26
26
  new_email = "new_email_address@example.com"
27
- stub_put(@auth, "admins.json?email=#{CGI.escape(email)}", nil)
27
+ stub_put(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", nil)
28
28
  @admin.update new_email, "Admin Name"
29
29
  @admin.email_address.should == new_email
30
30
  end
31
31
 
32
32
  should "delete an admin" do
33
- stub_delete(@auth, "admins.json?email=#{CGI.escape(@admin.email_address)}", nil)
33
+ stub_delete(@auth, "admins.json?email=#{ERB::Util.url_encode(@admin.email_address)}", nil)
34
34
  @admin.delete
35
35
  end
36
36
  end
@@ -191,7 +191,7 @@ class CampaignTest < Test::Unit::TestCase
191
191
 
192
192
  should "get the opens for a campaign" do
193
193
  min_date = "2010-01-01"
194
- stub_get(@auth, "campaigns/#{@campaign.campaign_id}/opens.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{CGI.escape(min_date)}", "campaign_opens.json")
194
+ 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")
195
195
  opens = @campaign.opens min_date
196
196
  opens.Results.size.should == 5
197
197
  opens.Results.first.EmailAddress.should == "subs+6576576576@example.com"
@@ -215,7 +215,7 @@ class CampaignTest < Test::Unit::TestCase
215
215
 
216
216
  should "get the subscriber clicks for a campaign" do
217
217
  min_date = "2010-01-01"
218
- stub_get(@auth, "campaigns/#{@campaign.campaign_id}/clicks.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{CGI.escape(min_date)}", "campaign_clicks.json")
218
+ 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")
219
219
  clicks = @campaign.clicks min_date
220
220
  clicks.Results.size.should == 3
221
221
  clicks.Results.first.EmailAddress.should == "subs+6576576576@example.com"
@@ -240,7 +240,7 @@ class CampaignTest < Test::Unit::TestCase
240
240
 
241
241
  should "get the unsubscribes for a campaign" do
242
242
  min_date = "2010-01-01"
243
- stub_get(@auth, "campaigns/#{@campaign.campaign_id}/unsubscribes.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{CGI.escape(min_date)}", "campaign_unsubscribes.json")
243
+ 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")
244
244
  unsubscribes = @campaign.unsubscribes min_date
245
245
  unsubscribes.Results.size.should == 1
246
246
  unsubscribes.Results.first.EmailAddress.should == "subs+6576576576@example.com"
@@ -258,7 +258,7 @@ class CampaignTest < Test::Unit::TestCase
258
258
 
259
259
  should "get the spam complaints for a campaign" do
260
260
  min_date = "2010-01-01"
261
- stub_get(@auth, "campaigns/#{@campaign.campaign_id}/spam.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{CGI.escape(min_date)}", "campaign_spam.json")
261
+ 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")
262
262
  spam = @campaign.spam min_date
263
263
  spam.Results.size.should == 1
264
264
  spam.Results.first.EmailAddress.should == "subs+6576576576@example.com"
@@ -275,7 +275,7 @@ class CampaignTest < Test::Unit::TestCase
275
275
 
276
276
  should "get the bounces for a campaign" do
277
277
  min_date = "2010-01-01"
278
- stub_get(@auth, "campaigns/#{@campaign.campaign_id}/bounces.json?page=1&pagesize=1000&orderfield=date&orderdirection=asc&date=#{CGI.escape(min_date)}", "campaign_bounces.json")
278
+ 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")
279
279
  bounces = @campaign.bounces min_date
280
280
  bounces.Results.size.should == 2
281
281
  bounces.Results.first.EmailAddress.should == "asdf@softbouncemyemail.com"
data/test/client_test.rb CHANGED
@@ -10,7 +10,7 @@ class ClientTest < Test::Unit::TestCase
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.should == "32a381c49a2df99f1d0c6f3c112352b9"
13
+ client_id.parsed_response.should == "32a381c49a2df99f1d0c6f3c112352b9"
14
14
  end
15
15
 
16
16
  should "get details of a client" do
@@ -83,7 +83,7 @@ class ClientTest < Test::Unit::TestCase
83
83
 
84
84
  should "get all lists to which a subscriber with a particular email address belongs" do
85
85
  email = "valid@example.com"
86
- stub_get(@auth, "clients/#{@client.client_id}/listsforemail.json?email=#{CGI.escape(email)}", "listsforemail.json")
86
+ stub_get(@auth, "clients/#{@client.client_id}/listsforemail.json?email=#{ERB::Util.url_encode(email)}", "listsforemail.json")
87
87
  lists = @client.lists_for_email(email)
88
88
  lists.size.should == 2
89
89
  lists.first.ListID.should == 'ab4a2b57c7c8f1ba62f898a1af1a575b'
@@ -131,7 +131,7 @@ class ClientTest < Test::Unit::TestCase
131
131
 
132
132
  should "unsuppress an email address" do
133
133
  email = "example@example.com"
134
- stub_put(@auth, "clients/#{@client.client_id}/unsuppress.json?email=#{CGI.escape(email)}", nil)
134
+ stub_put(@auth, "clients/#{@client.client_id}/unsuppress.json?email=#{ERB::Util.url_encode(email)}", nil)
135
135
  result = @client.unsuppress email
136
136
  end
137
137
 
@@ -155,7 +155,7 @@ class ClientTest < Test::Unit::TestCase
155
155
 
156
156
  should "set primary contact" do
157
157
  email = 'person@blackhole.com'
158
- stub_put(@auth, "clients/#{@client.client_id}/primarycontact.json?email=#{CGI.escape(email)}", 'client_set_primary_contact.json')
158
+ stub_put(@auth, "clients/#{@client.client_id}/primarycontact.json?email=#{ERB::Util.url_encode(email)}", 'client_set_primary_contact.json')
159
159
  result = @client.set_primary_contact email
160
160
  result.EmailAddress.should == email
161
161
  end
@@ -217,6 +217,14 @@ class ClientTest < Test::Unit::TestCase
217
217
  stub_delete(@auth, "clients/#{@client.client_id}.json", nil)
218
218
  @client.delete
219
219
  end
220
-
220
+
221
+ should "get all journeys" do
222
+ stub_get(@auth, "clients/#{@client.client_id}/journeys.json", "journeys.json")
223
+ 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'
228
+ end
221
229
  end
222
230
  end
@@ -82,7 +82,7 @@ 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=#{CGI.escape(refresh_token)}"
85
+ FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
86
86
  new_access_token.should == "SlAV32hkKG2e12e"
87
87
  new_expires_in.should == 1209600
88
88
  new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
@@ -97,7 +97,7 @@ class CreateSendTest < Test::Unit::TestCase
97
97
  lambda { access_token, expires_in, refresh_token = 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=#{CGI.escape(refresh_token)}"
100
+ FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
101
101
  end
102
102
 
103
103
  end
@@ -120,7 +120,7 @@ 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=#{CGI.escape(@auth[:refresh_token])}"
123
+ FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(@auth[:refresh_token])}"
124
124
  new_access_token.should == "SlAV32hkKG2e12e"
125
125
  new_expires_in.should == 1209600
126
126
  new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
@@ -246,7 +246,7 @@ class CreateSendTest < Test::Unit::TestCase
246
246
 
247
247
  should "set primary contact" do
248
248
  email = 'admin@blackhole.com'
249
- stub_put(@auth, "primarycontact.json?email=#{CGI.escape(email)}", 'admin_set_primary_contact.json')
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
251
  result.EmailAddress.should == email
252
252
  end
@@ -0,0 +1,35 @@
1
+ {
2
+ "Results": [
3
+ {
4
+ "EmailAddress": "example+1@example.com",
5
+ "BounceType": "4",
6
+ "Date": "2019-07-29 10:33:00",
7
+ "Reason": "Soft Bounce - Mailbox Full"
8
+ },
9
+ {
10
+ "EmailAddress": "example+2@example.com",
11
+ "BounceType": "1",
12
+ "Date": "2019-07-29 10:35:00",
13
+ "Reason": "Hard Bounce"
14
+ },
15
+ {
16
+ "EmailAddress": "example+3@example.com",
17
+ "BounceType": "1",
18
+ "Date": "2019-07-29 10:35:00",
19
+ "Reason": "Hard Bounce"
20
+ },
21
+ {
22
+ "EmailAddress": "example+4@example.com",
23
+ "BounceType": "1",
24
+ "Date": "2019-07-29 10:35:00",
25
+ "Reason": "Hard Bounce"
26
+ }
27
+ ],
28
+ "ResultsOrderedBy": "Date",
29
+ "OrderDirection": "ASC",
30
+ "PageNumber": 1,
31
+ "PageSize": 1000,
32
+ "RecordsOnThisPage": 4,
33
+ "TotalNumberOfRecords": 4,
34
+ "NumberOfPages": 1
35
+ }