createsend-sendowlfork 6.1.0.pre.hashie5

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 (139) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +7 -0
  5. data/CONTRIBUTING.md +8 -0
  6. data/Gemfile +3 -0
  7. data/HISTORY.md +299 -0
  8. data/LICENSE +19 -0
  9. data/README.md +220 -0
  10. data/RELEASE.md +53 -0
  11. data/Rakefile +24 -0
  12. data/createsend.gemspec +31 -0
  13. data/lib/createsend/administrator.rb +49 -0
  14. data/lib/createsend/cacert.pem +3849 -0
  15. data/lib/createsend/campaign.rb +202 -0
  16. data/lib/createsend/client.rb +224 -0
  17. data/lib/createsend/createsend.rb +291 -0
  18. data/lib/createsend/journey.rb +58 -0
  19. data/lib/createsend/list.rb +258 -0
  20. data/lib/createsend/person.rb +59 -0
  21. data/lib/createsend/segment.rb +81 -0
  22. data/lib/createsend/subscriber.rb +113 -0
  23. data/lib/createsend/template.rb +42 -0
  24. data/lib/createsend/transactional_classic_email.rb +32 -0
  25. data/lib/createsend/transactional_smart_email.rb +31 -0
  26. data/lib/createsend/transactional_timeline.rb +45 -0
  27. data/lib/createsend/version.rb +3 -0
  28. data/lib/createsend.rb +17 -0
  29. data/samples/authentication_sample.rb +64 -0
  30. data/samples/clients_sample.rb +79 -0
  31. data/samples/journey_sample.rb +87 -0
  32. data/samples/lists_sample.rb +51 -0
  33. data/samples/segments_sample.rb +21 -0
  34. data/samples/subscribers_sample.rb +51 -0
  35. data/test/administrator_test.rb +37 -0
  36. data/test/campaign_test.rb +296 -0
  37. data/test/client_test.rb +253 -0
  38. data/test/createsend_test.rb +321 -0
  39. data/test/fixtures/active_subscribers.json +87 -0
  40. data/test/fixtures/add_admin.json +3 -0
  41. data/test/fixtures/add_person.json +3 -0
  42. data/test/fixtures/add_subscriber.json +1 -0
  43. data/test/fixtures/admin_details.json +5 -0
  44. data/test/fixtures/admin_get_primary_contact.json +3 -0
  45. data/test/fixtures/admin_set_primary_contact.json +3 -0
  46. data/test/fixtures/administrators.json +12 -0
  47. data/test/fixtures/billingdetails.json +3 -0
  48. data/test/fixtures/bounced_subscribers.json +20 -0
  49. data/test/fixtures/campaign_bounces.json +25 -0
  50. data/test/fixtures/campaign_clicks.json +50 -0
  51. data/test/fixtures/campaign_listsandsegments.json +15 -0
  52. data/test/fixtures/campaign_opens.json +71 -0
  53. data/test/fixtures/campaign_recipients.json +91 -0
  54. data/test/fixtures/campaign_spam.json +16 -0
  55. data/test/fixtures/campaign_summary.json +16 -0
  56. data/test/fixtures/campaign_unsubscribes.json +17 -0
  57. data/test/fixtures/campaigns.json +37 -0
  58. data/test/fixtures/client_details.json +28 -0
  59. data/test/fixtures/client_get_primary_contact.json +3 -0
  60. data/test/fixtures/client_set_primary_contact.json +3 -0
  61. data/test/fixtures/clients.json +10 -0
  62. data/test/fixtures/countries.json +247 -0
  63. data/test/fixtures/create_campaign.json +1 -0
  64. data/test/fixtures/create_client.json +1 -0
  65. data/test/fixtures/create_custom_field.json +1 -0
  66. data/test/fixtures/create_list.json +1 -0
  67. data/test/fixtures/create_list_webhook.json +1 -0
  68. data/test/fixtures/create_segment.json +1 -0
  69. data/test/fixtures/create_template.json +1 -0
  70. data/test/fixtures/custom_api_error.json +4 -0
  71. data/test/fixtures/custom_fields.json +23 -0
  72. data/test/fixtures/deleted_subscribers.json +61 -0
  73. data/test/fixtures/drafts.json +26 -0
  74. data/test/fixtures/email_client_usage.json +38 -0
  75. data/test/fixtures/expired_oauth_token_api_error.json +4 -0
  76. data/test/fixtures/external_session.json +3 -0
  77. data/test/fixtures/import_subscribers.json +7 -0
  78. data/test/fixtures/import_subscribers_partial_success.json +17 -0
  79. data/test/fixtures/invalid_oauth_token_api_error.json +4 -0
  80. data/test/fixtures/journey_bounces.json +35 -0
  81. data/test/fixtures/journey_clicks.json +35 -0
  82. data/test/fixtures/journey_opens.json +55 -0
  83. data/test/fixtures/journey_recipients.json +27 -0
  84. data/test/fixtures/journey_summary.json +18 -0
  85. data/test/fixtures/journey_unsubscribes.json +26 -0
  86. data/test/fixtures/journeys.json +20 -0
  87. data/test/fixtures/list_details.json +8 -0
  88. data/test/fixtures/list_stats.json +26 -0
  89. data/test/fixtures/list_webhooks.json +18 -0
  90. data/test/fixtures/lists.json +10 -0
  91. data/test/fixtures/listsforemail.json +14 -0
  92. data/test/fixtures/oauth_exchange_token.json +5 -0
  93. data/test/fixtures/oauth_exchange_token_error.json +4 -0
  94. data/test/fixtures/oauth_refresh_token_error.json +4 -0
  95. data/test/fixtures/people.json +14 -0
  96. data/test/fixtures/person_details.json +6 -0
  97. data/test/fixtures/refresh_oauth_token.json +5 -0
  98. data/test/fixtures/revoked_oauth_token_api_error.json +4 -0
  99. data/test/fixtures/scheduled_campaigns.json +30 -0
  100. data/test/fixtures/segment_details.json +24 -0
  101. data/test/fixtures/segment_subscribers.json +27 -0
  102. data/test/fixtures/segments.json +12 -0
  103. data/test/fixtures/subscriber_details.json +23 -0
  104. data/test/fixtures/subscriber_details_with_track_and_sms_pref.json +25 -0
  105. data/test/fixtures/subscriber_history.json +45 -0
  106. data/test/fixtures/suppressionlist.json +41 -0
  107. data/test/fixtures/systemdate.json +3 -0
  108. data/test/fixtures/tags.json +10 -0
  109. data/test/fixtures/template_details.json +6 -0
  110. data/test/fixtures/templates.json +14 -0
  111. data/test/fixtures/timezones.json +99 -0
  112. data/test/fixtures/transfer_credits.json +4 -0
  113. data/test/fixtures/tx_classicemail_groups.json +14 -0
  114. data/test/fixtures/tx_message_details.json +36 -0
  115. data/test/fixtures/tx_message_details_with_statistics.json +72 -0
  116. data/test/fixtures/tx_messages.json +38 -0
  117. data/test/fixtures/tx_messages_classic.json +15 -0
  118. data/test/fixtures/tx_messages_smart.json +15 -0
  119. data/test/fixtures/tx_resend_message.json +6 -0
  120. data/test/fixtures/tx_send_multiple.json +12 -0
  121. data/test/fixtures/tx_send_single.json +7 -0
  122. data/test/fixtures/tx_smartemail_details.json +23 -0
  123. data/test/fixtures/tx_smartemails.json +15 -0
  124. data/test/fixtures/tx_statistics_classic.json +14 -0
  125. data/test/fixtures/tx_statistics_smart.json +14 -0
  126. data/test/fixtures/unconfirmed_subscribers.json +43 -0
  127. data/test/fixtures/unsubscribed_subscribers.json +61 -0
  128. data/test/fixtures/update_custom_field.json +1 -0
  129. data/test/helper.rb +79 -0
  130. data/test/journey_test.rb +156 -0
  131. data/test/list_test.rb +288 -0
  132. data/test/person_test.rb +39 -0
  133. data/test/segment_test.rb +74 -0
  134. data/test/subscriber_test.rb +177 -0
  135. data/test/template_test.rb +36 -0
  136. data/test/transactional_classic_email_test.rb +60 -0
  137. data/test/transactional_smart_email_test.rb +83 -0
  138. data/test/transactional_timeline_test.rb +110 -0
  139. metadata +431 -0
@@ -0,0 +1,81 @@
1
+ module CreateSend
2
+ # Represents a subscriber list segment and associated functionality.
3
+ class Segment < CreateSend
4
+ attr_reader :segment_id
5
+
6
+ def initialize(auth, segment_id)
7
+ @segment_id = segment_id
8
+ super
9
+ end
10
+
11
+ # Creates a new segment.
12
+ def self.create(auth, list_id, title, rule_groups)
13
+ options = { :body => {
14
+ :Title => title,
15
+ :RuleGroups => rule_groups }.to_json }
16
+ cs = CreateSend.new auth
17
+ response = cs.post "/segments/#{list_id}.json", options
18
+ response.parsed_response
19
+ end
20
+
21
+ # Updates this segment.
22
+ def update(title, rule_groups)
23
+ options = { :body => {
24
+ :Title => title,
25
+ :RuleGroups => rule_groups }.to_json }
26
+ cs_put "/segments/#{segment_id}.json", options
27
+ end
28
+
29
+ # Adds a rule to this segment.
30
+ def add_rule_group(rule_group)
31
+ options = { :body => {
32
+ :Rules => rule_group }.to_json }
33
+ post "rules", options
34
+ end
35
+
36
+ # Gets the active subscribers in this segment.
37
+ def subscribers(date="", page=1, page_size=1000, order_field="email",
38
+ order_direction="asc", include_tracking_preference=false)
39
+ options = { :query => {
40
+ :date => date,
41
+ :page => page,
42
+ :pagesize => page_size,
43
+ :orderfield => order_field,
44
+ :orderdirection => order_direction,
45
+ :includetrackingpreference => include_tracking_preference } }
46
+ response = get "active", options
47
+ Hashie::Mash.new(response)
48
+ end
49
+
50
+ # Gets the details of this segment
51
+ def details
52
+ response = cs_get "/segments/#{segment_id}.json", {}
53
+ Hashie::Mash.new(response)
54
+ end
55
+
56
+ # Clears all rules of this segment.
57
+ def clear_rules
58
+ cs_delete "/segments/#{segment_id}/rules.json", {}
59
+ end
60
+
61
+ # Deletes this segment.
62
+ def delete
63
+ super "/segments/#{segment_id}.json", {}
64
+ end
65
+
66
+ private
67
+
68
+ def get(action, options = {})
69
+ super uri_for(action), options
70
+ end
71
+
72
+ def post(action, options = {})
73
+ super uri_for(action), options
74
+ end
75
+
76
+ def uri_for(action)
77
+ "/segments/#{segment_id}/#{action}.json"
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,113 @@
1
+ module CreateSend
2
+ # Represents a subscriber and associated functionality.
3
+ class Subscriber < CreateSend
4
+ attr_reader :list_id
5
+ attr_reader :email_address
6
+
7
+ def initialize(auth, list_id, email_address)
8
+ @list_id = list_id
9
+ @email_address = email_address
10
+ super
11
+ end
12
+
13
+ # Gets a subscriber by list ID and 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
+ }
19
+ cs = CreateSend.new auth
20
+ response = cs.get "/subscribers/#{list_id}.json", options
21
+ Hashie::Mash.new(response)
22
+ end
23
+
24
+ # Adds a subscriber to a subscriber list.
25
+ def self.add(auth, list_id, email_address, name, custom_fields, resubscribe,
26
+ consent_to_track, restart_subscription_based_autoresponders=false, mobile_number=nil, consent_to_send_sms=nil)
27
+ options = { :body => {
28
+ :EmailAddress => email_address,
29
+ :Name => name,
30
+ :MobileNumber => mobile_number,
31
+ :CustomFields => custom_fields,
32
+ :Resubscribe => resubscribe,
33
+ :RestartSubscriptionBasedAutoresponders =>
34
+ restart_subscription_based_autoresponders,
35
+ :ConsentToTrack => consent_to_track,
36
+ :ConsentToSendSms => consent_to_send_sms }.to_json }
37
+ cs = CreateSend.new auth
38
+ response = cs.post "/subscribers/#{list_id}.json", options
39
+ response.parsed_response
40
+ end
41
+
42
+ # Imports subscribers into a subscriber list.
43
+ def self.import(auth, list_id, subscribers, resubscribe,
44
+ queue_subscription_based_autoresponders=false,
45
+ restart_subscription_based_autoresponders=false)
46
+ options = { :body => {
47
+ :Subscribers => subscribers,
48
+ :Resubscribe => resubscribe,
49
+ :QueueSubscriptionBasedAutoresponders =>
50
+ queue_subscription_based_autoresponders,
51
+ :RestartSubscriptionBasedAutoresponders =>
52
+ restart_subscription_based_autoresponders }.to_json }
53
+ begin
54
+ cs = CreateSend.new auth
55
+ response = cs.post(
56
+ "/subscribers/#{list_id}/import.json", options)
57
+ rescue BadRequest => br
58
+ # Subscriber import will throw BadRequest if some subscribers are not
59
+ # imported successfully. If this occurs, we want to return the
60
+ # ResultData property of the BadRequest exception (which is of the
61
+ # same "form" as the response we would receive upon a completely
62
+ # successful import).
63
+ if br.data.ResultData
64
+ return br.data.ResultData
65
+ else
66
+ raise br # Just raise other Bad Request errors
67
+ end
68
+ end
69
+ Hashie::Mash.new(response)
70
+ end
71
+
72
+ # Updates any aspect of a subscriber, including email address, name, and
73
+ # custom field data if supplied.
74
+ def update(new_email_address, name, custom_fields, resubscribe,
75
+ consent_to_track, restart_subscription_based_autoresponders=false, mobile_number=nil, consent_to_send_sms=nil)
76
+ options = {
77
+ :query => { :email => @email_address },
78
+ :body => {
79
+ :EmailAddress => new_email_address,
80
+ :Name => name,
81
+ :MobileNumber => mobile_number,
82
+ :CustomFields => custom_fields,
83
+ :Resubscribe => resubscribe,
84
+ :RestartSubscriptionBasedAutoresponders =>
85
+ restart_subscription_based_autoresponders,
86
+ :ConsentToTrack => consent_to_track,
87
+ :ConsentToSendSms => consent_to_send_sms }.to_json }
88
+ put "/subscribers/#{@list_id}.json", options
89
+ # Update @email_address, so this object can continue to be used reliably
90
+ @email_address = new_email_address
91
+ end
92
+
93
+ # Unsubscribes this subscriber from the associated list.
94
+ def unsubscribe
95
+ options = { :body => {
96
+ :EmailAddress => @email_address }.to_json }
97
+ post "/subscribers/#{@list_id}/unsubscribe.json", options
98
+ end
99
+
100
+ # Gets the historical record of this subscriber's trackable actions.
101
+ def history
102
+ options = { :query => { :email => @email_address } }
103
+ response = cs_get "/subscribers/#{@list_id}/history.json", options
104
+ response.map{|item| Hashie::Mash.new(item)}
105
+ end
106
+
107
+ # Moves this subscriber to the Deleted state in the associated list.
108
+ def delete
109
+ options = { :query => { :email => @email_address } }
110
+ super "/subscribers/#{@list_id}.json", options
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,42 @@
1
+ module CreateSend
2
+ # Represents an email template and associated functionality.
3
+ class Template < CreateSend
4
+ attr_reader :template_id
5
+
6
+ def initialize(auth, template_id)
7
+ @template_id = template_id
8
+ super
9
+ end
10
+
11
+ # Creates a new email template.
12
+ def self.create(auth, client_id, name, html_url, zip_url)
13
+ options = { :body => {
14
+ :Name => name,
15
+ :HtmlPageURL => html_url,
16
+ :ZipFileURL => zip_url }.to_json }
17
+ cs = CreateSend.new auth
18
+ response = cs.post "/templates/#{client_id}.json", options
19
+ response.parsed_response
20
+ end
21
+
22
+ # Gets the details of this email template.
23
+ def details
24
+ response = get "/templates/#{template_id}.json", {}
25
+ Hashie::Mash.new(response)
26
+ end
27
+
28
+ # Updates this email template.
29
+ def update(name, html_url, zip_url)
30
+ options = { :body => {
31
+ :Name => name,
32
+ :HtmlPageURL => html_url,
33
+ :ZipFileURL => zip_url }.to_json }
34
+ put "/templates/#{template_id}.json", options
35
+ end
36
+
37
+ # Deletes this email template.
38
+ def delete
39
+ super "/templates/#{template_id}.json", {}
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ module CreateSend
2
+ module Transactional
3
+ class ClassicEmail < CreateSend
4
+ attr_accessor :options
5
+
6
+ def initialize(auth, client_id = nil)
7
+ @auth = auth
8
+ @client_id = client_id
9
+ super
10
+ end
11
+
12
+ def send(options)
13
+ response = post "/transactional/classicemail/send", { :body => options.to_json , :query => client_id }
14
+ response.map{|item| Hashie::Mash.new(item)}
15
+ end
16
+
17
+ def groups
18
+ response = get "/transactional/classicemail/groups", :query => client_id
19
+ response.map{|item| Hashie::Mash.new(item)}
20
+ end
21
+
22
+ private
23
+
24
+ def client_id
25
+ {:clientID => @client_id} if @client_id
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+
32
+
@@ -0,0 +1,31 @@
1
+ module CreateSend
2
+ module Transactional
3
+ class SmartEmail < CreateSend
4
+ attr_reader :smart_email_id
5
+
6
+ def self.list(auth, options = nil)
7
+ cs = CreateSend.new auth
8
+ response = cs.get "/transactional/smartemail", :query => options
9
+ response.map{|item| Hashie::Mash.new(item)}
10
+ end
11
+
12
+ def initialize(auth, smart_email_id)
13
+ @auth = auth
14
+ @smart_email_id = smart_email_id
15
+ super
16
+ end
17
+
18
+ def details
19
+ response = get "/transactional/smartemail/#{@smart_email_id}"
20
+ Hashie::Mash.new(response)
21
+ end
22
+
23
+ def send(options)
24
+ response = post "/transactional/smartemail/#{@smart_email_id}/send", { :body => options.to_json }
25
+ response.map{|item| Hashie::Mash.new(item)}
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,45 @@
1
+ module CreateSend
2
+ module Transactional
3
+ class Timeline < CreateSend
4
+ attr_reader :client_id
5
+
6
+ def initialize(auth, client_id = nil)
7
+ @auth = auth
8
+ @client_id = client_id
9
+ super
10
+ end
11
+
12
+ def messages(options = {})
13
+ options = add_client_id(options)
14
+ response = get "/transactional/messages", { :query => options }
15
+ response.map{|item| Hashie::Mash.new(item)}
16
+ end
17
+
18
+ def statistics(options = {})
19
+ options = add_client_id(options)
20
+ response = get "/transactional/statistics", { :query => options }
21
+ Hashie::Mash.new(response)
22
+ end
23
+
24
+ def details(message_id, options = {})
25
+ options = add_client_id(options)
26
+ response = get "/transactional/messages/#{message_id}", { :query => options }
27
+ Hashie::Mash.new(response)
28
+ end
29
+
30
+ def resend(message_id)
31
+ response = post "/transactional/messages/#{message_id}/resend"
32
+ response.map{|item| Hashie::Mash.new(item)}
33
+ end
34
+
35
+ private
36
+
37
+ def add_client_id(options)
38
+ options['clientID'] = @client_id if @client_id
39
+ options
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,3 @@
1
+ module CreateSend
2
+ VERSION = "6.1.0-hashie5" unless defined?(CreateSend::VERSION)
3
+ end
data/lib/createsend.rb ADDED
@@ -0,0 +1,17 @@
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+
4
+ require 'createsend/version'
5
+ require 'createsend/createsend'
6
+ require 'createsend/client'
7
+ require 'createsend/campaign'
8
+ require 'createsend/list'
9
+ require 'createsend/segment'
10
+ require 'createsend/subscriber'
11
+ require 'createsend/template'
12
+ require 'createsend/person'
13
+ require 'createsend/administrator'
14
+ require 'createsend/transactional_classic_email'
15
+ require 'createsend/transactional_smart_email'
16
+ require 'createsend/transactional_timeline'
17
+ require 'createsend/journey'
@@ -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"
@@ -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"