createsend 4.1.2 → 6.0.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 +5 -5
- data/HISTORY.md +29 -0
- data/README.md +4 -4
- data/RELEASE.md +1 -1
- data/Rakefile +1 -1
- data/createsend.gemspec +1 -1
- data/lib/createsend/campaign.rb +1 -1
- data/lib/createsend/client.rb +25 -3
- data/lib/createsend/createsend.rb +3 -1
- data/lib/createsend/journey.rb +58 -0
- data/lib/createsend/list.rb +13 -12
- data/lib/createsend/segment.rb +3 -2
- data/lib/createsend/subscriber.rb +15 -10
- data/lib/createsend/version.rb +1 -1
- data/lib/createsend.rb +1 -0
- data/samples/authentication_sample.rb +64 -0
- data/samples/clients_sample.rb +79 -0
- data/samples/journey_sample.rb +87 -0
- data/samples/lists_sample.rb +41 -0
- data/samples/segments_sample.rb +21 -0
- data/samples/subscribes_sample.rb +22 -0
- data/test/administrator_test.rb +3 -3
- data/test/campaign_test.rb +6 -5
- data/test/client_test.rb +67 -36
- data/test/createsend_test.rb +4 -4
- 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/journey_bounces.json +35 -0
- data/test/fixtures/journey_clicks.json +35 -0
- data/test/fixtures/journey_opens.json +55 -0
- data/test/fixtures/journey_recipients.json +27 -0
- data/test/fixtures/journey_summary.json +18 -0
- data/test/fixtures/journey_unsubscribes.json +26 -0
- data/test/fixtures/journeys.json +20 -0
- data/test/fixtures/scheduled_campaigns.json +4 -2
- data/test/fixtures/segment_subscribers.json +2 -0
- data/test/fixtures/subscriber_details.json +1 -0
- data/test/fixtures/subscriber_details_with_track_pref.json +23 -0
- 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 +3 -2
- data/test/journey_test.rb +156 -0
- data/test/list_test.rb +16 -9
- data/test/person_test.rb +3 -3
- data/test/segment_test.rb +2 -1
- data/test/subscriber_test.rb +22 -12
- metadata +25 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1b2bb4cff071610599c8016946954e43a06069153feacda42c1ed0ec3f358e06
|
|
4
|
+
data.tar.gz: f3a2e2b67d20cc392b04b469a15b6d97ee1a7af65b9e5245a4d262047863164d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 229d9c032d55f82c23fed36742e5186eb7e2e4c590e5b8acf9f9463aba53241b41ba31dd5be1ca342556876f0b5f1b69c52a54bff8b161c4018b1611e2145baa
|
|
7
|
+
data.tar.gz: 945dc9bc23760e17d1f4a47e155d3cb356e7539e61e0109f3c0324375cc2f05d2bc1224cfcdb382dfa745a2d667a2ead5b8897962de3e0f7504196baf92e065e
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# createsend-ruby history
|
|
2
2
|
|
|
3
|
+
## v6.0.0 - 10 Feb, 2022
|
|
4
|
+
* Upgrades to Createsend API v3.3 which includes new breaking changes
|
|
5
|
+
* Breaking: 'client.campaigns' now returned an object to support pagination (use .Results to ge the array of campaigns)
|
|
6
|
+
* Added 'Tags' as another field that is returned in 'client.scheduled', 'client.drafts' and 'client.campaigns'
|
|
7
|
+
* Added 'Name' as another field that is returned in 'campaign.summary'
|
|
8
|
+
* Add new support for 'client.tags' endpoint (ie: getting list of tags for the client)
|
|
9
|
+
* Add support for pagination, filtering and sorting to 'client.campaigns' endpoint
|
|
10
|
+
* Bump `rake` to `~> 12.3.3`
|
|
11
|
+
* Adding support for returning ListJoinedDate for each subscriber.
|
|
12
|
+
* List.Active()
|
|
13
|
+
* List.Bounced()
|
|
14
|
+
* List.Unsubscribed()
|
|
15
|
+
* List.Unconfirmed()
|
|
16
|
+
* List.Deleted()
|
|
17
|
+
* Segment.Subscribers()
|
|
18
|
+
* Subscriber.Get()
|
|
19
|
+
|
|
20
|
+
## v5.1.1 - 8 Oct, 2021
|
|
21
|
+
* increased default timeout for HTTP requests to 120secs
|
|
22
|
+
|
|
23
|
+
## v5.1.0 - 3 Sep, 2019
|
|
24
|
+
* Added support for [Journeys API](https://www.campaignmonitor.com/api/journeys/)
|
|
25
|
+
|
|
26
|
+
## v5.0.0 - 19 Jun, 2018
|
|
27
|
+
* Upgrades to Createsend API v3.2 which includes new breaking changes
|
|
28
|
+
* Breaking: 'Consent to track' field is now mandatory for sending smart and classic transactionl emails
|
|
29
|
+
* Breaking: 'Consent to track' field is now mandatory when adding or updating subscribers
|
|
30
|
+
* Optional 'Include tracking preference' field when retrieving lists of subscribers
|
|
31
|
+
|
|
3
32
|
## v4.1.2 - 27 Nov, 2017
|
|
4
33
|
* Fix for the GZip compression issue: https://github.com/jnunemaker/httparty/issues/562
|
|
5
34
|
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# createsend
|
|
1
|
+
# createsend [](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
|
|
|
@@ -133,7 +133,7 @@ clients.each do |cl|
|
|
|
133
133
|
p "Client: #{cl.Name}"
|
|
134
134
|
client = CreateSend::Client.new auth, cl.ClientID
|
|
135
135
|
p "- Campaigns:"
|
|
136
|
-
client.
|
|
136
|
+
client.drafts.each do |cm|
|
|
137
137
|
p " - #{cm.Subject}"
|
|
138
138
|
end
|
|
139
139
|
end
|
|
@@ -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
|
-
[](https://app.travis-ci.com/campaignmonitor/createsend-ruby) [][coveralls] [][gemnasium] [][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.
|
|
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 = ["-
|
|
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."
|
data/createsend.gemspec
CHANGED
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
|
7
7
|
s.add_runtime_dependency 'json', '>= 1.0'
|
|
8
8
|
s.add_runtime_dependency 'hashie', '~> 3.0'
|
|
9
9
|
s.add_runtime_dependency 'httparty', '~> 0.14'
|
|
10
|
-
s.add_development_dependency 'rake', '~>
|
|
10
|
+
s.add_development_dependency 'rake', '~> 12.3.3'
|
|
11
11
|
s.add_development_dependency 'fakeweb', '~> 1.3'
|
|
12
12
|
s.add_development_dependency 'jnunemaker-matchy', '~> 0.4'
|
|
13
13
|
s.add_development_dependency 'shoulda-context', '~> 1.2'
|
data/lib/createsend/campaign.rb
CHANGED
data/lib/createsend/client.rb
CHANGED
|
@@ -25,9 +25,19 @@ module CreateSend
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# Gets the sent campaigns belonging to this client.
|
|
28
|
-
def campaigns
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
def campaigns(page=1, page_size=1000, order_direction="desc",
|
|
29
|
+
sent_from_date='', sent_to_date='', tags='')
|
|
30
|
+
options = { :query => {
|
|
31
|
+
:page => page,
|
|
32
|
+
:pagesize => page_size,
|
|
33
|
+
:orderdirection => order_direction,
|
|
34
|
+
:sentfromdate => sent_from_date,
|
|
35
|
+
:senttodate => sent_to_date,
|
|
36
|
+
:tags => tags
|
|
37
|
+
}}
|
|
38
|
+
|
|
39
|
+
response = get 'campaigns', options
|
|
40
|
+
Hashie::Mash.new(response)
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
# Gets the currently scheduled campaigns belonging to this client.
|
|
@@ -42,6 +52,12 @@ module CreateSend
|
|
|
42
52
|
response.map{|item| Hashie::Mash.new(item)}
|
|
43
53
|
end
|
|
44
54
|
|
|
55
|
+
# Gets all the tags belonging to this client.
|
|
56
|
+
def tags
|
|
57
|
+
response = get 'tags'
|
|
58
|
+
response.map{|item| Hashie::Mash.new(item)}
|
|
59
|
+
end
|
|
60
|
+
|
|
45
61
|
# Gets the subscriber lists belonging to this client.
|
|
46
62
|
def lists
|
|
47
63
|
response = get 'lists'
|
|
@@ -181,6 +197,12 @@ module CreateSend
|
|
|
181
197
|
super "/clients/#{client_id}.json", {}
|
|
182
198
|
end
|
|
183
199
|
|
|
200
|
+
# Gets the journeys belonging to this client.
|
|
201
|
+
def journeys
|
|
202
|
+
response = get 'journeys'
|
|
203
|
+
response.map{|item| Hashie::Mash.new(item)}
|
|
204
|
+
end
|
|
205
|
+
|
|
184
206
|
private
|
|
185
207
|
|
|
186
208
|
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,7 +111,7 @@ module CreateSend
|
|
|
109
111
|
end
|
|
110
112
|
end
|
|
111
113
|
|
|
112
|
-
@@base_uri = "https://api.createsend.com/api/v3.
|
|
114
|
+
@@base_uri = "https://api.createsend.com/api/v3.3"
|
|
113
115
|
@@oauth_base_uri = "https://api.createsend.com/oauth"
|
|
114
116
|
@@oauth_token_uri = "#{@@oauth_base_uri}/token"
|
|
115
117
|
headers({
|
|
@@ -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
|
data/lib/createsend/list.rb
CHANGED
|
@@ -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
|
data/lib/createsend/segment.rb
CHANGED
|
@@ -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 => {
|
|
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
|
|
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
|
|
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
|
data/lib/createsend/version.rb
CHANGED
data/lib/createsend.rb
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
+
require 'createsend'
|
|
3
|
+
|
|
4
|
+
class AuthorizationSample
|
|
5
|
+
def initialize
|
|
6
|
+
raise 'CREATESEND_API_KEY env var missing' if ENV['CREATESEND_API_KEY'].nil?
|
|
7
|
+
raise 'CREATESEND_CLIENT_ID env var missing' if ENV['CREATESEND_CLIENT_ID'].nil?
|
|
8
|
+
raise 'CREATESEND_OAUTH_CLIENT_ID env var missing' if ENV['CREATESEND_OAUTH_CLIENT_ID'].nil?
|
|
9
|
+
raise 'CREATESEND_OAUTH_CLIENT_SECRET env var missing' if ENV['CREATESEND_OAUTH_CLIENT_SECRET'].nil?
|
|
10
|
+
raise 'CREATESEND_OAUTH_REDIRECT_URL env var missing' if ENV['CREATESEND_OAUTH_REDIRECT_URL'].nil?
|
|
11
|
+
raise 'CREATESEND_OAUTH_SCOPE env var missing' if ENV['CREATESEND_OAUTH_SCOPE'].nil?
|
|
12
|
+
|
|
13
|
+
@createsendApiKey = ENV['CREATESEND_API_KEY']
|
|
14
|
+
@oauthClientId = ENV['CREATESEND_OAUTH_CLIENT_ID']
|
|
15
|
+
@oauthClientSecret = ENV['CREATESEND_OAUTH_CLIENT_SECRET']
|
|
16
|
+
@oauthRedirectUrl = ENV['CREATESEND_OAUTH_REDIRECT_URL']
|
|
17
|
+
@oauthScope = ENV['CREATESEND_OAUTH_SCOPE']
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def authentication_with_api_key
|
|
22
|
+
auth = {:api_key => @createsendApiKey}
|
|
23
|
+
@client = CreateSend::Client.new auth, @createsendClientId
|
|
24
|
+
|
|
25
|
+
@client.scheduled
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_authorise_url
|
|
29
|
+
state = 'some state data'
|
|
30
|
+
|
|
31
|
+
@authorize_url = CreateSend::CreateSend.authorize_url(@oauthClientId, @oauthRedirectUrl, @oauthScope, state);
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def exchange_token(code)
|
|
35
|
+
CreateSend::CreateSend.exchange_token(
|
|
36
|
+
client_id=@oauthClientId,
|
|
37
|
+
client_secret=@oauthClientSecret,
|
|
38
|
+
redirect_uri=@oauthRedirectUrl,
|
|
39
|
+
code=code # Get the code from the query string after hitting authorise url
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def authentication_with_oauth(access_token, refresh_token)
|
|
44
|
+
auth = {:access_token => access_token, :refresh_token => refresh_token}
|
|
45
|
+
@client = CreateSend::Client.new auth, @createsendClientId
|
|
46
|
+
|
|
47
|
+
@client.scheduled
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
sample = AuthorizationSample.new
|
|
52
|
+
authoriseUrl = sample.get_authorise_url
|
|
53
|
+
# hit the authorise url, where you would be redirected and receive the code parameter in the query string
|
|
54
|
+
access_token, expires_in, refresh_token = sample.exchange_token('code that you get once you hit authorize url')
|
|
55
|
+
|
|
56
|
+
puts "Getting scheduled campaigns with api authentication: #{sample.authentication_with_api_key.to_json}\n\n"
|
|
57
|
+
puts "Getting authorise url: #{authoriseUrl.to_json}\n\n"
|
|
58
|
+
puts "Getting access_token: #{access_token.to_json}\n\n"
|
|
59
|
+
puts "Getting scheduled campaigns with oauth authentication: #{sample.authentication_with_oauth(access_token, refresh_token).to_json}\n\n"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@client.scheduled
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
+
require 'createsend'
|
|
3
|
+
|
|
4
|
+
class ClientsSample
|
|
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_CLIENT_ID env var missing' if ENV['CREATESEND_CLIENT_ID'].nil?
|
|
9
|
+
|
|
10
|
+
auth = auth = {:access_token => ENV['CREATESEND_ACCESS_TOKEN'], :refresh_token => ENV['CREATESEND_REFRESH_TOKEN']}
|
|
11
|
+
@client = CreateSend::Client.new auth, ENV['CREATESEND_CLIENT_ID']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_all_sent_campaigns
|
|
15
|
+
campaigns = []
|
|
16
|
+
page_number = 1
|
|
17
|
+
loop do
|
|
18
|
+
page = @client.campaigns(page_number)
|
|
19
|
+
page_number += 1
|
|
20
|
+
campaigns.concat(page.Results)
|
|
21
|
+
if page.PageNumber == page.NumberOfPages
|
|
22
|
+
break
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
campaigns
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get_sent_campaigns_with_tag_filter
|
|
30
|
+
filtered_campaigns = []
|
|
31
|
+
page_number = 1
|
|
32
|
+
loop do
|
|
33
|
+
page = @client.campaigns(page_number, 1000, 'desc', '', '', 'tag_example, tag_example_2')
|
|
34
|
+
page_number += 1
|
|
35
|
+
filtered_campaigns.concat(page.Results)
|
|
36
|
+
if page.PageNumber == page.NumberOfPages
|
|
37
|
+
break
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
filtered_campaigns
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_2021_sent_campaigns
|
|
45
|
+
2021_campaigns = []
|
|
46
|
+
page_number = 1
|
|
47
|
+
loop do
|
|
48
|
+
page = @client.campaigns(1, 1000, 'desc', '2021-01-01', '2022-01-01', '')
|
|
49
|
+
page_number += 1
|
|
50
|
+
2021_campaigns.concat(page.Results)
|
|
51
|
+
if page.PageNumber == page.NumberOfPages
|
|
52
|
+
break
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
2021_campaigns
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def get_all_scheduled_campaigns
|
|
60
|
+
@client.scheduled
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_all_draft_campaigns
|
|
64
|
+
@client.drafts
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_all_client_tags
|
|
68
|
+
@client.tags
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
sample = ClientsSample.new
|
|
73
|
+
|
|
74
|
+
puts "All sent campaigns: #{sample.get_all_sent_campaigns.to_json}\n\n"
|
|
75
|
+
puts "All sent campaigns with `tag_example` and `tag_example_2` tag: #{sample.get_sent_campaigns_with_tag_filter.to_json}\n\n"
|
|
76
|
+
puts "All 2021 sent campaigns: #{sample.get_2021_sent_campaigns.to_json}\n\n"
|
|
77
|
+
puts "All scheduled campaigns: #{sample.get_all_scheduled_campaigns.to_json}\n\n"
|
|
78
|
+
puts "All draft campaigns: #{sample.get_all_draft_campaigns.to_json}\n\n"
|
|
79
|
+
puts "All client tags: #{sample.get_all_client_tags.to_json}\n\n"
|
|
@@ -0,0 +1,87 @@
|
|
|
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_ACCESS_TOKEN env var missing' if ENV['CREATESEND_ACCESS_TOKEN'].nil?
|
|
9
|
+
raise 'CREATESEND_REFRESH_TOKEN env var missing' if ENV['CREATESEND_REFRESH_TOKEN'].nil?
|
|
10
|
+
raise 'CREATESEND_CLIENT_ID env var missing' if ENV['CREATESEND_CLIENT_ID'].nil?
|
|
11
|
+
raise 'CREATESEND_JOURNEY_ID env var missing' if ENV['CREATESEND_JOURNEY_ID'].nil?
|
|
12
|
+
raise 'CREATESEND_EMAIL_ID env var missing' if ENV['CREATESEND_EMAIL_ID'].nil?
|
|
13
|
+
|
|
14
|
+
auth = {:access_token => ENV['CREATESEND_ACCESS_TOKEN'], :refresh_token => ENV['CREATESEND_REFRESH_TOKEN']}
|
|
15
|
+
@client = CreateSend::Client.new auth, ENV['CREATESEND_CLIENT_ID']
|
|
16
|
+
@journey = CreateSend::Journey.new auth, ENV['CREATESEND_JOURNEY_ID']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_all_journeys
|
|
20
|
+
@client.journeys
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_journey_summary
|
|
24
|
+
@journey.summary
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def get_recipients_for_email
|
|
28
|
+
@journey.email_recipients ENV['CREATESEND_EMAIL_ID']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_email_opens
|
|
32
|
+
opens = []
|
|
33
|
+
loop do
|
|
34
|
+
page = @journey.email_opens email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
|
|
35
|
+
opens.concat(page.Results)
|
|
36
|
+
if page.PageNumber == page.NumberOfPages
|
|
37
|
+
break
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
opens
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get_email_clicks
|
|
44
|
+
clicks = []
|
|
45
|
+
loop do
|
|
46
|
+
page = @journey.email_clicks email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
|
|
47
|
+
clicks.concat(page.Results)
|
|
48
|
+
if page.PageNumber == page.NumberOfPages
|
|
49
|
+
break
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
clicks
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def get_email_unsubscribes
|
|
56
|
+
unsubscribes = []
|
|
57
|
+
loop do
|
|
58
|
+
page = @journey.email_unsubscribes email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'desc'
|
|
59
|
+
unsubscribes.concat(page.Results)
|
|
60
|
+
if page.PageNumber == page.NumberOfPages
|
|
61
|
+
break
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
unsubscribes
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_email_bounces
|
|
68
|
+
bounces = []
|
|
69
|
+
loop do
|
|
70
|
+
page = @journey.email_bounces email_id = ENV['CREATESEND_EMAIL_ID'], date = @date, order_direction = 'asc'
|
|
71
|
+
bounces.concat(page.Results)
|
|
72
|
+
if page.PageNumber == page.NumberOfPages
|
|
73
|
+
break
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
bounces
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
sample = JourneySample.new
|
|
81
|
+
puts "All journeys: #{sample.get_all_journeys.to_json}\n\n"
|
|
82
|
+
puts "Journey Summary: #{sample.get_journey_summary.to_json}\n\n"
|
|
83
|
+
puts "Email recipients : #{sample.get_recipients_for_email.to_json}\n\n"
|
|
84
|
+
puts "Email Opens : #{sample.get_email_opens.to_json}\n\n"
|
|
85
|
+
puts "Email Clicks : #{sample.get_email_clicks.to_json}\n\n"
|
|
86
|
+
puts "Email Unsubscribes : #{sample.get_email_unsubscribes.to_json}\n\n"
|
|
87
|
+
puts "Email Bounces : #{sample.get_email_bounces.to_json}\n\n"
|