Skip to content

Commit 38c16e5

Browse files
authored
Merge pull request campaignmonitor#73 from campaignmonitor/ConsentToSendSmsSupport
ConsentToSendSmsSupport
2 parents e22c0f2 + 57172df commit 38c16e5

24 files changed

+738
-672
lines changed

HISTORY.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# createsend-ruby history
22

3+
## v6.1.0 - 27 Oct 2023
4+
* Added support for add/update subscribers specifying mobile_number and/or consent_to_send_sms (optional parameters)
5+
* Subscriber.Add
6+
* Subscriber.Update()
7+
* Added support for lists endpoints to be able to return the ConsentToSendSms (keyword parameter, is optional)
8+
* List.Active(include_sms_preference:true)
9+
* List.Bounced(include_sms_preference:true)
10+
* List.Unsubscribed(include_sms_preference:true)
11+
* List.Unconfirmed(include_sms_preference:true)
12+
* List.Deleted(include_sms_preference:true)
13+
* Clean-up various warnings associated with this package (excluding dependency package warning)
14+
* Add more samples
15+
316
## v6.0.0 - 10 Feb, 2022
417
* Upgrades to Createsend API v3.3 which includes new breaking changes
518
* Breaking: 'client.campaigns' now returned an object to support pagination (use .Results to ge the array of campaigns)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ should "add a subscriber with custom fields" do
194194
stub_post(@auth, "subscribers/#{@list_id}.json", "add_subscriber.json")
195195
custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ]
196196
email_address = CreateSend::Subscriber.add @auth, @list_id, "[email protected]", "Subscriber", custom_fields, true, "Yes"
197-
email_address.should == "[email protected]"
197+
email_address.should be == "[email protected]"
198198
end
199199
```
200200

lib/createsend/list.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,37 +116,37 @@ def stats
116116

117117
# Gets the active subscribers for this list.
118118
def active(date="", page=1, page_size=1000, order_field="email",
119-
order_direction="asc", include_tracking_preference=false)
119+
order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
120120
paged_result_by_date("active", date, page, page_size, order_field,
121-
order_direction, include_tracking_preference)
121+
order_direction, include_tracking_preference, include_sms_preference)
122122
end
123123

124124
# Gets the unconfirmed subscribers for this list.
125125
def unconfirmed(date="", page=1, page_size=1000, order_field="email",
126-
order_direction="asc", include_tracking_preference=false)
126+
order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
127127
paged_result_by_date("unconfirmed", date, page, page_size, order_field,
128-
order_direction, include_tracking_preference)
128+
order_direction, include_tracking_preference, include_sms_preference)
129129
end
130130

131131
# Gets the bounced subscribers for this list.
132132
def bounced(date="", page=1, page_size=1000, order_field="email",
133-
order_direction="asc", include_tracking_preference=false)
133+
order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
134134
paged_result_by_date("bounced", date, page, page_size, order_field,
135-
order_direction, include_tracking_preference)
135+
order_direction, include_tracking_preference, include_sms_preference)
136136
end
137137

138138
# Gets the unsubscribed subscribers for this list.
139139
def unsubscribed(date="", page=1, page_size=1000, order_field="email",
140-
order_direction="asc", include_tracking_preference=false)
140+
order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
141141
paged_result_by_date("unsubscribed", date, page, page_size, order_field,
142-
order_direction, include_tracking_preference)
142+
order_direction, include_tracking_preference, include_sms_preference)
143143
end
144144

145145
# Gets the deleted subscribers for this list.
146146
def deleted(date="", page=1, page_size=1000, order_field="email",
147-
order_direction="asc", include_tracking_preference=false)
147+
order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
148148
paged_result_by_date("deleted", date, page, page_size, order_field,
149-
order_direction, include_tracking_preference)
149+
order_direction, include_tracking_preference, include_sms_preference)
150150
end
151151

152152
# Updates this list.
@@ -225,14 +225,15 @@ def deactivate_webhook(webhook_id)
225225
private
226226

227227
def paged_result_by_date(resource, date, page, page_size, order_field,
228-
order_direction, include_tracking_preference)
228+
order_direction, include_tracking_preference, include_sms_preference)
229229
options = { :query => {
230230
:date => date,
231231
:page => page,
232232
:pagesize => page_size,
233233
:orderfield => order_field,
234234
:orderdirection => order_direction,
235-
:includetrackingpreference => include_tracking_preference } }
235+
:includetrackingpreference => include_tracking_preference,
236+
:includesmspreference => include_sms_preference} }
236237
response = get resource, options
237238
Hashie::Mash.new(response)
238239
end

lib/createsend/subscriber.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ def self.get(auth, list_id, email_address, include_tracking_preference=false)
2323

2424
# Adds a subscriber to a subscriber list.
2525
def self.add(auth, list_id, email_address, name, custom_fields, resubscribe,
26-
consent_to_track, restart_subscription_based_autoresponders=false)
26+
consent_to_track, restart_subscription_based_autoresponders=false, mobile_number=nil, consent_to_send_sms=nil)
2727
options = { :body => {
2828
:EmailAddress => email_address,
2929
:Name => name,
30+
:MobileNumber => mobile_number,
3031
:CustomFields => custom_fields,
3132
:Resubscribe => resubscribe,
3233
:RestartSubscriptionBasedAutoresponders =>
3334
restart_subscription_based_autoresponders,
34-
:ConsentToTrack => consent_to_track }.to_json }
35+
:ConsentToTrack => consent_to_track,
36+
:ConsentToSendSms => consent_to_send_sms }.to_json }
3537
cs = CreateSend.new auth
3638
response = cs.post "/subscribers/#{list_id}.json", options
3739
response.parsed_response
@@ -70,17 +72,19 @@ def self.import(auth, list_id, subscribers, resubscribe,
7072
# Updates any aspect of a subscriber, including email address, name, and
7173
# custom field data if supplied.
7274
def update(new_email_address, name, custom_fields, resubscribe,
73-
consent_to_track, restart_subscription_based_autoresponders=false)
75+
consent_to_track, restart_subscription_based_autoresponders=false, mobile_number=nil, consent_to_send_sms=nil)
7476
options = {
7577
:query => { :email => @email_address },
7678
:body => {
7779
:EmailAddress => new_email_address,
7880
:Name => name,
81+
:MobileNumber => mobile_number,
7982
:CustomFields => custom_fields,
8083
:Resubscribe => resubscribe,
8184
:RestartSubscriptionBasedAutoresponders =>
8285
restart_subscription_based_autoresponders,
83-
:ConsentToTrack => consent_to_track }.to_json }
86+
:ConsentToTrack => consent_to_track,
87+
:ConsentToSendSms => consent_to_send_sms }.to_json }
8488
put "/subscribers/#{@list_id}.json", options
8589
# Update @email_address, so this object can continue to be used reliably
8690
@email_address = new_email_address

lib/createsend/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module CreateSend
2-
VERSION = "6.0.0" unless defined?(CreateSend::VERSION)
2+
VERSION = "6.0.1" unless defined?(CreateSend::VERSION)
33
end

samples/lists_sample.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def initialize
1212
end
1313

1414
def get_active_subscribers
15-
@list.active
15+
@list.active()
16+
end
17+
18+
def get_active_with_sms_preference_subscribers
19+
@list.active(include_sms_preference:true)
1620
end
1721

1822
def get_bounced_subscribers
@@ -23,6 +27,10 @@ def get_unsubscribed_subscribers
2327
@list.unsubscribed
2428
end
2529

30+
def get_unsubscribed_with_sms_preference_subscribers
31+
@list.unsubscribed(include_sms_preference:true)
32+
end
33+
2634
def get_unconfirmed_subscribers
2735
@list.unconfirmed
2836
end
@@ -35,7 +43,9 @@ def get_deleted_subscribers
3543
sample = ListsSample.new
3644

3745
puts "All active subscribers: #{sample.get_active_subscribers.to_json}\n\n"
46+
puts "All active subscribers with sms preference: #{sample.get_active_with_sms_preference_subscribers.to_json}\n\n"
3847
puts "All bounced subscribers: #{sample.get_bounced_subscribers.to_json}\n\n"
39-
puts "All unsubscribed subscribers: #{sample.get_unsubscribed_subscribers.to_json}\n\n"
4048
puts "All unconfirmed subscribers: #{sample.get_unconfirmed_subscribers.to_json}\n\n"
49+
puts "All unsubscribed subscribers: #{sample.get_unsubscribed_subscribers.to_json}\n\n"
50+
puts "All unsubscribed subscribers with sms preference: #{sample.get_unsubscribed_with_sms_preference_subscribers.to_json}\n\n"
4151
puts "All deleted subscribers: #{sample.get_deleted_subscribers.to_json}\n\n"

samples/subscribers_sample.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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'], "[email protected]", "Subscriber", [], true, "Yes", false
15+
end
16+
17+
def add_subscriber_with_mobile
18+
@subscriberAdded = CreateSend::Subscriber.add @auth, ENV['CREATESEND_LIST_ID'], "[email protected]", "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'], "[email protected]", "SubscriberWithMobileAndConsent", [], true, "Yes", false, "+61423152523", "Yes"
23+
end
24+
25+
def get_subscriber
26+
@subscriber = CreateSend::Subscriber.get @auth, ENV['CREATESEND_LIST_ID'], "[email protected]"
27+
end
28+
29+
def import_subscribers
30+
subscribers = [
31+
{"EmailAddress":"[email protected]","Name":"subscriberImport11", "ConsentToTrack":"Yes"},
32+
{"EmailAddress":"[email protected]","Name":"subscriberImport12", "ConsentToTrack":"No", "MobileNumber":"+1612105111", "ConsentToSendSms":"Yes"},
33+
{"EmailAddress":"[email protected]","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'], '[email protected]')
40+
@subscriberUpdated = @subscriber.update("[email protected]", "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"

samples/subscribes_sample.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/administrator_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ class AdministratorTest < Test::Unit::TestCase
1010
1111
stub_get(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", "admin_details.json")
1212
admin = CreateSend::Administrator.get @auth, email
13-
admin.EmailAddress.should == email
14-
admin.Name.should == "Admin One"
15-
admin.Status.should == "Active"
13+
admin.EmailAddress.should be == email
14+
admin.Name.should be == "Admin One"
15+
admin.Status.should be == "Active"
1616
end
1717

1818
should "add an administrator" do
1919
stub_post(@auth, "admins.json", "add_admin.json")
2020
result = CreateSend::Administrator.add @auth, "[email protected]", "Admin"
21-
result.EmailAddress.should == "[email protected]"
21+
result.EmailAddress.should be == "[email protected]"
2222
end
2323

2424
should "update an administrator" do
2525
2626
new_email = "[email protected]"
2727
stub_put(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", nil)
2828
@admin.update new_email, "Admin Name"
29-
@admin.email_address.should == new_email
29+
@admin.email_address.should be == new_email
3030
end
3131

3232
should "delete an admin" do

0 commit comments

Comments
 (0)