mailerlite-ruby 1.0.2
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 +7 -0
- data/.env.example +1 -0
- data/.github/workflows/main.yml +17 -0
- data/.github/workflows/publish_gem.yml +21 -0
- data/.gitignore +60 -0
- data/.rspec +1 -0
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +801 -0
- data/Rakefile +8 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/fixtures/automations/fetch.yml +61 -0
- data/fixtures/automations/get.yml +68 -0
- data/fixtures/automations/get_subscriber_activity.yml +71 -0
- data/fixtures/batch/request.yml +59 -0
- data/fixtures/campaigns/activity.yml +64 -0
- data/fixtures/campaigns/create.yml +65 -0
- data/fixtures/campaigns/delete.yml +53 -0
- data/fixtures/campaigns/fetch.yml +64 -0
- data/fixtures/campaigns/get.yml +68 -0
- data/fixtures/campaigns/languages.yml +60 -0
- data/fixtures/campaigns/schedule.yml +160 -0
- data/fixtures/campaigns/update.yml +159 -0
- data/fixtures/fields/create.yml +57 -0
- data/fixtures/fields/delete.yml +53 -0
- data/fixtures/fields/get.yml +60 -0
- data/fixtures/fields/update.yml +57 -0
- data/fixtures/forms/delete.yml +53 -0
- data/fixtures/forms/fetch.yml +60 -0
- data/fixtures/forms/fetch_subscribers.yml +59 -0
- data/fixtures/forms/list.yml +62 -0
- data/fixtures/forms/update.yml +60 -0
- data/fixtures/groups/assign_subscriber.yml +58 -0
- data/fixtures/groups/create.yml +58 -0
- data/fixtures/groups/delete.yml +53 -0
- data/fixtures/groups/get.yml +63 -0
- data/fixtures/groups/get_subscribers.yml +62 -0
- data/fixtures/groups/unassign_subscriber.yml +53 -0
- data/fixtures/groups/update.yml +58 -0
- data/fixtures/segments/delete.yml +53 -0
- data/fixtures/segments/get_subscribers.yml +61 -0
- data/fixtures/segments/list.yml +60 -0
- data/fixtures/segments/update.yml +58 -0
- data/fixtures/subscribers/create.yml +57 -0
- data/fixtures/subscribers/delete.yml +51 -0
- data/fixtures/subscribers/fetch.yml +68 -0
- data/fixtures/subscribers/fetch_count.yml +55 -0
- data/fixtures/subscribers/get.yml +62 -0
- data/fixtures/timezones/list.yml +575 -0
- data/fixtures/webhooks/create.yml +58 -0
- data/fixtures/webhooks/delete.yml +53 -0
- data/fixtures/webhooks/get.yml +58 -0
- data/fixtures/webhooks/list.yml +61 -0
- data/fixtures/webhooks/update.yml +58 -0
- data/lib/mailerlite/automations/automations.rb +62 -0
- data/lib/mailerlite/batch/batch.rb +24 -0
- data/lib/mailerlite/campaigns/campaigns.rb +216 -0
- data/lib/mailerlite/client.rb +35 -0
- data/lib/mailerlite/fields/fields.rb +61 -0
- data/lib/mailerlite/forms/forms.rb +73 -0
- data/lib/mailerlite/groups/groups.rb +90 -0
- data/lib/mailerlite/segments/segments.rb +62 -0
- data/lib/mailerlite/subscribers/subscribers.rb +116 -0
- data/lib/mailerlite/timezones/timezones.rb +22 -0
- data/lib/mailerlite/version.rb +5 -0
- data/lib/mailerlite/webhooks/webhooks.rb +67 -0
- data/lib/mailerlite-ruby.rb +3 -0
- data/lib/mailerlite.rb +13 -0
- data/mailerlite-ruby.gemspec +42 -0
- data/renovate.json +5 -0
- data/spec/automations_rspec.rb +63 -0
- data/spec/batches_rspec.rb +41 -0
- data/spec/campaigns_rspec.rb +155 -0
- data/spec/fields_rspec.rb +70 -0
- data/spec/forms_rspec.rb +81 -0
- data/spec/groups_rspec.rb +97 -0
- data/spec/segments_rspec.rb +70 -0
- data/spec/spec_helper.rb +101 -0
- data/spec/subscribers_rspec.rb +84 -0
- data/spec/timezones_rspec.rb +36 -0
- data/spec/webhooks_rspec.rb +86 -0
- metadata +303 -0
data/README.md
ADDED
@@ -0,0 +1,801 @@
|
|
1
|
+
<a href="https://www.mailerlite.com"><img src="https://app.mailerlite.com/assets/images/logo-color.png" width="200px"/></a>
|
2
|
+
|
3
|
+
# MailerLite Ruby SDK
|
4
|
+
|
5
|
+
[](./LICENSE)
|
6
|
+
|
7
|
+
## Getting started
|
8
|
+
|
9
|
+
For more information about MailerLite API, please visit the [following link:](https://developers.mailerlite.com/docs/#mailerlite-api)
|
10
|
+
|
11
|
+
### Authentication
|
12
|
+
|
13
|
+
API keys are a quick way to implement machine-to-machine authentication without any direct inputs from a human beyond initial setup.
|
14
|
+
|
15
|
+
For more information how to obtain an API key visit the [following link](https://developers.mailerlite.com/docs/#mailerlite-api)
|
16
|
+
|
17
|
+
## Table of Contents
|
18
|
+
|
19
|
+
- [MailerLite Ruby SDK](#mailerlite-ruby-sdk)
|
20
|
+
- [Getting started](#getting-started)
|
21
|
+
- [Authentication](#authentication)
|
22
|
+
- [Table of Contents](#table-of-contents)
|
23
|
+
- [Installation](#installation)
|
24
|
+
- [Usage](#usage)
|
25
|
+
- [MailerLite Client](#mailerlite-client)
|
26
|
+
- [Subscribers](#subscribers)
|
27
|
+
- [List all subscribers](#list-all-subscribers)
|
28
|
+
- [Create a subscriber](#create-a-subscriber)
|
29
|
+
- [Update a subscriber](#update-a-subscriber)
|
30
|
+
- [Get a subscriber](#get-a-subscriber)
|
31
|
+
- [Delete a subscriber](#delete-a-subscriber)
|
32
|
+
- [Groups](#groups)
|
33
|
+
- [List all groups](#list-all-groups)
|
34
|
+
- [Create a group](#create-a-group)
|
35
|
+
- [Update a group](#update-a-group)
|
36
|
+
- [Delete a group](#delete-a-group)
|
37
|
+
- [Get subscribers belonging to a group](#get-subscribers-belonging-to-a-group)
|
38
|
+
- [Assign subscriber to a group](#assign-subscriber-to-a-group)
|
39
|
+
- [Unassign subscriber from a group](#unassign-subscriber-from-a-group)
|
40
|
+
- [Segments](#segments)
|
41
|
+
- [List all segments](#list-all-segments)
|
42
|
+
- [Update a segment](#update-a-segment)
|
43
|
+
- [Delete a segment](#delete-a-segment)
|
44
|
+
- [Get subscribers belonging to a segment](#get-subscribers-belonging-to-a-segment)
|
45
|
+
- [Fields](#fields)
|
46
|
+
- [List all fields](#list-all-fields)
|
47
|
+
- [Create a field](#create-a-field)
|
48
|
+
- [Update a field](#update-a-field)
|
49
|
+
- [Delete a field](#delete-a-field)
|
50
|
+
- [Automations](#automations)
|
51
|
+
- [List all automations](#list-all-automations)
|
52
|
+
- [Get an automation](#get-an-automation)
|
53
|
+
- [Get subscribers activity for an automation](#get-subscribers-activity-for-an-automation)
|
54
|
+
- [Campaigns](#campaigns)
|
55
|
+
- [List all campaigns](#list-all-campaigns)
|
56
|
+
- [Get a campaign](#get-a-campaign)
|
57
|
+
- [Create a campaign](#create-a-campaign)
|
58
|
+
- [Update a campaign](#update-a-campaign)
|
59
|
+
- [Schedule a campaign](#schedule-a-campaign)
|
60
|
+
- [Cancel a campaign](#cancel-a-campaign)
|
61
|
+
- [Delete a campaign](#delete-a-campaign)
|
62
|
+
- [Get subscribers activity for a campaign](#get-subscribers-activity-for-a-campaign)
|
63
|
+
- [Forms](#forms)
|
64
|
+
- [List all forms](#list-all-forms)
|
65
|
+
- [Get a form](#get-a-form)
|
66
|
+
- [Update a form](#update-a-form)
|
67
|
+
- [Delete a form](#delete-a-form)
|
68
|
+
- [Get subscribers who signed up to a specific form](#get-subscribers-who-signed-up-to-a-specific-form)
|
69
|
+
- [Batching](#batching)
|
70
|
+
- [Create a new batch](#create-a-new-batch)
|
71
|
+
- [Webhooks](#webhooks)
|
72
|
+
- [List all webhooks](#list-all-webhooks)
|
73
|
+
- [Get a webhook](#get-a-webhook)
|
74
|
+
- [Create a webhook](#create-a-webhook)
|
75
|
+
- [Update a webhook](#update-a-webhook)
|
76
|
+
- [Delete a webhook](#delete-a-webhook)
|
77
|
+
- [Timezones](#timezones)
|
78
|
+
- [Get a list of timezones](#get-a-list-of-timezones)
|
79
|
+
- [Campaign languages](#campaign-languages)
|
80
|
+
- [Get a list of languages](#get-a-list-of-languages)
|
81
|
+
|
82
|
+
## Setup
|
83
|
+
|
84
|
+
```bash
|
85
|
+
gem install mailerlite-ruby
|
86
|
+
```
|
87
|
+
|
88
|
+
You will have to initalize it in your Ruby file with `require "mailerlite-ruby"`.
|
89
|
+
|
90
|
+
# Usage
|
91
|
+
|
92
|
+
This SDK requires that you either have `.env` file with `MAILERLITE_API_TOKEN` env variable or that your variable is enabled system wide (useful for Docker/Kubernetes). The example of how `MAILERLITE_API_TOKEN` should look like is in `.env.example`.
|
93
|
+
|
94
|
+
## Subscribers
|
95
|
+
|
96
|
+
<a name="subscribers"></a>
|
97
|
+
|
98
|
+
### List all subscribers
|
99
|
+
|
100
|
+
<a name="get-a-list-of-subscribers"></a>
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
require "mailerlite-ruby"
|
104
|
+
|
105
|
+
# Intialize the class
|
106
|
+
subscribers = Mailerlite::Subscribers.new
|
107
|
+
|
108
|
+
response = subscribers.list(filter: { status: 'active' })
|
109
|
+
```
|
110
|
+
|
111
|
+
### Create a subscriber
|
112
|
+
|
113
|
+
<a name="create-a-subscriber"></a>
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
require "mailerlite-ruby"
|
117
|
+
|
118
|
+
# Intialize the class
|
119
|
+
subscribers = Mailerlite::Subscribers.new
|
120
|
+
|
121
|
+
response = subscribers.create(email:'some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')
|
122
|
+
```
|
123
|
+
|
124
|
+
### Update a subscriber
|
125
|
+
|
126
|
+
<a name="update-a-subscriber"></a>
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
require "mailerlite-ruby"
|
130
|
+
|
131
|
+
# Intialize the class
|
132
|
+
subscribers = Mailerlite::Subscribers.new
|
133
|
+
|
134
|
+
response = subscribers.update(email:'some@email.com', fields: {'name': 'John', 'last_name': 'Doe'}, ip_address:'1.2.3.4', optin_ip:'1.2.3.4')
|
135
|
+
```
|
136
|
+
|
137
|
+
### Get a subscriber
|
138
|
+
|
139
|
+
<a name="get-a-subscriber"></a>
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
require "mailerlite-ruby"
|
143
|
+
|
144
|
+
# Intialize the class
|
145
|
+
subscribers = Mailerlite::Subscribers.new
|
146
|
+
|
147
|
+
response = subscribers.get('some@email.com')
|
148
|
+
```
|
149
|
+
|
150
|
+
### Delete a subscriber
|
151
|
+
|
152
|
+
<a name="delete-a-subscriber"></a>
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
require "mailerlite-ruby"
|
156
|
+
|
157
|
+
# Intialize the class
|
158
|
+
subscribers = Mailerlite::Subscribers.new
|
159
|
+
|
160
|
+
subscriber_id = 1234567890
|
161
|
+
|
162
|
+
response = subscribers.delete(subscriber_id)
|
163
|
+
```
|
164
|
+
|
165
|
+
## Groups
|
166
|
+
|
167
|
+
<a name="groups"></a>
|
168
|
+
|
169
|
+
### List all groups
|
170
|
+
|
171
|
+
<a name="list-all-groups"></a>
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
require "mailerlite-ruby"
|
175
|
+
|
176
|
+
# Intialize the class
|
177
|
+
groups = Mailerlite::Groups.new
|
178
|
+
|
179
|
+
response = groups.list(limit:10, page:1, filter:{'name': 'My'}, sort:'name')
|
180
|
+
```
|
181
|
+
|
182
|
+
### Create a group
|
183
|
+
|
184
|
+
<a name="create-a-group"></a>
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
require "mailerlite-ruby"
|
188
|
+
|
189
|
+
# Intialize the class
|
190
|
+
groups = Mailerlite::Groups.new
|
191
|
+
|
192
|
+
response = groups.create(name:'Group Name')
|
193
|
+
```
|
194
|
+
|
195
|
+
### Update a group
|
196
|
+
|
197
|
+
<a name="update-a-group"></a>
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
require "mailerlite-ruby"
|
201
|
+
|
202
|
+
# Intialize the class
|
203
|
+
groups = Mailerlite::Groups.new
|
204
|
+
|
205
|
+
response = groups.update(group_id:1234567, name:'My New Group')
|
206
|
+
```
|
207
|
+
|
208
|
+
### Delete a group
|
209
|
+
|
210
|
+
<a name="delete-a-group"></a>
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
require "mailerlite-ruby"
|
214
|
+
|
215
|
+
# Intialize the class
|
216
|
+
groups = Mailerlite::Groups.new
|
217
|
+
|
218
|
+
group_id = 1234567
|
219
|
+
|
220
|
+
response = groups.delete(group_id)
|
221
|
+
```
|
222
|
+
|
223
|
+
### Get subscribers belonging to a group
|
224
|
+
|
225
|
+
<a name="get-subscribers-belonging-to-a-group"></a>
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
require "mailerlite-ruby"
|
229
|
+
|
230
|
+
# Intialize the class
|
231
|
+
groups = Mailerlite::Groups.new
|
232
|
+
|
233
|
+
response = groups.get_subscribers(group_id:1234567, page:1, limit:10, filter:{'status': 'active'})
|
234
|
+
```
|
235
|
+
|
236
|
+
### Assign subscriber to a group
|
237
|
+
|
238
|
+
<a name="assign-subscribers-to-a-group"></a>
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
require "mailerlite-ruby"
|
242
|
+
|
243
|
+
# Intialize the class
|
244
|
+
groups = Mailerlite::Groups.new
|
245
|
+
|
246
|
+
response = subscribers.assign_subscriber(subscriber_id:111222, group_id:1234567)
|
247
|
+
```
|
248
|
+
|
249
|
+
### Unassign subscriber from a group
|
250
|
+
|
251
|
+
<a name="unassign-subscribers-from-a-group"></a>
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
require "mailerlite-ruby"
|
255
|
+
|
256
|
+
# Intialize the class
|
257
|
+
groups = Mailerlite::Groups.new
|
258
|
+
|
259
|
+
response = subscribers.unassign_subscriber(subscriber_id:111222, group_id:1234567)
|
260
|
+
```
|
261
|
+
|
262
|
+
## Segments
|
263
|
+
|
264
|
+
<a name="segments"></a>
|
265
|
+
|
266
|
+
### List all segments
|
267
|
+
|
268
|
+
<a name="list-all-segments"></a>
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
require "mailerlite-ruby"
|
272
|
+
|
273
|
+
# Intialize the class
|
274
|
+
segments = Mailerlite::Segments.new
|
275
|
+
|
276
|
+
response = segments.list(limit:10, page:1)
|
277
|
+
```
|
278
|
+
|
279
|
+
### Update a segment
|
280
|
+
|
281
|
+
<a name="update-a-segment"></a>
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
require "mailerlite-ruby"
|
285
|
+
|
286
|
+
# Intialize the class
|
287
|
+
segments = Mailerlite::Segments.new
|
288
|
+
|
289
|
+
response = segments.update(segment_id: 123456, name:'My New Segment Name')
|
290
|
+
```
|
291
|
+
|
292
|
+
### Delete a segment
|
293
|
+
|
294
|
+
<a name="delete-a-segment"></a>
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
require "mailerlite-ruby"
|
298
|
+
|
299
|
+
# Intialize the class
|
300
|
+
segments = Mailerlite::Segments.new
|
301
|
+
segment_id = 123456
|
302
|
+
|
303
|
+
response = segments.delete(segment_id)
|
304
|
+
```
|
305
|
+
|
306
|
+
### Get subscribers belonging to a segment
|
307
|
+
|
308
|
+
<a name="get-subscribers-belonging-to-a-segment"></a>
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
require "mailerlite-ruby"
|
312
|
+
|
313
|
+
# Intialize the class
|
314
|
+
segments = Mailerlite::Segments.new
|
315
|
+
|
316
|
+
response = segments.get_subscribers(segment_id:123456, limit:10, filter:{'status': 'active'})
|
317
|
+
```
|
318
|
+
|
319
|
+
## Fields
|
320
|
+
|
321
|
+
<a name="fields"></a>
|
322
|
+
|
323
|
+
### List all fields
|
324
|
+
|
325
|
+
<a name="list-all-fields"></a>
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
require "mailerlite-ruby"
|
329
|
+
|
330
|
+
# Intialize the class
|
331
|
+
fields = Mailerlite::Fields.new
|
332
|
+
|
333
|
+
response = fields.list(limit:10, page:1, sort:'name', filter:{'keyword': 'abc', 'type': 'text'})
|
334
|
+
```
|
335
|
+
|
336
|
+
### Create a field
|
337
|
+
|
338
|
+
<a name="create-a-field"></a>
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
require "mailerlite-ruby"
|
342
|
+
|
343
|
+
# Intialize the class
|
344
|
+
fields = Mailerlite::Fields.new
|
345
|
+
|
346
|
+
response = fields.create(name:'My Field', type:'text')
|
347
|
+
```
|
348
|
+
|
349
|
+
### Update a field
|
350
|
+
|
351
|
+
<a name="update-a-field"></a>
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
require "mailerlite-ruby"
|
355
|
+
|
356
|
+
# Intialize the class
|
357
|
+
fields = Mailerlite::Fields.new
|
358
|
+
|
359
|
+
response = fields.update(field_id:123345, name:'My New Field')
|
360
|
+
```
|
361
|
+
|
362
|
+
### Delete a field
|
363
|
+
|
364
|
+
<a name="delete-a-field"></a>
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
require "mailerlite-ruby"
|
368
|
+
|
369
|
+
# Intialize the class
|
370
|
+
fields = Mailerlite::Fields.new
|
371
|
+
|
372
|
+
field_id = 123456
|
373
|
+
|
374
|
+
response = fields.delete(field_id)
|
375
|
+
```
|
376
|
+
|
377
|
+
## Automations
|
378
|
+
|
379
|
+
<a name="automations"></a>
|
380
|
+
|
381
|
+
### List all automations
|
382
|
+
|
383
|
+
<a name="list-all-automations"></a>
|
384
|
+
|
385
|
+
```ruby
|
386
|
+
require "mailerlite-ruby"
|
387
|
+
|
388
|
+
# Intialize the class
|
389
|
+
automations = Mailerlite::Automations.new
|
390
|
+
|
391
|
+
response = automations.list(limit:10, page:1, filter:{'status': true, 'name': 'some name', 'group': 123456})
|
392
|
+
```
|
393
|
+
|
394
|
+
### Get an automation
|
395
|
+
|
396
|
+
<a name="get-an-automation"></a>
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
require "mailerlite-ruby"
|
400
|
+
|
401
|
+
# Intialize the class
|
402
|
+
automations = Mailerlite::Automations.new
|
403
|
+
|
404
|
+
automation_id = 123456
|
405
|
+
|
406
|
+
response = automations.get(automation_id)
|
407
|
+
```
|
408
|
+
|
409
|
+
### Get subscribers activity for an automation
|
410
|
+
|
411
|
+
<a name="get-subscribers-activity-for-an-automation"></a>
|
412
|
+
|
413
|
+
```ruby
|
414
|
+
require "mailerlite-ruby"
|
415
|
+
|
416
|
+
# Intialize the class
|
417
|
+
automations = Mailerlite::Automations.new
|
418
|
+
|
419
|
+
response = automations.activity(automation_id:123456, page:1, limit:10, filter:{'status': 'active', 'date_from': '2022-12-20', 'date_to': '2022-12-31'})
|
420
|
+
```
|
421
|
+
|
422
|
+
## Campaigns
|
423
|
+
|
424
|
+
<a name="campaigns"></a>
|
425
|
+
|
426
|
+
### List all campaigns
|
427
|
+
|
428
|
+
<a name="list-all-campaigns"></a>
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
require "mailerlite-ruby"
|
432
|
+
|
433
|
+
# Intialize the class
|
434
|
+
campaigns = Mailerlite::Campaigns.new
|
435
|
+
|
436
|
+
response = campaigns.list(limit:10, page:1, filter:{'status': 'ready', 'type': 'regular'})
|
437
|
+
```
|
438
|
+
|
439
|
+
### Get a campaign
|
440
|
+
|
441
|
+
<a name="get-a-campaign"></a>
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
require "mailerlite-ruby"
|
445
|
+
|
446
|
+
# Intialize the class
|
447
|
+
campaigns = Mailerlite::Campaigns.new
|
448
|
+
|
449
|
+
response = campaigns.get(campaign_id:123456)
|
450
|
+
```
|
451
|
+
|
452
|
+
### Create a campaign
|
453
|
+
|
454
|
+
<a name="create-a-campaign"></a>
|
455
|
+
|
456
|
+
```ruby
|
457
|
+
require "mailerlite-ruby"
|
458
|
+
|
459
|
+
# Intialize the class
|
460
|
+
campaigns = Mailerlite::Campaigns.new
|
461
|
+
|
462
|
+
response = campaigns.create(
|
463
|
+
name: "Test Campaign",
|
464
|
+
language_id: 1,
|
465
|
+
type: "regular",
|
466
|
+
emails: [{
|
467
|
+
"subject": "This is a test campaign",
|
468
|
+
"from_name": "Test Man",
|
469
|
+
"from": "testuser@mailerlite.com",
|
470
|
+
"content": "Hi there, this is a test campaign!"
|
471
|
+
}]
|
472
|
+
)
|
473
|
+
```
|
474
|
+
|
475
|
+
### Update a campaign
|
476
|
+
|
477
|
+
<a name="update-a-campaign"></a>
|
478
|
+
|
479
|
+
```ruby
|
480
|
+
require "mailerlite-ruby"
|
481
|
+
|
482
|
+
# Intialize the class
|
483
|
+
campaigns = Mailerlite::Campaigns.new
|
484
|
+
|
485
|
+
response = campaigns.update(
|
486
|
+
campaign_id: 1233455,
|
487
|
+
name: "New Campaign Name",
|
488
|
+
language_id: 2,
|
489
|
+
emails: [{
|
490
|
+
"subject": "This is a test campaign",
|
491
|
+
"from_name": "Test Man",
|
492
|
+
"from": "testuser@mailerlite.com",
|
493
|
+
"content": "Hi there, this is a test campaign!"
|
494
|
+
}]
|
495
|
+
)
|
496
|
+
```
|
497
|
+
|
498
|
+
### Schedule a campaign
|
499
|
+
|
500
|
+
<a name="schedule-a-campaign"></a>
|
501
|
+
|
502
|
+
```ruby
|
503
|
+
require "mailerlite-ruby"
|
504
|
+
|
505
|
+
# Intialize the class
|
506
|
+
campaigns = Mailerlite::Campaigns.new
|
507
|
+
|
508
|
+
response = campaigns.schedule(
|
509
|
+
campaign_id: 123456,
|
510
|
+
delivery: "scheduled",
|
511
|
+
schedule: {
|
512
|
+
"date": "2022-12-31",
|
513
|
+
"hours": "22",
|
514
|
+
"minutes": "00"
|
515
|
+
}
|
516
|
+
)
|
517
|
+
```
|
518
|
+
|
519
|
+
### Cancel a campaign
|
520
|
+
|
521
|
+
<a name="cancel-a-campaign"></a>
|
522
|
+
|
523
|
+
```ruby
|
524
|
+
require "mailerlite-ruby"
|
525
|
+
|
526
|
+
# Intialize the class
|
527
|
+
campaigns = Mailerlite::Campaigns.new
|
528
|
+
|
529
|
+
campaign_id = 123456
|
530
|
+
|
531
|
+
response = campaigns.cancel(campaign_id)
|
532
|
+
```
|
533
|
+
|
534
|
+
### Delete a campaign
|
535
|
+
|
536
|
+
<a name="cancel-a-campaign"></a>
|
537
|
+
|
538
|
+
```ruby
|
539
|
+
require "mailerlite-ruby"
|
540
|
+
|
541
|
+
# Intialize the class
|
542
|
+
campaigns = Mailerlite::Campaigns.new
|
543
|
+
|
544
|
+
campaign_id = 123456
|
545
|
+
|
546
|
+
response = campaigns.delete(campaign_id)
|
547
|
+
```
|
548
|
+
|
549
|
+
### Get subscribers activity for a campaign
|
550
|
+
|
551
|
+
<a name="get-subscribers-activity-for-an-campaign"></a>
|
552
|
+
|
553
|
+
```ruby
|
554
|
+
require "mailerlite-ruby"
|
555
|
+
|
556
|
+
# Intialize the class
|
557
|
+
campaigns = Mailerlite::Campaigns.new
|
558
|
+
|
559
|
+
campaign_id = 123456
|
560
|
+
|
561
|
+
response = campaigns.activity(campaign_id)
|
562
|
+
```
|
563
|
+
|
564
|
+
## Forms
|
565
|
+
|
566
|
+
<a name="forms"></a>
|
567
|
+
|
568
|
+
### List all forms
|
569
|
+
|
570
|
+
<a name="list-all-forms"></a>
|
571
|
+
|
572
|
+
```ruby
|
573
|
+
require "mailerlite-ruby"
|
574
|
+
|
575
|
+
# Intialize the class
|
576
|
+
forms = Mailerlite::Forms.new
|
577
|
+
|
578
|
+
response = forms.list(limit:10, page:1, sort:'name', filter:{'name': 'form name'})
|
579
|
+
```
|
580
|
+
|
581
|
+
### Get a form
|
582
|
+
|
583
|
+
<a name="get-a-form"></a>
|
584
|
+
|
585
|
+
```ruby
|
586
|
+
require "mailerlite-ruby"
|
587
|
+
|
588
|
+
# Intialize the class
|
589
|
+
forms = Mailerlite::Forms.new
|
590
|
+
|
591
|
+
form_id = 123456
|
592
|
+
|
593
|
+
response = forms.get(form_id)
|
594
|
+
```
|
595
|
+
|
596
|
+
### Update a form
|
597
|
+
|
598
|
+
<a name="update-a-form"></a>
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
require "mailerlite-ruby"
|
602
|
+
|
603
|
+
# Intialize the class
|
604
|
+
forms = Mailerlite::Forms.new
|
605
|
+
|
606
|
+
response = forms.update(form_id:123456, name: 'My form Name')
|
607
|
+
```
|
608
|
+
|
609
|
+
### Delete a form
|
610
|
+
|
611
|
+
<a name="cancel-a-form"></a>
|
612
|
+
|
613
|
+
```ruby
|
614
|
+
require "mailerlite-ruby"
|
615
|
+
|
616
|
+
# Intialize the class
|
617
|
+
forms = Mailerlite::Forms.new
|
618
|
+
|
619
|
+
form_id = 123456
|
620
|
+
|
621
|
+
response = forms.delete(form_id)
|
622
|
+
```
|
623
|
+
|
624
|
+
### Get subscribers who signed up to a specific form
|
625
|
+
|
626
|
+
<a name="get-subscribers-who-signed-up-to-a-specific-form"></a>
|
627
|
+
|
628
|
+
```ruby
|
629
|
+
require "mailerlite-ruby"
|
630
|
+
|
631
|
+
# Intialize the class
|
632
|
+
forms = Mailerlite::Forms.new
|
633
|
+
|
634
|
+
response = forms.get_subscribers(form_id:123345, page:1, limit:10, filter:{'status': 'active'})
|
635
|
+
```
|
636
|
+
|
637
|
+
## Batching
|
638
|
+
|
639
|
+
<a name="batching"></a>
|
640
|
+
|
641
|
+
### Create a new batch
|
642
|
+
|
643
|
+
<a name="create-a-new-batch"></a>
|
644
|
+
|
645
|
+
```ruby
|
646
|
+
require "mailerlite-ruby"
|
647
|
+
|
648
|
+
# Intialize the class
|
649
|
+
batch = Mailerlite::Batch.new
|
650
|
+
|
651
|
+
response = batch.request(
|
652
|
+
requests: [
|
653
|
+
{ method: 'GET', path: 'api/subscribers/list' },
|
654
|
+
{ method: 'GET', path: 'api/campaigns/list' }
|
655
|
+
]
|
656
|
+
)
|
657
|
+
```
|
658
|
+
|
659
|
+
## Webhooks
|
660
|
+
|
661
|
+
<a name="webhooks"></a>
|
662
|
+
|
663
|
+
### List all webhooks
|
664
|
+
|
665
|
+
<a name="list-all-webhooks"></a>
|
666
|
+
|
667
|
+
```ruby
|
668
|
+
require "mailerlite-ruby"
|
669
|
+
|
670
|
+
# Intialize the class
|
671
|
+
subscribers = Mailerlite::Subscribers.new
|
672
|
+
|
673
|
+
response = webhooks.list()
|
674
|
+
```
|
675
|
+
|
676
|
+
### Get a webhook
|
677
|
+
|
678
|
+
<a name="get-a-webhook"></a>
|
679
|
+
|
680
|
+
```ruby
|
681
|
+
require "mailerlite-ruby"
|
682
|
+
|
683
|
+
# Intialize the class
|
684
|
+
subscribers = Mailerlite::Subscribers.new
|
685
|
+
|
686
|
+
webhook_id = 123456
|
687
|
+
|
688
|
+
response = webhooks.get(webhook_id)
|
689
|
+
```
|
690
|
+
|
691
|
+
### Create a webhook
|
692
|
+
|
693
|
+
<a name="create-a-webhook"></a>
|
694
|
+
|
695
|
+
```ruby
|
696
|
+
require "mailerlite-ruby"
|
697
|
+
|
698
|
+
# Intialize the class
|
699
|
+
webhooks = Mailerlite::Webhooks.new
|
700
|
+
|
701
|
+
response = webhooks.create(
|
702
|
+
events:[
|
703
|
+
'subscriber.created',
|
704
|
+
'subscriber.updated',
|
705
|
+
'subscriber.unsubscribed'
|
706
|
+
],
|
707
|
+
url:'https://my-url.com',
|
708
|
+
name: 'Webhook name'
|
709
|
+
)
|
710
|
+
```
|
711
|
+
|
712
|
+
### Update a webhook
|
713
|
+
|
714
|
+
<a name="update-a-webhook"></a>
|
715
|
+
|
716
|
+
```ruby
|
717
|
+
require "mailerlite-ruby"
|
718
|
+
|
719
|
+
# Intialize the class
|
720
|
+
webhooks = Mailerlite::Webhooks.new
|
721
|
+
|
722
|
+
response = webhooks.update(
|
723
|
+
webhook_id: 123456,
|
724
|
+
events:[
|
725
|
+
'subscriber.created',
|
726
|
+
'subscriber.updated',
|
727
|
+
'subscriber.unsubscribed'
|
728
|
+
],
|
729
|
+
url:'https://my-url.com',
|
730
|
+
name: 'Webhook name',
|
731
|
+
enabled: false
|
732
|
+
)
|
733
|
+
```
|
734
|
+
|
735
|
+
### Delete a webhook
|
736
|
+
|
737
|
+
<a name="cancel-a-webhook"></a>
|
738
|
+
|
739
|
+
```ruby
|
740
|
+
require "mailerlite-ruby"
|
741
|
+
|
742
|
+
# Intialize the class
|
743
|
+
webhooks = Mailerlite::Webhooks.new
|
744
|
+
|
745
|
+
webhook_id = 123456
|
746
|
+
|
747
|
+
response = webhooks.delete(webhook_id)
|
748
|
+
```
|
749
|
+
|
750
|
+
## Timezones
|
751
|
+
|
752
|
+
<a name="timezones"></a>
|
753
|
+
|
754
|
+
### Get a list of timezones
|
755
|
+
|
756
|
+
<a name="get-a-list-of-timezones"></a>
|
757
|
+
|
758
|
+
```ruby
|
759
|
+
require "mailerlite-ruby"
|
760
|
+
|
761
|
+
# Intialize the class
|
762
|
+
timezones = Mailerlite::Timezones.new
|
763
|
+
|
764
|
+
response = timezones.list()
|
765
|
+
```
|
766
|
+
|
767
|
+
## Campaign languages
|
768
|
+
|
769
|
+
<a name="languages"></a>
|
770
|
+
|
771
|
+
### Get a list of languages
|
772
|
+
|
773
|
+
<a name="get-a-list-of-languages"></a>
|
774
|
+
|
775
|
+
```ruby
|
776
|
+
require "mailerlite-ruby"
|
777
|
+
|
778
|
+
# Intialize the class
|
779
|
+
campaigns = Mailerlite::Campaigns.new
|
780
|
+
|
781
|
+
response = campaigns.languages()
|
782
|
+
```
|
783
|
+
|
784
|
+
# Testing
|
785
|
+
|
786
|
+
```bash
|
787
|
+
bundle i
|
788
|
+
bundle exec rspec spec/*rspec.rb
|
789
|
+
```
|
790
|
+
|
791
|
+
To run tests you would need to install gems using bundle and then run rspec via bundle to run all tests.
|
792
|
+
The fixtures for the test have been recorded using vcr and are available in the ./fixtures directory
|
793
|
+
|
794
|
+
# Generate Docs
|
795
|
+
|
796
|
+
```bash
|
797
|
+
bundle i
|
798
|
+
bundle exec yardoc 'lib/**/*.rb'
|
799
|
+
```
|
800
|
+
|
801
|
+
This will generate html docs in the doc directory which can be opened up in any browser. Navigate to index.html and open it up.
|