mailersend-ruby 3.1.0 → 3.4.1
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 +4 -4
- data/.envrc +2 -0
- data/.github/workflows/main.yml +1 -1
- data/.github/workflows/publish_gem.yml +17 -14
- data/.gitignore +2 -1
- data/.vesnik.yaml +36 -0
- data/README.md +423 -0
- data/fixtures/email/email_send_template_language.yml +56 -0
- data/fixtures/emails/emails_list_emails.yml +35 -0
- data/fixtures/emails/emails_list_emails_empty_page.yml +35 -0
- data/fixtures/emails/emails_single_email.yml +35 -0
- data/fixtures/whatsapp/whatsapp_send.yml +47 -0
- data/fixtures/whatsapp/whatsapp_send_multiple_recipients.yml +47 -0
- data/fixtures/whatsapp/whatsapp_send_personalization.yml +47 -0
- data/fixtures/whatsapp_activities/whatsapp_activities_list.yml +43 -0
- data/fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_get.yml +43 -0
- data/fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_list.yml +43 -0
- data/fixtures/whatsapp_items/whatsapp_items_get.yml +43 -0
- data/fixtures/whatsapp_items/whatsapp_items_list.yml +43 -0
- data/fixtures/whatsapp_messages/whatsapp_messages_get.yml +43 -0
- data/fixtures/whatsapp_messages/whatsapp_messages_list.yml +43 -0
- data/fixtures/whatsapp_recipient/whatsapp_recipient_get.yml +43 -0
- data/fixtures/whatsapp_recipient/whatsapp_recipient_list.yml +43 -0
- data/fixtures/whatsapp_templates/whatsapp_templates_get.yml +43 -0
- data/fixtures/whatsapp_templates/whatsapp_templates_list.yml +43 -0
- data/flake.lock +49 -0
- data/flake.nix +31 -0
- data/justfile +56 -0
- data/lefthook.yml +14 -0
- data/lib/mailersend/email/email.rb +10 -0
- data/lib/mailersend/emails/emails.rb +44 -0
- data/lib/mailersend/version.rb +1 -1
- data/lib/mailersend/whatsapp/whatsapp.rb +47 -0
- data/lib/mailersend/whatsapp_activities/whatsapp_activities.rb +45 -0
- data/lib/mailersend/whatsapp_inbound_messages/whatsapp_inbound_messages.rb +47 -0
- data/lib/mailersend/whatsapp_items/whatsapp_items.rb +57 -0
- data/lib/mailersend/whatsapp_messages/whatsapp_messages.rb +47 -0
- data/lib/mailersend/whatsapp_recipient/whatsapp_recipient.rb +38 -0
- data/lib/mailersend/whatsapp_templates/whatsapp_templates.rb +44 -0
- data/lib/mailersend.rb +8 -0
- data/mailersend-ruby.gemspec +1 -1
- data/spec/email_rspec.rb +15 -0
- data/spec/emails_rspec.rb +175 -0
- data/spec/whatsapp_activities_rspec.rb +38 -0
- data/spec/whatsapp_inbound_messages_rspec.rb +49 -0
- data/spec/whatsapp_items_rspec.rb +52 -0
- data/spec/whatsapp_messages_rspec.rb +50 -0
- data/spec/whatsapp_recipient_rspec.rb +40 -0
- data/spec/whatsapp_rspec.rb +65 -0
- data/spec/whatsapp_templates_rspec.rb +48 -0
- metadata +47 -5
- data/CHANGELOG.md +0 -148
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.mailersend.com/v1/whatsapp/templates?category=UTILITY&language=en_US&limit=25&page=1&status=approved&whatsapp_account_id=3enl6x27wmrxrl2v
|
|
6
|
+
body:
|
|
7
|
+
encoding: ASCII-8BIT
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
Authorization:
|
|
11
|
+
- "<AUTH>"
|
|
12
|
+
User-Agent:
|
|
13
|
+
- MailerSend-client-ruby/3.4.0
|
|
14
|
+
Accept:
|
|
15
|
+
- application/json
|
|
16
|
+
Connection:
|
|
17
|
+
- close
|
|
18
|
+
Host:
|
|
19
|
+
- api.mailersend.com
|
|
20
|
+
response:
|
|
21
|
+
status:
|
|
22
|
+
code: 200
|
|
23
|
+
message: OK
|
|
24
|
+
headers:
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 20 Oct 2026 08:00:00 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- close
|
|
33
|
+
Cache-Control:
|
|
34
|
+
- no-cache, private
|
|
35
|
+
Strict-Transport-Security:
|
|
36
|
+
- max-age=31536000; includeSubDomains
|
|
37
|
+
Server:
|
|
38
|
+
- cloudflare
|
|
39
|
+
body:
|
|
40
|
+
encoding: UTF-8
|
|
41
|
+
string: '{"data":[{"id":"23zxk54v6gjy6v7m","whatsapp_account_id":"3enl6x27wmrxrl2v","name":"order_confirmation","readable_name":"Order confirmation","category":"UTILITY","language":"en_US","status":"approved","components":{"header":{"format":"TEXT","text":"{{1}}"},"body":{"text":"Hi {{1}}, your order is confirmed and will arrive on {{2}}."},"buttons":[{"type":"URL","text":"View order","url":"https://shop.example.com/{{1}}"}]},"created_at":"2026-10-14T12:25:33.000000Z","updated_at":"2026-10-14T12:41:07.000000Z"},{"id":"p6nq4jyzkyv5x3zl","whatsapp_account_id":"3enl6x27wmrxrl2v","name":"delivery_update","readable_name":"Delivery update","category":"UTILITY","language":"en_US","status":"approved","components":{"header":null,"body":{"text":"Your parcel is out for delivery today."},"buttons":[{"type":"QUICK_REPLY","text":"Change delivery time","url":null}]},"created_at":"2026-10-13T09:02:18.000000Z","updated_at":"2026-10-13T09:02:18.000000Z"}],"links":{"first":"https://api.mailersend.com/v1/whatsapp/templates?page=1","last":null,"prev":null,"next":null},"meta":{"current_page":1,"current_page_url":"https://api.mailersend.com/v1/whatsapp/templates?page=1","from":1,"path":"https://api.mailersend.com/v1/whatsapp/templates","per_page":25,"to":2}}'
|
|
42
|
+
recorded_at: Tue, 20 Oct 2026 08:00:00 GMT
|
|
43
|
+
recorded_with: VCR 6.3.1
|
data/flake.lock
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodes": {
|
|
3
|
+
"nixpkgs": {
|
|
4
|
+
"locked": {
|
|
5
|
+
"lastModified": 1789546076,
|
|
6
|
+
"narHash": "sha256-zVxLZiSnmaaPLwnhj7pwmqe3axBg/C6nG5JZsJMh2g4=",
|
|
7
|
+
"owner": "NixOS",
|
|
8
|
+
"repo": "nixpkgs",
|
|
9
|
+
"rev": "b1b875982b17dabde9b4a37f3e229e74913e6db3",
|
|
10
|
+
"type": "github"
|
|
11
|
+
},
|
|
12
|
+
"original": {
|
|
13
|
+
"owner": "NixOS",
|
|
14
|
+
"ref": "nixos-unstable",
|
|
15
|
+
"repo": "nixpkgs",
|
|
16
|
+
"type": "github"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"root": {
|
|
20
|
+
"inputs": {
|
|
21
|
+
"nixpkgs": "nixpkgs",
|
|
22
|
+
"vesnik": "vesnik"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"vesnik": {
|
|
26
|
+
"inputs": {
|
|
27
|
+
"nixpkgs": [
|
|
28
|
+
"nixpkgs"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"locked": {
|
|
32
|
+
"lastModified": 1792501163,
|
|
33
|
+
"narHash": "sha256-NL9FUQSh2m8WD67KBuWi0Y5jy+qkGE/0dT+BC3MJD60=",
|
|
34
|
+
"owner": "nklmilojevic",
|
|
35
|
+
"repo": "vesnik",
|
|
36
|
+
"rev": "ee5d22cdabf097da4fbcd975da9473a8be78ea28",
|
|
37
|
+
"type": "github"
|
|
38
|
+
},
|
|
39
|
+
"original": {
|
|
40
|
+
"owner": "nklmilojevic",
|
|
41
|
+
"ref": "v0.2.0",
|
|
42
|
+
"repo": "vesnik",
|
|
43
|
+
"type": "github"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"root": "root",
|
|
48
|
+
"version": 7
|
|
49
|
+
}
|
data/flake.nix
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
description = "MailerSend Ruby SDK environment";
|
|
3
|
+
|
|
4
|
+
inputs = {
|
|
5
|
+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
6
|
+
# Release notes and versions for `just release`.
|
|
7
|
+
vesnik = {
|
|
8
|
+
url = "github:nklmilojevic/vesnik/v0.2.0";
|
|
9
|
+
inputs.nixpkgs.follows = "nixpkgs";
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
outputs = { self, nixpkgs, vesnik }:
|
|
14
|
+
let
|
|
15
|
+
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
|
|
16
|
+
forEachSystem = f:
|
|
17
|
+
nixpkgs.lib.genAttrs systems (system: f system nixpkgs.legacyPackages.${system});
|
|
18
|
+
in
|
|
19
|
+
{
|
|
20
|
+
devShells = forEachSystem (system: pkgs: {
|
|
21
|
+
default = pkgs.mkShell {
|
|
22
|
+
packages = with pkgs; [
|
|
23
|
+
lefthook
|
|
24
|
+
gitleaks
|
|
25
|
+
git-secrets
|
|
26
|
+
just
|
|
27
|
+
] ++ [ vesnik.packages.${system}.default ];
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
data/justfile
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
set shell := ["bash", "-uc"]
|
|
2
|
+
|
|
3
|
+
[private]
|
|
4
|
+
default:
|
|
5
|
+
@just --list
|
|
6
|
+
|
|
7
|
+
# Release main: vesnik picks the version (minor if the model gives none) and writes the notes
|
|
8
|
+
release:
|
|
9
|
+
@git checkout main
|
|
10
|
+
@git pull --tags -f
|
|
11
|
+
@just _publish-release --default-bump minor
|
|
12
|
+
@just _open "https://github.com/mailersend/mailersend-ruby/releases"
|
|
13
|
+
|
|
14
|
+
# Release main as a patch version
|
|
15
|
+
hotfix-release:
|
|
16
|
+
@git checkout main
|
|
17
|
+
@git pull --tags -f
|
|
18
|
+
@just _publish-release --bump patch
|
|
19
|
+
@just _open "https://github.com/mailersend/mailersend-ruby/releases"
|
|
20
|
+
|
|
21
|
+
# --- Internal helpers ----------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
# Tag main and publish the GitHub Release with vesnik from PATH or the Nix dev
|
|
24
|
+
# shell; the tag push starts the RubyGems publish workflow. Without vesnik, the
|
|
25
|
+
# version is typed by hand. VESNIK_YES=1 skips vesnik's review.
|
|
26
|
+
[private]
|
|
27
|
+
_publish-release +flags:
|
|
28
|
+
#!/usr/bin/env bash
|
|
29
|
+
set -uo pipefail
|
|
30
|
+
vesnik=""
|
|
31
|
+
if command -v vesnik >/dev/null 2>&1; then
|
|
32
|
+
vesnik="vesnik"
|
|
33
|
+
elif command -v nix >/dev/null 2>&1; then
|
|
34
|
+
vesnik="nix develop --command vesnik"
|
|
35
|
+
fi
|
|
36
|
+
if [ -n "$vesnik" ]; then
|
|
37
|
+
review=""
|
|
38
|
+
if [ "${VESNIK_YES:-}" = 1 ]; then review="--yes"; fi
|
|
39
|
+
$vesnik release {{flags}} $review
|
|
40
|
+
case $? in
|
|
41
|
+
0) exit 0 ;;
|
|
42
|
+
3) echo "Release aborted; nothing was tagged." >&2; exit 1 ;;
|
|
43
|
+
4) echo "The tag is pushed but the GitHub Release failed; run: vesnik renote <tag>" >&2; exit 1 ;;
|
|
44
|
+
*) echo "vesnik failed before tagging; falling back to the manual release." >&2 ;;
|
|
45
|
+
esac
|
|
46
|
+
fi
|
|
47
|
+
echo "> Latest version:"
|
|
48
|
+
git tag -l --sort=-creatordate | head -n 1
|
|
49
|
+
read -r VERSION || exit 1
|
|
50
|
+
# No --generate-notes: it copies PR titles, which carry internal ticket keys.
|
|
51
|
+
gh release create "$VERSION" --target main --notes "" || exit 1
|
|
52
|
+
echo "Add the release notes: vesnik renote $VERSION"
|
|
53
|
+
|
|
54
|
+
[private]
|
|
55
|
+
_open url:
|
|
56
|
+
@if [ "$(uname -s)" = "Darwin" ]; then open "{{url}}"; elif command -v xdg-open >/dev/null 2>&1; then xdg-open "{{url}}"; else echo "{{url}}"; fi
|
data/lefthook.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
pre-commit:
|
|
3
|
+
commands:
|
|
4
|
+
gitleaks:
|
|
5
|
+
run: gitleaks git --pre-commit --redact --staged --verbose --no-banner
|
|
6
|
+
fail_text: Staged changes contain a secret. Remove it; never commit and revert.
|
|
7
|
+
secrets:
|
|
8
|
+
run: |
|
|
9
|
+
git secrets --list | grep -q 'mssp' || {
|
|
10
|
+
git secrets --register-aws
|
|
11
|
+
git secrets --add 'mlsn\.[A-Za-z0-9._-]+'
|
|
12
|
+
git secrets --add 'mssp\.[A-Za-z0-9._-]+'
|
|
13
|
+
}
|
|
14
|
+
git secrets --scan {staged_files}
|
|
@@ -16,6 +16,7 @@ module Mailersend
|
|
|
16
16
|
:reply_to,
|
|
17
17
|
:attachments,
|
|
18
18
|
:template_id,
|
|
19
|
+
:language,
|
|
19
20
|
:tags,
|
|
20
21
|
:variables,
|
|
21
22
|
:personalization,
|
|
@@ -40,6 +41,7 @@ module Mailersend
|
|
|
40
41
|
@headers = {}
|
|
41
42
|
@list_unsubscribe = nil
|
|
42
43
|
@send_at = send_at
|
|
44
|
+
@language = nil
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
def add_recipients(recipients)
|
|
@@ -86,6 +88,13 @@ module Mailersend
|
|
|
86
88
|
@template_id = template_id
|
|
87
89
|
end
|
|
88
90
|
|
|
91
|
+
# Language code (e.g. 'de', 'fr', 'pt-BR'). Only meaningful when a
|
|
92
|
+
# template_id is set; ignored for raw html/text sends. Max length 10.
|
|
93
|
+
# Supported: de, en, es, fr, it, lt, nl, pl, pt-BR
|
|
94
|
+
def add_language(language)
|
|
95
|
+
@language = language
|
|
96
|
+
end
|
|
97
|
+
|
|
89
98
|
def add_tags(tags)
|
|
90
99
|
@tags << tags
|
|
91
100
|
end
|
|
@@ -131,6 +140,7 @@ module Mailersend
|
|
|
131
140
|
'variables' => @variables,
|
|
132
141
|
'personalization' => @personalization,
|
|
133
142
|
'template_id' => @template_id,
|
|
143
|
+
'language' => @language,
|
|
134
144
|
'attachments' => @attachments,
|
|
135
145
|
'headers' => @headers,
|
|
136
146
|
'list_unsubscribe' => @list_unsubscribe,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# Emails endpoint from MailerSend API.
|
|
5
|
+
class Emails
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:domain_id,
|
|
8
|
+
:date_from,
|
|
9
|
+
:date_to,
|
|
10
|
+
:limit,
|
|
11
|
+
:page,
|
|
12
|
+
:email_id
|
|
13
|
+
|
|
14
|
+
def initialize(client = Mailersend::Client.new)
|
|
15
|
+
@client = client
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def list(domain_id:, date_from:, date_to:, limit: nil, page: nil, status: nil, interaction: nil,
|
|
19
|
+
recipient_email: nil, message_id: nil, template_id: nil, subject: nil, tag: nil)
|
|
20
|
+
hash = {
|
|
21
|
+
'domain_id' => domain_id,
|
|
22
|
+
'date_from' => date_from,
|
|
23
|
+
'date_to' => date_to,
|
|
24
|
+
'limit' => limit,
|
|
25
|
+
'page' => page,
|
|
26
|
+
# The API rejects a scalar status/interaction with 422, so they are always sent in array form.
|
|
27
|
+
'status[]' => status,
|
|
28
|
+
'interaction[]' => interaction,
|
|
29
|
+
'recipient_email' => recipient_email,
|
|
30
|
+
'message_id' => message_id,
|
|
31
|
+
'template_id' => template_id,
|
|
32
|
+
'subject' => subject,
|
|
33
|
+
'tag' => tag
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/emails',
|
|
37
|
+
query: URI.encode_www_form(hash.compact)))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def single(email_id:)
|
|
41
|
+
client.http.get("#{MAILERSEND_API_URL}/email/#{email_id}")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/mailersend/version.rb
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# Send a WhatsApp message through MailerSend API
|
|
5
|
+
class WhatsApp
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:from,
|
|
8
|
+
:to,
|
|
9
|
+
:template_id,
|
|
10
|
+
:personalization
|
|
11
|
+
|
|
12
|
+
def initialize(client = Mailersend::Client.new)
|
|
13
|
+
@client = client
|
|
14
|
+
@from = ''
|
|
15
|
+
@to = []
|
|
16
|
+
@template_id = ''
|
|
17
|
+
@personalization = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_from(from)
|
|
21
|
+
@from = from
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_to(to)
|
|
25
|
+
@to << to
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_template_id(template_id)
|
|
29
|
+
@template_id = template_id
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_personalization(personalization)
|
|
33
|
+
@personalization << personalization
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def send
|
|
37
|
+
message = {
|
|
38
|
+
'from' => @from,
|
|
39
|
+
'to' => @to,
|
|
40
|
+
'template_id' => @template_id,
|
|
41
|
+
'personalization' => @personalization
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
client.http.post("#{MAILERSEND_API_URL}/whatsapp/send", json: message.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} })
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Activities endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppActivities
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:whatsapp_item_id,
|
|
8
|
+
:whatsapp_message_id,
|
|
9
|
+
:recipient,
|
|
10
|
+
:type,
|
|
11
|
+
:date_from,
|
|
12
|
+
:date_to,
|
|
13
|
+
:page,
|
|
14
|
+
:limit
|
|
15
|
+
|
|
16
|
+
def initialize(client = Mailersend::Client.new)
|
|
17
|
+
@client = client
|
|
18
|
+
@whatsapp_item_id = whatsapp_item_id
|
|
19
|
+
@whatsapp_message_id = whatsapp_message_id
|
|
20
|
+
@recipient = recipient
|
|
21
|
+
@type = type
|
|
22
|
+
@date_from = date_from
|
|
23
|
+
@date_to = date_to
|
|
24
|
+
@page = page
|
|
25
|
+
@limit = limit
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def list(whatsapp_item_id: nil, whatsapp_message_id: nil, recipient: nil, type: nil, date_from: nil, date_to: nil,
|
|
29
|
+
page: nil, limit: nil)
|
|
30
|
+
hash = {
|
|
31
|
+
'whatsapp_item_id' => whatsapp_item_id,
|
|
32
|
+
'whatsapp_message_id' => whatsapp_message_id,
|
|
33
|
+
'recipient' => recipient,
|
|
34
|
+
'type[]' => type,
|
|
35
|
+
'date_from' => date_from,
|
|
36
|
+
'date_to' => date_to,
|
|
37
|
+
'page' => page,
|
|
38
|
+
'limit' => limit
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/activities',
|
|
42
|
+
query: URI.encode_www_form(hash.compact)))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Inbound Messages endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppInboundMessages
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:whatsapp_account_id,
|
|
8
|
+
:from,
|
|
9
|
+
:type,
|
|
10
|
+
:date_from,
|
|
11
|
+
:date_to,
|
|
12
|
+
:page,
|
|
13
|
+
:limit,
|
|
14
|
+
:whatsapp_inbound_message_id
|
|
15
|
+
|
|
16
|
+
def initialize(client = Mailersend::Client.new)
|
|
17
|
+
@client = client
|
|
18
|
+
@whatsapp_account_id = whatsapp_account_id
|
|
19
|
+
@from = from
|
|
20
|
+
@type = type
|
|
21
|
+
@date_from = date_from
|
|
22
|
+
@date_to = date_to
|
|
23
|
+
@page = page
|
|
24
|
+
@limit = limit
|
|
25
|
+
@whatsapp_inbound_message_id = whatsapp_inbound_message_id
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def list(whatsapp_account_id: nil, from: nil, type: nil, date_from: nil, date_to: nil, page: nil, limit: nil)
|
|
29
|
+
hash = {
|
|
30
|
+
'whatsapp_account_id' => whatsapp_account_id,
|
|
31
|
+
'from' => from,
|
|
32
|
+
'type[]' => type,
|
|
33
|
+
'date_from' => date_from,
|
|
34
|
+
'date_to' => date_to,
|
|
35
|
+
'page' => page,
|
|
36
|
+
'limit' => limit
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/inbound-messages',
|
|
40
|
+
query: URI.encode_www_form(hash.compact)))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get(whatsapp_inbound_message_id:)
|
|
44
|
+
client.http.get("#{MAILERSEND_API_URL}/whatsapp/inbound-messages/#{whatsapp_inbound_message_id}")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Items endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppItems
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:recipient,
|
|
8
|
+
:whatsapp_message_id,
|
|
9
|
+
:status,
|
|
10
|
+
:whatsapp_account_id,
|
|
11
|
+
:from,
|
|
12
|
+
:template_id,
|
|
13
|
+
:date_from,
|
|
14
|
+
:date_to,
|
|
15
|
+
:page,
|
|
16
|
+
:limit,
|
|
17
|
+
:whatsapp_item_id
|
|
18
|
+
|
|
19
|
+
def initialize(client = Mailersend::Client.new)
|
|
20
|
+
@client = client
|
|
21
|
+
@recipient = recipient
|
|
22
|
+
@whatsapp_message_id = whatsapp_message_id
|
|
23
|
+
@status = status
|
|
24
|
+
@whatsapp_account_id = whatsapp_account_id
|
|
25
|
+
@from = from
|
|
26
|
+
@template_id = template_id
|
|
27
|
+
@date_from = date_from
|
|
28
|
+
@date_to = date_to
|
|
29
|
+
@page = page
|
|
30
|
+
@limit = limit
|
|
31
|
+
@whatsapp_item_id = whatsapp_item_id
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def list(recipient: nil, whatsapp_message_id: nil, status: nil, whatsapp_account_id: nil, from: nil,
|
|
35
|
+
template_id: nil, date_from: nil, date_to: nil, page: nil, limit: nil)
|
|
36
|
+
hash = {
|
|
37
|
+
'recipient' => recipient,
|
|
38
|
+
'whatsapp_message_id' => whatsapp_message_id,
|
|
39
|
+
'status[]' => status,
|
|
40
|
+
'whatsapp_account_id' => whatsapp_account_id,
|
|
41
|
+
'from' => from,
|
|
42
|
+
'template_id' => template_id,
|
|
43
|
+
'date_from' => date_from,
|
|
44
|
+
'date_to' => date_to,
|
|
45
|
+
'page' => page,
|
|
46
|
+
'limit' => limit
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/items',
|
|
50
|
+
query: URI.encode_www_form(hash.compact)))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def get(whatsapp_item_id:)
|
|
54
|
+
client.http.get("#{MAILERSEND_API_URL}/whatsapp/items/#{whatsapp_item_id}")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Messages endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppMessages
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:whatsapp_account_id,
|
|
8
|
+
:from,
|
|
9
|
+
:template_id,
|
|
10
|
+
:date_from,
|
|
11
|
+
:date_to,
|
|
12
|
+
:page,
|
|
13
|
+
:limit,
|
|
14
|
+
:whatsapp_message_id
|
|
15
|
+
|
|
16
|
+
def initialize(client = Mailersend::Client.new)
|
|
17
|
+
@client = client
|
|
18
|
+
@whatsapp_account_id = whatsapp_account_id
|
|
19
|
+
@from = from
|
|
20
|
+
@template_id = template_id
|
|
21
|
+
@date_from = date_from
|
|
22
|
+
@date_to = date_to
|
|
23
|
+
@page = page
|
|
24
|
+
@limit = limit
|
|
25
|
+
@whatsapp_message_id = whatsapp_message_id
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def list(whatsapp_account_id: nil, from: nil, template_id: nil, date_from: nil, date_to: nil, page: nil, limit: nil)
|
|
29
|
+
hash = {
|
|
30
|
+
'whatsapp_account_id' => whatsapp_account_id,
|
|
31
|
+
'from' => from,
|
|
32
|
+
'template_id' => template_id,
|
|
33
|
+
'date_from' => date_from,
|
|
34
|
+
'date_to' => date_to,
|
|
35
|
+
'page' => page,
|
|
36
|
+
'limit' => limit
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/messages',
|
|
40
|
+
query: URI.encode_www_form(hash.compact)))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get(whatsapp_message_id:)
|
|
44
|
+
client.http.get("#{MAILERSEND_API_URL}/whatsapp/messages/#{whatsapp_message_id}")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Recipient endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppRecipient
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:status,
|
|
8
|
+
:phone_number,
|
|
9
|
+
:page,
|
|
10
|
+
:limit,
|
|
11
|
+
:whatsapp_recipient_id
|
|
12
|
+
|
|
13
|
+
def initialize(client = Mailersend::Client.new)
|
|
14
|
+
@client = client
|
|
15
|
+
@status = status
|
|
16
|
+
@phone_number = phone_number
|
|
17
|
+
@page = page
|
|
18
|
+
@limit = limit
|
|
19
|
+
@whatsapp_recipient_id = whatsapp_recipient_id
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def list(status: nil, phone_number: nil, page: nil, limit: nil)
|
|
23
|
+
hash = {
|
|
24
|
+
'status' => status,
|
|
25
|
+
'phone_number' => phone_number,
|
|
26
|
+
'page' => page,
|
|
27
|
+
'limit' => limit
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/recipients',
|
|
31
|
+
query: URI.encode_www_form(hash.compact)))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get(whatsapp_recipient_id:)
|
|
35
|
+
client.http.get("#{MAILERSEND_API_URL}/whatsapp/recipients/#{whatsapp_recipient_id}")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailersend
|
|
4
|
+
# WhatsApp Templates endpoint from MailerSend API.
|
|
5
|
+
class WhatsAppTemplates
|
|
6
|
+
attr_accessor :client,
|
|
7
|
+
:whatsapp_account_id,
|
|
8
|
+
:status,
|
|
9
|
+
:category,
|
|
10
|
+
:language,
|
|
11
|
+
:page,
|
|
12
|
+
:limit,
|
|
13
|
+
:whatsapp_template_id
|
|
14
|
+
|
|
15
|
+
def initialize(client = Mailersend::Client.new)
|
|
16
|
+
@client = client
|
|
17
|
+
@whatsapp_account_id = whatsapp_account_id
|
|
18
|
+
@status = status
|
|
19
|
+
@category = category
|
|
20
|
+
@language = language
|
|
21
|
+
@page = page
|
|
22
|
+
@limit = limit
|
|
23
|
+
@whatsapp_template_id = whatsapp_template_id
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def list(whatsapp_account_id: nil, status: nil, category: nil, language: nil, page: nil, limit: nil)
|
|
27
|
+
hash = {
|
|
28
|
+
'whatsapp_account_id' => whatsapp_account_id,
|
|
29
|
+
'status' => status,
|
|
30
|
+
'category' => category,
|
|
31
|
+
'language' => language,
|
|
32
|
+
'page' => page,
|
|
33
|
+
'limit' => limit
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: '/v1/whatsapp/templates',
|
|
37
|
+
query: URI.encode_www_form(hash.compact)))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get(whatsapp_template_id:)
|
|
41
|
+
client.http.get("#{MAILERSEND_API_URL}/whatsapp/templates/#{whatsapp_template_id}")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/mailersend.rb
CHANGED
|
@@ -10,12 +10,20 @@ require_relative 'mailersend/dmarc_monitoring/dmarc_monitoring'
|
|
|
10
10
|
require_relative 'mailersend/domains/domains'
|
|
11
11
|
require_relative 'mailersend/email/email'
|
|
12
12
|
require_relative 'mailersend/email_verification/email_verification'
|
|
13
|
+
require_relative 'mailersend/emails/emails'
|
|
13
14
|
require_relative 'mailersend/inbound_routing/inbound_routing'
|
|
14
15
|
require_relative 'mailersend/messages/messages'
|
|
15
16
|
require_relative 'mailersend/recipients/recipients'
|
|
16
17
|
require_relative 'mailersend/scheduled_messages/scheduled_messages'
|
|
17
18
|
require_relative 'mailersend/sender_identity/sender_identity'
|
|
18
19
|
require_relative 'mailersend/sms/sms'
|
|
20
|
+
require_relative 'mailersend/whatsapp/whatsapp'
|
|
21
|
+
require_relative 'mailersend/whatsapp_messages/whatsapp_messages'
|
|
22
|
+
require_relative 'mailersend/whatsapp_items/whatsapp_items'
|
|
23
|
+
require_relative 'mailersend/whatsapp_activities/whatsapp_activities'
|
|
24
|
+
require_relative 'mailersend/whatsapp_inbound_messages/whatsapp_inbound_messages'
|
|
25
|
+
require_relative 'mailersend/whatsapp_recipient/whatsapp_recipient'
|
|
26
|
+
require_relative 'mailersend/whatsapp_templates/whatsapp_templates'
|
|
19
27
|
require_relative 'mailersend/sms_activity/sms_activity'
|
|
20
28
|
require_relative 'mailersend/sms_messages/sms_messages'
|
|
21
29
|
require_relative 'mailersend/sms_number/sms_number'
|
data/mailersend-ruby.gemspec
CHANGED
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
|
|
21
21
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
22
22
|
spec.metadata['source_code_uri'] = 'https://github.com/mailersend/mailersend-ruby'
|
|
23
|
-
spec.metadata['changelog_uri'] = 'https://github.com/mailersend/mailersend-ruby/
|
|
23
|
+
spec.metadata['changelog_uri'] = 'https://github.com/mailersend/mailersend-ruby/releases'
|
|
24
24
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
25
25
|
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0")
|
data/spec/email_rspec.rb
CHANGED
|
@@ -26,4 +26,19 @@ RSpec.describe Mailersend::Email do
|
|
|
26
26
|
expect(response.status).to eq(202)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
+
|
|
30
|
+
it 'includes the language in the request body when set' do
|
|
31
|
+
# Cassette is matched on the request body, so this passes only when
|
|
32
|
+
# the serialized payload contains the language field.
|
|
33
|
+
VCR.use_cassette('email/email_send_template_language', match_requests_on: %i[method uri body]) do
|
|
34
|
+
email.from = { 'email' => 'sender@test-sdk.com', 'name' => 'Sender' }
|
|
35
|
+
email.recipients = [{ 'email' => 'test@mailerlite.com', 'name' => 'Test' }]
|
|
36
|
+
email.subject = 'Test Email'
|
|
37
|
+
email.add_template_id('123abc')
|
|
38
|
+
email.add_language('de')
|
|
39
|
+
|
|
40
|
+
response = email.send
|
|
41
|
+
expect(response.status).to eq(202)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
29
44
|
end
|