mailersend-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fb6199cff0a78e0716fd71e505603272ec11f5be3e1807932068fd0347ffe8c6
4
+ data.tar.gz: 60f799a1d817d792e2c0f90d94ed5e4c5b0cf1d27df00d91b5923d31574adfad
5
+ SHA512:
6
+ metadata.gz: 2b3154b1ef480050c9509602e0f0192b0b55fe97af546d80f774d504fd4b28271df747f30e99121fcc4c94e2e16951d09692ef7f8559754c079d948a6bef21cf
7
+ data.tar.gz: fed0dbf67eaf84f36c77918a245dadfa52e6a2aedee915e5ba0a9803f4b7d81b625ae90798ef079aac3cc6c77227aa6cb66441693a46c6b10bb8127720556237
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ API_TOKEN="Bearer superlongkey"
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
10
+ .idea
11
+ Gemfile.lock
12
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ SuggestExtensions: false
4
+ NewCops: enable
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Enabled: false
16
+
17
+ Metrics/ParameterLists:
18
+ Enabled: false
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+
25
+ Naming/FileName:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Released]
2
+
3
+ ## [0.1.0] - 2021-06-14
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Nikola Milojević
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,427 @@
1
+ <a href="https://www.mailersend.com"><img src="https://www.mailersend.com/images/logo.svg" width="200px"/></a>
2
+
3
+ MailerSend Ruby SDK
4
+
5
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
6
+
7
+ - [Installation](#installation)
8
+ - [Setup](#setup)
9
+ - [Usage](#usage)
10
+ - [Email](#email)
11
+ - [Send an email](#send-an-email)
12
+ - [Send and email with CC and BCC](#send-and-email-with-cc-and-bcc)
13
+ - [Send a templated email](#send-a-templated-email)
14
+ - [Advanced personalization](#advanced-personalization)
15
+ - [Simple personalization](#simple-personalization)
16
+ - [Send email with attachment](#send-email-with-attachment)
17
+ - [Activity](#activity)
18
+ - [Get a list of activities](#get-a-list-of-activities)
19
+ - [Analytics](#analytics)
20
+ - [Activity data by date](#activity-data-by-date)
21
+ - [Opens by country](#opens-by-country)
22
+ - [Opens by user-agent name](#opens-by-user-agent-name)
23
+ - [Opens by reading environment](#opens-by-reading-environment)
24
+ - [Domains](#domains)
25
+ - [Get a list of domains](#get-a-list-of-domains)
26
+ - [Get a single domain](#get-a-single-domain)
27
+ - [Delete a domain](#delete-a-domain)
28
+ - [Update domain settings](#update-domain-settings)
29
+ - [Messages](#messages)
30
+ - [Get a list of messages](#get-a-list-of-messages)
31
+ - [Get info for a single message](#get-info-for-a-single-message)
32
+ - [Recipients](#recipients)
33
+ - [Get recipients](#get-recipients)
34
+ - [Get a single recipient](#get-a-single-recipient)
35
+ - [Delete a recipient](#delete-a-recipient)
36
+ - [Tokens](#tokens)
37
+ - [Create a token](#create-a-token)
38
+ - [Update a token](#update-a-token)
39
+ - [Delete a token](#delete-a-token)
40
+ - [Webhooks](#webhooks)
41
+ - [List webhooks](#list-webhooks)
42
+ - [Get a webhook](#get-a-webhook)
43
+ - [Create a webhook](#create-a-webhook)
44
+ - [Update a webhook](#update-a-webhook)
45
+ - [Support and Feedback](#support-and-feedback)
46
+ - [License](#license)
47
+
48
+ # Installation
49
+
50
+ ## Setup
51
+
52
+ ```bash
53
+ gem install mailersend-ruby
54
+ ```
55
+
56
+ You will have to initalize it in your Ruby file with `require "mailersend-ruby"`.
57
+
58
+ # Usage
59
+
60
+ This SDK requires that you either have `.env` file with `API_TOKEN` env variable or that your variable is enabled system wide (useful for Docker/Kubernetes). The example of how `API_TOKEN` should look like is in `.env.example`.
61
+
62
+ ## Email
63
+
64
+ ### Send an email
65
+
66
+ ```ruby
67
+ require "mailersend-ruby"
68
+
69
+ # Intialize the email class
70
+ ms_email = Mailersend::Email.new
71
+
72
+ # Add parameters
73
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
74
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
75
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
76
+ ms_email.add_subject("Time")
77
+ ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
78
+ ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
79
+
80
+ # Send the email
81
+ ms_email.send
82
+ ```
83
+
84
+ ### Send and email with CC and BCC
85
+
86
+ ```ruby
87
+ require "mailersend-ruby"
88
+
89
+ # Intialize the email class
90
+ ms_email = Mailersend::Email.new
91
+
92
+ # Add parameters
93
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
94
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
95
+ ms_email.add_cc("email" => "chris@parksandrec.com", "name" => "Chris")
96
+ ms_email.add_bcc("email" => "andy@parksandrec.com", "name" => "Andy")
97
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
98
+ ms_email.add_subject("Time")
99
+ ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
100
+ ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
101
+
102
+ # Send the email
103
+ ms_email.send
104
+ ```
105
+
106
+ ### Send a templated email
107
+
108
+ ```ruby
109
+ require "mailersend-ruby"
110
+
111
+ # Intialize the email class
112
+ ms_email = Mailersend::Email.new
113
+
114
+ # Add parameters
115
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
116
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
117
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
118
+ ms_email.add_subject("Time")
119
+ ms_email.add_template_id(12415125)
120
+
121
+ # Send the email
122
+ ms_email.send
123
+ ```
124
+
125
+ ### Advanced personalization
126
+
127
+ ```ruby
128
+ require "mailersend-ruby"
129
+
130
+ # Intialize the email class
131
+ ms_email = Mailersend::Email.new
132
+
133
+ # Add parameters
134
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
135
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
136
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
137
+ ms_email.add_subject("Time")
138
+ ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
139
+ ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
140
+
141
+ personalization = {
142
+ "email": "test@test.com",
143
+ "data": {
144
+ "var": "value",
145
+ "boolean": true,
146
+ "object": {
147
+ "key": "object-value"
148
+ },
149
+ "number": 2,
150
+ "array": [
151
+ 1,
152
+ 2,
153
+ 3
154
+ ]
155
+ }
156
+ }
157
+
158
+ ms_email.add_personalization(personalization)
159
+
160
+ ms_email.send
161
+ ```
162
+
163
+ ### Simple personalization
164
+
165
+ ```ruby
166
+ require "mailersend-ruby"
167
+
168
+ # Intialize the email class
169
+ ms_email = Mailersend::Email.new
170
+
171
+ # Add parameters
172
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
173
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
174
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
175
+ ms_email.add_subject("Time")
176
+ ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
177
+ ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
178
+
179
+ variables = {
180
+ "email": "test@test.com",
181
+ "substitutions": [
182
+ {
183
+ "var": "test",
184
+ "value": "test"
185
+ }
186
+ ]
187
+ }
188
+
189
+ ms_email.add_variables(variables)
190
+
191
+ ms_email.send
192
+ ```
193
+
194
+ ### Send email with attachment
195
+
196
+ ```ruby
197
+ require "mailersend-ruby"
198
+
199
+ # Intialize the email class
200
+ ms_email = Mailersend::Email.new
201
+
202
+ # Add parameters
203
+ ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
204
+ ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
205
+ ms_email.add_cc("email" => "chris@parksandrec.com", "name" => "Chris")
206
+ ms_email.add_bcc("email" => "andy@parksandrec.com", "name" => "Andy")
207
+ ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
208
+ ms_email.add_subject("Time")
209
+ ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
210
+ ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
211
+
212
+ # You can add one or multiple attachments
213
+ ms.add_attachment(content: "/Users/Jerry/Desktop/doc.pdf", filename: "doc.pdf")
214
+ ms.add_attachment(content: "/Users/Jerry/Desktop/pic.png", filename: "pic.png")
215
+
216
+ ms_email.send
217
+ ```
218
+
219
+ ## Activity
220
+
221
+ ### Get a list of activities
222
+
223
+ ```ruby
224
+ require "mailersend-ruby"
225
+
226
+ ms_activity = Mailersend::Activity.new
227
+ ms_activity.get(domain_id: "xxx2241ll", page: 3, limit: 5, date_from: 1620643567, date_to: 1623321967)
228
+ ```
229
+
230
+ ## Analytics
231
+
232
+ ### Activity data by date
233
+
234
+ ```ruby
235
+ require "mailersend-ruby"
236
+
237
+ ms_analytics = Mailersend::Analytics.new
238
+ ms_analytics.date(date_from: 1620643567, date_to: 1623321967, events: %w[sent queued]))
239
+ ```
240
+
241
+ ### Opens by country
242
+
243
+ ```ruby
244
+ require "mailersend-ruby"
245
+
246
+ ms_analytics = Mailersend::Analytics.new
247
+ ms_analytics.country(date_from: 1620643567, date_to: 1623321967)
248
+ ```
249
+
250
+ ### Opens by user-agent name
251
+
252
+ ```ruby
253
+ require "mailersend-ruby"
254
+
255
+ ms_analytics = Mailersend::Analytics.new
256
+ ms_analytics.ua_name(date_from: 1620643567, date_to: 1623321967)
257
+ ```
258
+
259
+ ### Opens by reading environment
260
+
261
+ ```ruby
262
+ require "mailersend-ruby"
263
+
264
+ ms_analytics = Mailersend::Analytics.new
265
+ ms_analytics.ua_type(date_from: 1620643567, date_to: 1623321967)
266
+ ```
267
+
268
+ ## Domains
269
+
270
+ ### Get a list of domains
271
+
272
+ ```ruby
273
+ require "mailersend-ruby"
274
+
275
+ ms_domains = Mailersend::Domains.new
276
+ ms_domains.list
277
+ ```
278
+
279
+ ### Get a single domain
280
+
281
+ ```ruby
282
+ require "mailersend-ruby"
283
+
284
+ ms_domains = Mailersend::Domains.new
285
+ ms_domains.list(domain_id: "idofdomain12412")
286
+ ```
287
+
288
+ ### Delete a domain
289
+
290
+ ```ruby
291
+ require "mailersend-ruby"
292
+
293
+ ms_domains = Mailersend::Domains.new
294
+ ms_domains.delete(domain_id: "idofdomain12412")
295
+ ```
296
+
297
+ ### Update domain settings
298
+
299
+ ```ruby
300
+ require "mailersend-ruby"
301
+
302
+ ms_domains = Mailersend::Domains.new
303
+ ms_domains.settings(domain_id: "idofdomain12412", track_clicks: true, track_unsubscribe: false)
304
+ ```
305
+
306
+ ## Messages
307
+
308
+ ### Get a list of messages
309
+
310
+ ```ruby
311
+ require "mailersend-ruby"
312
+
313
+ ms_messages = Mailersend::Messages.new
314
+ ms_messages.list(page: 1, limit: 10)
315
+ ```
316
+
317
+ ### Get info for a single message
318
+
319
+ ```ruby
320
+ require "mailersend-ruby"
321
+
322
+ ms_messages = Mailersend::Messages.new
323
+ ms_messages.single(message_id: "mess11454")
324
+ ```
325
+
326
+ ## Recipients
327
+
328
+ ### Get recipients
329
+
330
+ ```ruby
331
+ require "mailersend-ruby"
332
+
333
+ ms_recipients = Mailersend::Recipients.new
334
+ ms_recipients.list(page: 1, limit: 10)
335
+ ```
336
+
337
+ ### Get a single recipient
338
+
339
+ ```ruby
340
+ require "mailersend-ruby"
341
+
342
+ ms_recipients = Mailersend::Recipients.new
343
+ ms_recipients.single(recipient_id: "id124")
344
+ ```
345
+
346
+ ### Delete a recipient
347
+
348
+ ```ruby
349
+ require "mailersend-ruby"
350
+
351
+ ms_recipients = Mailersend::Recipients.new
352
+ ms_recipients.delete(recipient_id: "id124")
353
+ ```
354
+
355
+ ## Tokens
356
+
357
+ ### Create a token
358
+ ```ruby
359
+ require "mailersend-ruby"
360
+
361
+ ms_tokens = Mailersend::Tokens.new
362
+ ms_tokens.create(name: "Very nice token", scopes: %w[ email_full domains_read ])
363
+ ```
364
+
365
+ ### Update a token
366
+ ```ruby
367
+ require "mailersend-ruby"
368
+
369
+ ms_tokens = Mailersend::Tokens.new
370
+ ms_tokens.update(token_id: "d2220fx04", name: "Very nice token", scopes: %w[ email_full domains_read activity_read ])
371
+ ```
372
+
373
+ ### Delete a token
374
+ ```ruby
375
+ require "mailersend-ruby"
376
+
377
+ ms_tokens = Mailersend::Tokens.new
378
+ ms_tokens.delete(token_id: "d2220fx04")
379
+ ```
380
+
381
+ ## Webhooks
382
+
383
+ ### List webhooks
384
+ ```ruby
385
+ require "mailersend-ruby"
386
+
387
+ ms_webhooks = Mailersend::Webhooks.new
388
+ ms_webhooks.list(domain_id: "xxx2241ll")
389
+ ```
390
+
391
+ ### Get a webhook
392
+ ```ruby
393
+ require "mailersend-ruby"
394
+
395
+ ms_webhooks = Mailersend::Webhooks.new
396
+ ms_webhooks.list(webhook_id: "zzz2241ll")
397
+ ```
398
+
399
+ ### Create a webhook
400
+ ```ruby
401
+ require "mailersend-ruby"
402
+
403
+ ms_webhooks = Mailersend::Webhooks.new
404
+ ms_webhooks.create(domain_id: "xxx2241ll", url: "https://domain.com/hook", name: "Webhook", events: ["activity.sent", "activity.delivered"], enabled: true)
405
+ ```
406
+
407
+ ### Update a webhook
408
+ ```ruby
409
+ require "mailersend-ruby"
410
+
411
+ ms_webhooks = Mailersend::Webhooks.new
412
+ ms_webhooks.update(webhook_id: "zzz2241ll", enabled: false)
413
+ ```
414
+
415
+ # Support and Feedback
416
+
417
+ In case you find any bugs, submit an issue directly here in GitHub.
418
+
419
+ You are welcome to create SDK for any other programming language.
420
+
421
+ If you have any troubles using our API or SDK free to contact our support by email [info@mailersend.com](mailto:info@mailersend.com)
422
+
423
+ The official documentation is at [https://developers.mailersend.com](https://developers.mailersend.com)
424
+
425
+ # License
426
+
427
+ [The MIT License (MIT)](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require_relative "../lib/mailersend/version"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mailersend"
data/lib/mailersend.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mailersend/client"
4
+ require "mailersend/activity/activity"
5
+ require "mailersend/analytics/analytics"
6
+ require "mailersend/domains/domains"
7
+ require "mailersend/email/email"
8
+ require "mailersend/messages/messages"
9
+ require "mailersend/recipients/recipients"
10
+ require "mailersend/tokens/tokens"
11
+ require "mailersend/webhooks/webhooks"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # Activity endpoint from MailerSend API
5
+ class Activity
6
+ attr_accessor :client,
7
+ :domain_id,
8
+ :page,
9
+ :limit,
10
+ :date_from,
11
+ :date_to
12
+
13
+ def initialize(client = Mailersend::Client.new)
14
+ @client = client
15
+ @domain_id = domain_id
16
+ @page = page
17
+ @limit = limit
18
+ @date_from = date_from
19
+ @date_to = date_to
20
+ end
21
+
22
+ def get(domain_id:, page: nil, limit: nil, date_from: nil, date_to: nil)
23
+ hash = {
24
+ page: page,
25
+ limit: limit,
26
+ date_from: date_from,
27
+ date_to: date_to
28
+ }
29
+
30
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/analytics/#{domain_id}",
31
+ query: URI.encode_www_form(hash.compact)))
32
+ puts response
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # This is a class for getting the analytics from MailerSend API.
5
+ class Analytics
6
+ attr_accessor :client,
7
+ :date_from,
8
+ :date_to,
9
+ :events,
10
+ :domain_id,
11
+ :recipient_id,
12
+ :group_by,
13
+ :tags
14
+
15
+ def initialize(client = Mailersend::Client.new)
16
+ @client = client
17
+ @date_from = ""
18
+ @date_to = ""
19
+ @events = []
20
+ @domain_id = ""
21
+ @recipient_id = ""
22
+ @group_by = ""
23
+ @tags = []
24
+ end
25
+
26
+ def date(date_from:, date_to:, events:, domain_id: nil, recipient_id: nil, group_by: nil, tags: nil)
27
+ hash = {
28
+ "date_from" => date_from,
29
+ "date_to" => date_to,
30
+ "event[]" => events,
31
+ "domain_id" => domain_id,
32
+ "recipient_id" => recipient_id,
33
+ "group_by" => group_by,
34
+ "tags[]" => tags
35
+ }
36
+
37
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/analytics/date",
38
+ query: URI.encode_www_form(hash.compact)))
39
+ puts response
40
+ end
41
+
42
+ def country(date_from:, date_to:, domain_id: nil, recipient_id: nil, tags: nil)
43
+ hash = {
44
+ domain_id: domain_id,
45
+ recipient_id: recipient_id,
46
+ date_from: date_from,
47
+ date_to: date_to,
48
+ "tags[]": tags
49
+ }
50
+
51
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/analytics/country",
52
+ query: URI.encode_www_form(hash.compact)))
53
+ puts response
54
+ end
55
+
56
+ def ua_name(date_from:, date_to:, domain_id: nil, recipient_id: nil, tags: nil)
57
+ hash = {
58
+ domain_id: domain_id,
59
+ recipient_id: recipient_id,
60
+ date_from: date_from,
61
+ date_to: date_to,
62
+ "tags[]": tags
63
+ }
64
+
65
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/analytics/ua-name",
66
+ query: URI.encode_www_form(hash.compact)))
67
+ puts response
68
+ end
69
+
70
+ def ua_type(date_from:, date_to:, domain_id: nil, recipient_id: nil, tags: nil)
71
+ hash = {
72
+ domain_id: domain_id,
73
+ recipient_id: recipient_id,
74
+ date_from: date_from,
75
+ date_to: date_to,
76
+ "tags[]": tags
77
+ }
78
+
79
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/analytics/ua-type",
80
+ query: URI.encode_www_form(hash.compact)))
81
+ puts response
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+ require "dotenv/load"
5
+
6
+ API_URL = "https://api.mailersend.com/v1"
7
+ API_BASE_HOST = "api.mailersend.com"
8
+
9
+ Dotenv.require_keys("API_TOKEN")
10
+
11
+ # mailersend-ruby is a gem that integrates all endpoints from MailerSend API
12
+ module Mailersend
13
+ attr_reader :api_token
14
+
15
+ # Inits the client.
16
+ class Client
17
+ def initialize(api_token = ENV["API_TOKEN"])
18
+ @api_token = api_token
19
+ end
20
+
21
+ def http
22
+ HTTP
23
+ .timeout(connect: 15, read: 30)
24
+ .auth(@api_token)
25
+ .headers("User-Agent" => "MailerSend-client-ruby/1.0.0",
26
+ "Accept" => "application/json")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # Domains endpoint from MailerSend API
5
+ class Domains
6
+ attr_accessor :client,
7
+ :domain_id,
8
+ :page,
9
+ :limit,
10
+ :verified
11
+
12
+ def initialize(client = Mailersend.client.new)
13
+ @client = client
14
+ @domain_id = domain_id
15
+ @page = page
16
+ @limit = limit
17
+ @verified = verified
18
+ end
19
+
20
+ def list
21
+ hash = {
22
+ "page" => page,
23
+ "limit" => limit,
24
+ "verified" => verified
25
+ }
26
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/domains/#{domain_id}",
27
+ query: URI.encode_www_form(hash.compact)))
28
+ puts response
29
+ end
30
+
31
+ def delete(domain_id:)
32
+ response = client.http.delete(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/domains/#{domain_id}"))
33
+ puts response
34
+ end
35
+
36
+ def recipients(domain_id:)
37
+ hash = {
38
+ "page" => page,
39
+ "limit" => limit
40
+ }
41
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/domains/#{domain_id}/recipients",
42
+ query: URI.encode_www_form(hash.compact)))
43
+ puts response
44
+ end
45
+
46
+ def settings(domain_id:, send_paused: nil, track_clicks: nil, track_opens: nil, track_unsubscribe: nil, track_unsubscribe_html: nil, track_unsubscribe_plain: nil, track_content: nil, custom_tracking_enabled: nil, custom_tracking_subdomain: nil)
47
+ hash = {
48
+ "send_paused" => send_paused,
49
+ "track_clicks" => track_clicks,
50
+ "track_opens" => track_opens,
51
+ "track_unsubscribe" => track_unsubscribe,
52
+ "track_unsubscribe_html" => track_unsubscribe_html,
53
+ "track_unsubscribe_plain" => track_unsubscribe_plain,
54
+ "track_content" => track_content,
55
+ "custom_tracking_enabled" => custom_tracking_enabled,
56
+ "custom_tracking_subdomain" => custom_tracking_subdomain
57
+ }
58
+ response = client.http.put("#{API_URL}/domains/#{domain_id}/settings", json: hash.compact)
59
+ puts response
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+
5
+ module Mailersend
6
+ # Send an email through MailerSend API
7
+ class Email
8
+ attr_accessor :client,
9
+ :from,
10
+ :recipients,
11
+ :subject,
12
+ :text,
13
+ :html,
14
+ :ccs,
15
+ :bcc,
16
+ :reply_to,
17
+ :attachments,
18
+ :template_id,
19
+ :tags,
20
+ :variables,
21
+ :personalization
22
+
23
+ def initialize(client = Mailersend::Client.new)
24
+ @client = client
25
+ @from = {}
26
+ @recipients = []
27
+ @ccs = []
28
+ @bcc = []
29
+ @reply_to = {}
30
+ @subject = nil
31
+ @text = {}
32
+ @html = {}
33
+ @variables = []
34
+ @personalization = []
35
+ @attachments = []
36
+ @tags = []
37
+ end
38
+
39
+ def add_recipients(recipients)
40
+ @recipients << recipients
41
+ end
42
+
43
+ def add_from(from)
44
+ @from = from
45
+ end
46
+
47
+ def add_cc(ccs)
48
+ @ccs << ccs
49
+ end
50
+
51
+ def add_bcc(bcc)
52
+ @bcc << bcc
53
+ end
54
+
55
+ def add_reply_to(_reply_to)
56
+ @reply_to = reply to
57
+ end
58
+
59
+ def add_subject(subject)
60
+ @subject = subject
61
+ end
62
+
63
+ def add_text(text)
64
+ @text = text
65
+ end
66
+
67
+ def add_html(html)
68
+ @html = html
69
+ end
70
+
71
+ def add_variables(variables)
72
+ @variables << variables
73
+ end
74
+
75
+ def add_personalization(personalization)
76
+ @personalization << personalization
77
+ end
78
+
79
+ def add_template_id(template_id)
80
+ @template_id = template_id
81
+ end
82
+
83
+ def add_tags(tags)
84
+ @tags << tags
85
+ end
86
+
87
+ def add_attachment(content:, filename:)
88
+ data = File.open(content.to_s).read
89
+ encoded = Base64.strict_encode64(data)
90
+ attachments << {
91
+ "content" => encoded,
92
+ "filename" => filename
93
+ }
94
+ end
95
+
96
+ def send
97
+ message = {
98
+ "from" => from,
99
+ "to" => recipients,
100
+ "cc" => ccs,
101
+ "bcc" => bcc,
102
+ "reply_to" => reply_to,
103
+ "subject" => subject,
104
+ "text" => text,
105
+ "html" => html,
106
+ "variables" => variables,
107
+ "personalization" => personalization,
108
+ "template_id" => template_id,
109
+ "attachments" => attachments
110
+ }
111
+
112
+ response = client.http.post("#{API_URL}/email", json: message.compact)
113
+ puts response
114
+ puts response.status.code
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # Messages endpoint from MailerSend API.
5
+ class Messages
6
+ attr_accessor :client,
7
+ :page,
8
+ :limit,
9
+ :message_id
10
+
11
+ def initialize(client = Mailersend::Client.new)
12
+ @client = client
13
+ @page = page
14
+ @limit = limit
15
+ @message_id = message_id
16
+ end
17
+
18
+ def list(page: nil, limit: nil)
19
+ hash = {
20
+ "page" => page,
21
+ "limit" => limit
22
+ }
23
+
24
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/messages",
25
+ query: URI.encode_www_form(hash)))
26
+ puts response
27
+ end
28
+
29
+ def single(message_id:)
30
+ response = client.http.get("#{API_URL}/messages/#{message_id}")
31
+ puts response
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # Recipients endpoint from MailerSend API.
5
+ class Recipients
6
+ attr_accessor :client,
7
+ :page,
8
+ :limit,
9
+ :recipient_id
10
+
11
+ def initialize(client = Mailersend::Client.new)
12
+ @client = client
13
+ @page = page
14
+ @limit = limit
15
+ @recipient_id = recipient_id
16
+ end
17
+
18
+ def list(page: nil, limit: nil)
19
+ hash = {
20
+ "page" => page,
21
+ "limit" => limit
22
+ }
23
+
24
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/recipients",
25
+ query: URI.encode_www_form(hash)))
26
+ puts response
27
+ end
28
+
29
+ def single(recipient_id:)
30
+ response = client.http.get("#{API_URL}/recipients/#{recipient_id}")
31
+ puts response
32
+ end
33
+
34
+ def delete(recipient_id:)
35
+ response = client.http.delete("#{API_URL}/recipients/#{recipient_id}")
36
+ puts response
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # Tokens endpoint from MailerSend API.
5
+ class Tokens
6
+ attr_accessor :client,
7
+ :name,
8
+ :scopes,
9
+ :token_id,
10
+ :status
11
+
12
+ def initialize(client = Mailersend::Client.new)
13
+ @client = client
14
+ @name = {}
15
+ @scopes = []
16
+ @token_id = {}
17
+ @status = {}
18
+ end
19
+
20
+ def create(name:, scopes:)
21
+ json = {
22
+ "name" => name,
23
+ "scopes" => scopes
24
+ }
25
+ response = client.http.post("#{API_URL}/token", json: json)
26
+ puts response
27
+ end
28
+
29
+ def update(token_id:, status:)
30
+ status = {
31
+ status: status
32
+ }
33
+ response = client.http.put("#{API_URL}/token/#{token_id}/settings", json: status)
34
+ puts response
35
+ end
36
+
37
+ def delete(name:)
38
+ response = client.http.delete("#{API_URL}/token/#{name}")
39
+ puts response
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailersend
4
+ # This is a class for getting the analytics from MailerSend API.
5
+ class Webhooks
6
+ attr_accessor :client,
7
+ :domain_id,
8
+ :url,
9
+ :name,
10
+ :events,
11
+ :enabled
12
+
13
+ def initialize(client = Mailersend::Client.new)
14
+ @client = client
15
+ @domain_id = domain_id
16
+ @url = url
17
+ @name = name
18
+ @events = []
19
+ @enabled = enabled
20
+ @events = events
21
+ end
22
+
23
+ def list(domain_id:)
24
+ hash = {
25
+ "domain_id" => domain_id
26
+ }
27
+ response = client.http.get(URI::HTTPS.build(host: API_BASE_HOST, path: "/v1/webhooks",
28
+ query: URI.encode_www_form(hash)))
29
+ puts response
30
+ end
31
+
32
+ def single(webhook_id:)
33
+ response = client.http.get("#{API_URL}/webhooks/#{webhook_id}")
34
+ puts response
35
+ end
36
+
37
+ def create(url:, name:, events:, domain_id:, enabled: nil)
38
+ hash = {
39
+ "url" => url,
40
+ "name" => name,
41
+ "events" => events,
42
+ "domain_id" => domain_id,
43
+ "enabled" => enabled.to_s == "true"
44
+ }
45
+
46
+ response = client.http.post("#{API_URL}/webhooks", json: hash.compact)
47
+ puts response
48
+ end
49
+
50
+ def update(webhook_id:, url: nil, name: nil, events: nil, enabled: nil)
51
+ hash = {
52
+ "url" => url,
53
+ "name" => name,
54
+ "events" => events,
55
+ "enabled" => enabled.to_s == "true"
56
+ }
57
+ response = client.http.put("#{API_URL}/webhooks/#{webhook_id}", json: hash.compact)
58
+ puts response
59
+ end
60
+
61
+ def delete(webhook_id:)
62
+ response = client.http.delete("#{API_URL}/webhooks/#{webhook_id}")
63
+ puts response
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "mailersend/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "mailersend-ruby"
9
+ spec.version = Mailersend::VERSION
10
+ spec.authors = ["Nikola Milojević"]
11
+ spec.email = ["info@mailersend.com"]
12
+
13
+ spec.summary = "MailerSend's official Ruby SDK"
14
+ spec.description = "MailerSend's official Ruby SDK. Interacts will all endpoints at MailerSend API."
15
+ spec.homepage = "https://www.mailersend.com"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.5.0"
18
+
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/mailersend/mailersend-ruby"
23
+ spec.metadata["changelog_uri"] = "https://github.com/mailersend/mailersend-ruby/CHANGELOG.md"
24
+
25
+ spec.files = `git ls-files -z`.split("\x0")
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.2.15"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rubocop", "~> 1.7"
32
+ spec.add_dependency "dotenv-rails", "~> 2.7"
33
+ spec.add_dependency "http", "~> 5.0"
34
+ spec.add_dependency "json", "~> 2.5"
35
+ spec.add_dependency "uri", "~> 0.10.1"
36
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailersend-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikola Milojević
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.15
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.15
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: http
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.5'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: uri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.1
111
+ description: MailerSend's official Ruby SDK. Interacts will all endpoints at MailerSend
112
+ API.
113
+ email:
114
+ - info@mailersend.com
115
+ executables:
116
+ - console
117
+ - setup
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".env.example"
122
+ - ".github/workflows/main.yml"
123
+ - ".gitignore"
124
+ - ".rubocop.yml"
125
+ - CHANGELOG.md
126
+ - Gemfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - lib/mailersend-ruby.rb
133
+ - lib/mailersend.rb
134
+ - lib/mailersend/activity/activity.rb
135
+ - lib/mailersend/analytics/analytics.rb
136
+ - lib/mailersend/client.rb
137
+ - lib/mailersend/domains/domains.rb
138
+ - lib/mailersend/email/email.rb
139
+ - lib/mailersend/messages/messages.rb
140
+ - lib/mailersend/recipients/recipients.rb
141
+ - lib/mailersend/tokens/tokens.rb
142
+ - lib/mailersend/version.rb
143
+ - lib/mailersend/webhooks/webhooks.rb
144
+ - mailersend-ruby.gemspec
145
+ homepage: https://www.mailersend.com
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
150
+ homepage_uri: https://www.mailersend.com
151
+ source_code_uri: https://github.com/mailersend/mailersend-ruby
152
+ changelog_uri: https://github.com/mailersend/mailersend-ruby/CHANGELOG.md
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 2.5.0
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.2.15
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: MailerSend's official Ruby SDK
172
+ test_files: []