createsend 5.1.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +30 -0
  3. data/README.md +2 -2
  4. data/createsend.gemspec +1 -1
  5. data/lib/createsend/client.rb +19 -3
  6. data/lib/createsend/createsend.rb +1 -1
  7. data/lib/createsend/list.rb +13 -12
  8. data/lib/createsend/subscriber.rb +8 -4
  9. data/lib/createsend/version.rb +1 -1
  10. data/samples/authentication_sample.rb +64 -0
  11. data/samples/clients_sample.rb +79 -0
  12. data/samples/journey_sample.rb +3 -2
  13. data/samples/lists_sample.rb +51 -0
  14. data/samples/segments_sample.rb +21 -0
  15. data/samples/subscribers_sample.rb +51 -0
  16. data/test/administrator_test.rb +5 -5
  17. data/test/campaign_test.rb +114 -113
  18. data/test/client_test.rb +121 -98
  19. data/test/createsend_test.rb +47 -47
  20. data/test/fixtures/active_subscribers.json +5 -0
  21. data/test/fixtures/bounced_subscribers.json +1 -0
  22. data/test/fixtures/campaign_summary.json +2 -1
  23. data/test/fixtures/campaigns.json +37 -26
  24. data/test/fixtures/deleted_subscribers.json +5 -0
  25. data/test/fixtures/drafts.json +4 -2
  26. data/test/fixtures/scheduled_campaigns.json +4 -2
  27. data/test/fixtures/segment_subscribers.json +2 -0
  28. data/test/fixtures/subscriber_details.json +2 -0
  29. data/test/fixtures/{subscriber_details_with_track_pref.json → subscriber_details_with_track_and_sms_pref.json} +4 -1
  30. data/test/fixtures/tags.json +10 -0
  31. data/test/fixtures/unconfirmed_subscribers.json +6 -2
  32. data/test/fixtures/unsubscribed_subscribers.json +6 -1
  33. data/test/helper.rb +1 -1
  34. data/test/journey_test.rb +86 -86
  35. data/test/list_test.rb +130 -123
  36. data/test/person_test.rb +6 -6
  37. data/test/segment_test.rb +23 -22
  38. data/test/subscriber_test.rb +55 -51
  39. data/test/template_test.rb +5 -5
  40. data/test/transactional_classic_email_test.rb +6 -6
  41. data/test/transactional_smart_email_test.rb +19 -19
  42. data/test/transactional_timeline_test.rb +25 -25
  43. metadata +16 -113
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9e3ed5e50f1be54bdb680b399675fef8e72fc1e09d41264ec35d85de005b0ea
4
- data.tar.gz: 1b39dc69dcb31589101712316897771aa15ba48c8ddd5c6bd6255c2352337db3
3
+ metadata.gz: aacabbc393f38cd9a35d6c304c9cc0c1381173d0b13ec6133e477524cd126225
4
+ data.tar.gz: cec43502b0d8c4e71d0ec34ba441d7c04e10ff64ed28ae6cc85b4f3b37c7a31b
5
5
  SHA512:
6
- metadata.gz: c9d44f747b5d4e64692686c47a0ca56f13d55fe97a0674cfc20659e05b8a518df3ac45f33ab8b575945b1ac9dd69fa503c0884cfb74abdbc3c0f306a0642f7a7
7
- data.tar.gz: 68987336af46b08f9693bf65a1a6fc29af99ee81a044b1468b7a410084191a2e6973595ba1db86406be7c0c7cdace14a968e46e1f83754950bf3ef3a4c5e76a2
6
+ metadata.gz: db70e62fafe46cdae685f167076de7cf6d85c222933cd4c2110e8348f29a0b318d3be1d7ccb2c85d78837829c896f030e1dec45fc87318dd136e66b05f74e15a
7
+ data.tar.gz: 8a51368024b9db927b734d09c7f4473c79ecb6c2a71cddcc17ceafca5a07ad243f680d7dc24739667e1887aee75535ee307b61a30eb8fd9920f7f5b506e4a8ca
data/HISTORY.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # createsend-ruby history
2
2
 
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
+
16
+ ## v6.0.0 - 10 Feb, 2022
17
+ * Upgrades to Createsend API v3.3 which includes new breaking changes
18
+ * Breaking: 'client.campaigns' now returned an object to support pagination (use .Results to ge the array of campaigns)
19
+ * Added 'Tags' as another field that is returned in 'client.scheduled', 'client.drafts' and 'client.campaigns'
20
+ * Added 'Name' as another field that is returned in 'campaign.summary'
21
+ * Add new support for 'client.tags' endpoint (ie: getting list of tags for the client)
22
+ * Add support for pagination, filtering and sorting to 'client.campaigns' endpoint
23
+ * Bump `rake` to `~> 12.3.3`
24
+ * Adding support for returning ListJoinedDate for each subscriber.
25
+ * List.Active()
26
+ * List.Bounced()
27
+ * List.Unsubscribed()
28
+ * List.Unconfirmed()
29
+ * List.Deleted()
30
+ * Segment.Subscribers()
31
+ * Subscriber.Get()
32
+
3
33
  ## v5.1.1 - 8 Oct, 2021
4
34
  * increased default timeout for HTTP requests to 120secs
5
35
 
data/README.md CHANGED
@@ -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.campaigns.each do |cm|
136
+ client.drafts.each do |cm|
137
137
  p " - #{cm.Subject}"
138
138
  end
139
139
  end
@@ -194,7 +194,7 @@ 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
196
  email_address = CreateSend::Subscriber.add @auth, @list_id, "subscriber@example.com", "Subscriber", custom_fields, true, "Yes"
197
- email_address.should == "subscriber@example.com"
197
+ email_address.should be == "subscriber@example.com"
198
198
  end
199
199
  ```
200
200
 
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.0'
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'
@@ -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
- response = get 'campaigns'
30
- response.map{|item| Hashie::Mash.new(item)}
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'
@@ -111,7 +111,7 @@ module CreateSend
111
111
  end
112
112
  end
113
113
 
114
- @@base_uri = "https://api.createsend.com/api/v3.2"
114
+ @@base_uri = "https://api.createsend.com/api/v3.3"
115
115
  @@oauth_base_uri = "https://api.createsend.com/oauth"
116
116
  @@oauth_token_uri = "#{@@oauth_base_uri}/token"
117
117
  headers({
@@ -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", include_tracking_preference=false)
119
+ order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
120
120
  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)
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", include_tracking_preference=false)
126
+ order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
127
127
  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)
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", include_tracking_preference=false)
133
+ order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
134
134
  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)
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", include_tracking_preference=false)
140
+ order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
141
141
  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)
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", include_tracking_preference=false)
147
+ order_direction="asc", include_tracking_preference=false, include_sms_preference:false)
148
148
  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)
150
150
  end
151
151
 
152
152
  # Updates this list.
@@ -225,14 +225,15 @@ module CreateSend
225
225
  private
226
226
 
227
227
  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)
229
229
  options = { :query => {
230
230
  :date => date,
231
231
  :page => page,
232
232
  :pagesize => page_size,
233
233
  :orderfield => order_field,
234
234
  :orderdirection => order_direction,
235
- :includetrackingpreference => include_tracking_preference } }
235
+ :includetrackingpreference => include_tracking_preference,
236
+ :includesmspreference => include_sms_preference} }
236
237
  response = get resource, options
237
238
  Hashie::Mash.new(response)
238
239
  end
@@ -23,15 +23,17 @@ module CreateSend
23
23
 
24
24
  # Adds a subscriber to a subscriber list.
25
25
  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)
27
27
  options = { :body => {
28
28
  :EmailAddress => email_address,
29
29
  :Name => name,
30
+ :MobileNumber => mobile_number,
30
31
  :CustomFields => custom_fields,
31
32
  :Resubscribe => resubscribe,
32
33
  :RestartSubscriptionBasedAutoresponders =>
33
34
  restart_subscription_based_autoresponders,
34
- :ConsentToTrack => consent_to_track }.to_json }
35
+ :ConsentToTrack => consent_to_track,
36
+ :ConsentToSendSms => consent_to_send_sms }.to_json }
35
37
  cs = CreateSend.new auth
36
38
  response = cs.post "/subscribers/#{list_id}.json", options
37
39
  response.parsed_response
@@ -70,17 +72,19 @@ module CreateSend
70
72
  # Updates any aspect of a subscriber, including email address, name, and
71
73
  # custom field data if supplied.
72
74
  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)
74
76
  options = {
75
77
  :query => { :email => @email_address },
76
78
  :body => {
77
79
  :EmailAddress => new_email_address,
78
80
  :Name => name,
81
+ :MobileNumber => mobile_number,
79
82
  :CustomFields => custom_fields,
80
83
  :Resubscribe => resubscribe,
81
84
  :RestartSubscriptionBasedAutoresponders =>
82
85
  restart_subscription_based_autoresponders,
83
- :ConsentToTrack => consent_to_track }.to_json }
86
+ :ConsentToTrack => consent_to_track,
87
+ :ConsentToSendSms => consent_to_send_sms }.to_json }
84
88
  put "/subscribers/#{@list_id}.json", options
85
89
  # Update @email_address, so this object can continue to be used reliably
86
90
  @email_address = new_email_address
@@ -1,3 +1,3 @@
1
1
  module CreateSend
2
- VERSION = "5.1.1" unless defined?(CreateSend::VERSION)
2
+ VERSION = "6.1.0" unless defined?(CreateSend::VERSION)
3
3
  end
@@ -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"
@@ -5,12 +5,13 @@ class JourneySample
5
5
  @date = "2019-01-01 00:00"
6
6
 
7
7
  def initialize
8
- raise 'CREATESEND_API_KEY env var missing' if ENV['CREATESEND_API_KEY'].nil?
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?
9
10
  raise 'CREATESEND_CLIENT_ID env var missing' if ENV['CREATESEND_CLIENT_ID'].nil?
10
11
  raise 'CREATESEND_JOURNEY_ID env var missing' if ENV['CREATESEND_JOURNEY_ID'].nil?
11
12
  raise 'CREATESEND_EMAIL_ID env var missing' if ENV['CREATESEND_EMAIL_ID'].nil?
12
13
 
13
- auth = {:api_key => ENV['CREATESEND_API_KEY']}
14
+ auth = {:access_token => ENV['CREATESEND_ACCESS_TOKEN'], :refresh_token => ENV['CREATESEND_REFRESH_TOKEN']}
14
15
  @client = CreateSend::Client.new auth, ENV['CREATESEND_CLIENT_ID']
15
16
  @journey = CreateSend::Journey.new auth, ENV['CREATESEND_JOURNEY_ID']
16
17
  end
@@ -0,0 +1,51 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'createsend'
3
+
4
+ class ListsSample
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
+ @list = CreateSend::List.new auth, ENV['CREATESEND_LIST_ID']
12
+ end
13
+
14
+ def get_active_subscribers
15
+ @list.active()
16
+ end
17
+
18
+ def get_active_with_sms_preference_subscribers
19
+ @list.active(include_sms_preference:true)
20
+ end
21
+
22
+ def get_bounced_subscribers
23
+ @list.bounced
24
+ end
25
+
26
+ def get_unsubscribed_subscribers
27
+ @list.unsubscribed
28
+ end
29
+
30
+ def get_unsubscribed_with_sms_preference_subscribers
31
+ @list.unsubscribed(include_sms_preference:true)
32
+ end
33
+
34
+ def get_unconfirmed_subscribers
35
+ @list.unconfirmed
36
+ end
37
+
38
+ def get_deleted_subscribers
39
+ @list.deleted
40
+ end
41
+ end
42
+
43
+ sample = ListsSample.new
44
+
45
+ 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"
47
+ puts "All bounced subscribers: #{sample.get_bounced_subscribers.to_json}\n\n"
48
+ 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"
51
+ puts "All deleted subscribers: #{sample.get_deleted_subscribers.to_json}\n\n"
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'createsend'
3
+
4
+ class SegmentsSample
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_SEGMENT_ID env var missing' if ENV['CREATESEND_SEGMENT_ID'].nil?
9
+
10
+ auth = {:access_token => ENV['CREATESEND_ACCESS_TOKEN'], :refresh_token => ENV['CREATESEND_REFRESH_TOKEN']}
11
+ @segment = CreateSend::Segment.new auth, ENV['CREATESEND_SEGMENT_ID']
12
+ end
13
+
14
+ def get_active_subscribers
15
+ @segment.subscribers
16
+ end
17
+ end
18
+
19
+ sample = SegmentsSample.new
20
+
21
+ puts "All active subscribers: #{sample.get_active_subscribers.to_json}\n\n"
@@ -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"
@@ -10,15 +10,15 @@ class AdministratorTest < Test::Unit::TestCase
10
10
  email = "admin@example.com"
11
11
  stub_get(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", "admin_details.json")
12
12
  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"
16
16
  end
17
17
 
18
18
  should "add an administrator" do
19
19
  stub_post(@auth, "admins.json", "add_admin.json")
20
20
  result = CreateSend::Administrator.add @auth, "admin@example.com", "Admin"
21
- result.EmailAddress.should == "admin@example.com"
21
+ result.EmailAddress.should be == "admin@example.com"
22
22
  end
23
23
 
24
24
  should "update an administrator" do
@@ -26,7 +26,7 @@ class AdministratorTest < Test::Unit::TestCase
26
26
  new_email = "new_email_address@example.com"
27
27
  stub_put(@auth, "admins.json?email=#{ERB::Util.url_encode(email)}", nil)
28
28
  @admin.update new_email, "Admin Name"
29
- @admin.email_address.should == new_email
29
+ @admin.email_address.should be == new_email
30
30
  end
31
31
 
32
32
  should "delete an admin" do