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,202 @@
1
+ module CreateSend
2
+ # Represents a campaign and provides associated functionality.
3
+ class Campaign < CreateSend
4
+ attr_reader :campaign_id
5
+
6
+ def initialize(auth, campaign_id)
7
+ @campaign_id = campaign_id
8
+ super
9
+ end
10
+
11
+ # Creates a new campaign for a client.
12
+ # client_id - String representing the ID of the client for whom the
13
+ # campaign will be created.
14
+ # subject - String representing the subject of the campaign.
15
+ # name - String representing the name of the campaign.
16
+ # from_name - String representing the from name for the campaign.
17
+ # from_email - String representing the from address for the campaign.
18
+ # reply_to - String representing the reply-to address for the campaign.
19
+ # html_url - String representing the URL for the campaign HTML content.
20
+ # text_url - String representing the URL for the campaign text content.
21
+ # Note that text_url is optional and if nil or an empty string, text
22
+ # content will be automatically generated from the HTML content.
23
+ # list_ids - Array of Strings representing the IDs of the lists to
24
+ # which the campaign will be sent.
25
+ # segment_ids - Array of Strings representing the IDs of the segments to
26
+ # which the campaign will be sent.
27
+ def self.create(auth, client_id, subject, name, from_name, from_email,
28
+ reply_to, html_url, text_url, list_ids, segment_ids)
29
+ options = { :body => {
30
+ :Subject => subject,
31
+ :Name => name,
32
+ :FromName => from_name,
33
+ :FromEmail => from_email,
34
+ :ReplyTo => reply_to,
35
+ :HtmlUrl => html_url,
36
+ :TextUrl => text_url,
37
+ :ListIDs => list_ids,
38
+ :SegmentIDs => segment_ids }.to_json }
39
+ cs = CreateSend.new auth
40
+ response = cs.post "/campaigns/#{client_id}.json", options
41
+ response.parsed_response
42
+ end
43
+
44
+ # Creates a new campaign for a client, from a template.
45
+ # client_id - String representing the ID of the client for whom the
46
+ # campaign will be created.
47
+ # subject - String representing the subject of the campaign.
48
+ # name - String representing the name of the campaign.
49
+ # from_name - String representing the from name for the campaign.
50
+ # from_email - String representing the from address for the campaign.
51
+ # reply_to - String representing the reply-to address for the campaign.
52
+ # list_ids - Array of Strings representing the IDs of the lists to
53
+ # which the campaign will be sent.
54
+ # segment_ids - Array of Strings representing the IDs of the segments to
55
+ # which the campaign will be sent.
56
+ # template_id - String representing the ID of the template on which
57
+ # the campaign will be based.
58
+ # template_content - Hash representing the content to be used for the
59
+ # editable areas of the template. See documentation at
60
+ # campaignmonitor.com/api/campaigns/#creating_a_campaign_from_template
61
+ # for full details of template content format.
62
+ def self.create_from_template(auth, client_id, subject, name, from_name,
63
+ from_email, reply_to, list_ids, segment_ids, template_id,
64
+ template_content)
65
+ options = { :body => {
66
+ :Subject => subject,
67
+ :Name => name,
68
+ :FromName => from_name,
69
+ :FromEmail => from_email,
70
+ :ReplyTo => reply_to,
71
+ :ListIDs => list_ids,
72
+ :SegmentIDs => segment_ids,
73
+ :TemplateID => template_id,
74
+ :TemplateContent => template_content }.to_json }
75
+ cs = CreateSend.new auth
76
+ response = cs.post(
77
+ "/campaigns/#{client_id}/fromtemplate.json", options)
78
+ response.parsed_response
79
+ end
80
+
81
+ # Sends a preview of this campaign.
82
+ def send_preview(recipients, personalize="fallback")
83
+ options = { :body => {
84
+ :PreviewRecipients => recipients.kind_of?(String) ?
85
+ [ recipients ] : recipients,
86
+ :Personalize => personalize }.to_json }
87
+ post "sendpreview", options
88
+ end
89
+
90
+ # Sends this campaign.
91
+ def send(confirmation_email, send_date="immediately")
92
+ options = { :body => {
93
+ :ConfirmationEmail => confirmation_email,
94
+ :SendDate => send_date }.to_json }
95
+ post "send", options
96
+ end
97
+
98
+ # Unschedules this campaign if it is currently scheduled.
99
+ def unschedule
100
+ options = { :body => "" }
101
+ post "unschedule", options
102
+ end
103
+
104
+ # Deletes this campaign.
105
+ def delete
106
+ super "/campaigns/#{campaign_id}.json", {}
107
+ end
108
+
109
+ # Gets a summary of this campaign
110
+ def summary
111
+ response = get "summary", {}
112
+ Hashie::Mash.new(response)
113
+ end
114
+
115
+ # Gets the email clients that subscribers used to open the campaign
116
+ def email_client_usage
117
+ response = get "emailclientusage", {}
118
+ response.map{|item| Hashie::Mash.new(item)}
119
+ end
120
+
121
+ # Retrieves the lists and segments to which this campaaign will
122
+ # be (or was) sent.
123
+ def lists_and_segments
124
+ response = get "listsandsegments", {}
125
+ Hashie::Mash.new(response)
126
+ end
127
+
128
+ # Retrieves the recipients of this campaign.
129
+ def recipients(page=1, page_size=1000, order_field="email",
130
+ order_direction="asc")
131
+ options = { :query => {
132
+ :page => page,
133
+ :pagesize => page_size,
134
+ :orderfield => order_field,
135
+ :orderdirection => order_direction } }
136
+ response = get 'recipients', options
137
+ Hashie::Mash.new(response)
138
+ end
139
+
140
+ # Retrieves the opens for this campaign.
141
+ def opens(date="", page=1, page_size=1000, order_field="date",
142
+ order_direction="asc")
143
+ paged_result_by_date("opens", date, page, page_size, order_field,
144
+ order_direction)
145
+ end
146
+
147
+ # Retrieves the subscriber clicks for this campaign.
148
+ def clicks(date="", page=1, page_size=1000, order_field="date",
149
+ order_direction="asc")
150
+ paged_result_by_date("clicks", date, page, page_size, order_field,
151
+ order_direction)
152
+ end
153
+
154
+ # Retrieves the unsubscribes for this campaign.
155
+ def unsubscribes(date="", page=1, page_size=1000, order_field="date",
156
+ order_direction="asc")
157
+ paged_result_by_date("unsubscribes", date, page, page_size, order_field,
158
+ order_direction)
159
+ end
160
+
161
+ # Retrieves the spam complaints for this campaign.
162
+ def spam(date="", page=1, page_size=1000, order_field="date",
163
+ order_direction="asc")
164
+ paged_result_by_date("spam", date, page, page_size, order_field,
165
+ order_direction)
166
+ end
167
+
168
+ # Retrieves the bounces for this campaign.
169
+ def bounces(date="", page=1, page_size=1000, order_field="date",
170
+ order_direction="asc")
171
+ paged_result_by_date("bounces", date, page, page_size, order_field,
172
+ order_direction)
173
+ end
174
+
175
+ private
176
+
177
+ def paged_result_by_date(resource, date, page, page_size, order_field,
178
+ order_direction)
179
+ options = { :query => {
180
+ :date => date,
181
+ :page => page,
182
+ :pagesize => page_size,
183
+ :orderfield => order_field,
184
+ :orderdirection => order_direction } }
185
+ response = get resource, options
186
+ Hashie::Mash.new(response)
187
+ end
188
+
189
+ def get(action, options = {})
190
+ super uri_for(action), options
191
+ end
192
+
193
+ def post(action, options = {})
194
+ super uri_for(action), options
195
+ end
196
+
197
+ def uri_for(action)
198
+ "/campaigns/#{campaign_id}/#{action}.json"
199
+ end
200
+
201
+ end
202
+ end
@@ -0,0 +1,224 @@
1
+ module CreateSend
2
+ # Represents a client and associated functionality.
3
+ class Client < CreateSend
4
+ attr_reader :client_id
5
+
6
+ def initialize(auth, client_id)
7
+ @client_id = client_id
8
+ super
9
+ end
10
+
11
+ # Creates a client.
12
+ def self.create(auth, company, timezone, country)
13
+ options = { :body => {
14
+ :CompanyName => company,
15
+ :TimeZone => timezone,
16
+ :Country => country }.to_json }
17
+ cs = CreateSend.new auth
18
+ cs.post "/clients.json", options
19
+ end
20
+
21
+ # Gets the details of this client.
22
+ def details
23
+ response = cs_get "/clients/#{client_id}.json", {}
24
+ Hashie::Mash.new(response)
25
+ end
26
+
27
+ # Gets the sent campaigns belonging to this client.
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)
41
+ end
42
+
43
+ # Gets the currently scheduled campaigns belonging to this client.
44
+ def scheduled
45
+ response = get 'scheduled'
46
+ response.map{|item| Hashie::Mash.new(item)}
47
+ end
48
+
49
+ # Gets the draft campaigns belonging to this client.
50
+ def drafts
51
+ response = get 'drafts'
52
+ response.map{|item| Hashie::Mash.new(item)}
53
+ end
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
+
61
+ # Gets the subscriber lists belonging to this client.
62
+ def lists
63
+ response = get 'lists'
64
+ response.map{|item| Hashie::Mash.new(item)}
65
+ end
66
+
67
+ # Gets the lists across a client, to which a subscriber with a particular
68
+ # email address belongs.
69
+ # email_address - A String representing the subcriber's email address
70
+ def lists_for_email(email_address)
71
+ options = { :query => { :email => email_address } }
72
+ response = get 'listsforemail', options
73
+ response.map{|item| Hashie::Mash.new(item)}
74
+ end
75
+
76
+ # Gets the segments belonging to this client.
77
+ def segments
78
+ response = get 'segments'
79
+ response.map{|item| Hashie::Mash.new(item)}
80
+ end
81
+
82
+ # Gets the people associated with this client
83
+ def people
84
+ response = get "people"
85
+ response.map{|item| Hashie::Mash.new(item)}
86
+ end
87
+
88
+ def get_primary_contact
89
+ response = get "primarycontact"
90
+ Hashie::Mash.new(response)
91
+ end
92
+
93
+ def set_primary_contact(email)
94
+ options = { :query => { :email => email } }
95
+ response = put "primarycontact", options
96
+ Hashie::Mash.new(response)
97
+ end
98
+
99
+ # Gets this client's suppression list.
100
+ def suppressionlist(page=1, page_size=1000, order_field="email",
101
+ order_direction="asc")
102
+ options = { :query => {
103
+ :page => page,
104
+ :pagesize => page_size,
105
+ :orderfield => order_field,
106
+ :orderdirection => order_direction } }
107
+ response = get 'suppressionlist', options
108
+ Hashie::Mash.new(response)
109
+ end
110
+
111
+ # Adds email addresses to a client's suppression list
112
+ def suppress(emails)
113
+ options = { :body => {
114
+ :EmailAddresses => emails.kind_of?(String) ?
115
+ [ emails ] : emails }.to_json }
116
+ post "suppress", options
117
+ end
118
+
119
+ # Unsuppresses an email address by removing it from the the client's
120
+ # suppression list
121
+ def unsuppress(email)
122
+ options = { :query => { :email => email }, :body => '' }
123
+ put "unsuppress", options
124
+ end
125
+
126
+ # Gets the templates belonging to this client.
127
+ def templates
128
+ response = get 'templates'
129
+ response.map{|item| Hashie::Mash.new(item)}
130
+ end
131
+
132
+ # Sets the basic details for this client.
133
+ def set_basics(company, timezone, country)
134
+ options = { :body => {
135
+ :CompanyName => company,
136
+ :TimeZone => timezone,
137
+ :Country => country }.to_json }
138
+ put 'setbasics', options
139
+ end
140
+
141
+ # Sets the PAYG billing settings for this client.
142
+ def set_payg_billing(currency, can_purchase_credits, client_pays,
143
+ markup_percentage, markup_on_delivery=0, markup_per_recipient=0,
144
+ markup_on_design_spam_test=0)
145
+ options = { :body => {
146
+ :Currency => currency,
147
+ :CanPurchaseCredits => can_purchase_credits,
148
+ :ClientPays => client_pays,
149
+ :MarkupPercentage => markup_percentage,
150
+ :MarkupOnDelivery => markup_on_delivery,
151
+ :MarkupPerRecipient => markup_per_recipient,
152
+ :MarkupOnDesignSpamTest => markup_on_design_spam_test }.to_json }
153
+ put 'setpaygbilling', options
154
+ end
155
+
156
+ # Sets the monthly billing settings for this client.
157
+ # monthly_scheme must be nil, Basic or Unlimited
158
+ def set_monthly_billing(currency, client_pays, markup_percentage,
159
+ monthly_scheme = nil)
160
+ options = { :body => {
161
+ :Currency => currency,
162
+ :ClientPays => client_pays,
163
+ :MarkupPercentage => markup_percentage,
164
+ :MonthlyScheme => monthly_scheme }.to_json }
165
+ put 'setmonthlybilling', options
166
+ end
167
+
168
+ # Transfer credits to or from this client.
169
+ #
170
+ # credits - An Integer representing the number of credits to transfer.
171
+ # This value may be either positive if you want to allocate credits from
172
+ # your account to the client, or negative if you want to deduct credits
173
+ # from the client back into your account.
174
+ # can_use_my_credits_when_they_run_out - A Boolean value representing
175
+ # which, if set to true, will allow the client to continue sending using
176
+ # your credits or payment details once they run out of credits, and if
177
+ # set to false, will prevent the client from using your credits to
178
+ # continue sending until you allocate more credits to them.
179
+ #
180
+ # Returns an object of the following form representing the result:
181
+ # {
182
+ # AccountCredits # Integer representing credits in your account now
183
+ # ClientCredits # Integer representing credits in this client's
184
+ # account now
185
+ # }
186
+ def transfer_credits(credits, can_use_my_credits_when_they_run_out)
187
+ options = { :body => {
188
+ :Credits => credits,
189
+ :CanUseMyCreditsWhenTheyRunOut => can_use_my_credits_when_they_run_out
190
+ }.to_json }
191
+ response = post 'credits', options
192
+ Hashie::Mash.new(response)
193
+ end
194
+
195
+ # Deletes this client.
196
+ def delete
197
+ super "/clients/#{client_id}.json", {}
198
+ end
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
+
206
+ private
207
+
208
+ def get(action, options = {})
209
+ super uri_for(action), options
210
+ end
211
+
212
+ def post(action, options = {})
213
+ super uri_for(action), options
214
+ end
215
+
216
+ def put(action, options = {})
217
+ super uri_for(action), options
218
+ end
219
+
220
+ def uri_for(action)
221
+ "/clients/#{client_id}/#{action}.json"
222
+ end
223
+ end
224
+ end