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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +2 -0
  3. data/.github/workflows/main.yml +1 -1
  4. data/.github/workflows/publish_gem.yml +17 -14
  5. data/.gitignore +2 -1
  6. data/.vesnik.yaml +36 -0
  7. data/README.md +423 -0
  8. data/fixtures/email/email_send_template_language.yml +56 -0
  9. data/fixtures/emails/emails_list_emails.yml +35 -0
  10. data/fixtures/emails/emails_list_emails_empty_page.yml +35 -0
  11. data/fixtures/emails/emails_single_email.yml +35 -0
  12. data/fixtures/whatsapp/whatsapp_send.yml +47 -0
  13. data/fixtures/whatsapp/whatsapp_send_multiple_recipients.yml +47 -0
  14. data/fixtures/whatsapp/whatsapp_send_personalization.yml +47 -0
  15. data/fixtures/whatsapp_activities/whatsapp_activities_list.yml +43 -0
  16. data/fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_get.yml +43 -0
  17. data/fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_list.yml +43 -0
  18. data/fixtures/whatsapp_items/whatsapp_items_get.yml +43 -0
  19. data/fixtures/whatsapp_items/whatsapp_items_list.yml +43 -0
  20. data/fixtures/whatsapp_messages/whatsapp_messages_get.yml +43 -0
  21. data/fixtures/whatsapp_messages/whatsapp_messages_list.yml +43 -0
  22. data/fixtures/whatsapp_recipient/whatsapp_recipient_get.yml +43 -0
  23. data/fixtures/whatsapp_recipient/whatsapp_recipient_list.yml +43 -0
  24. data/fixtures/whatsapp_templates/whatsapp_templates_get.yml +43 -0
  25. data/fixtures/whatsapp_templates/whatsapp_templates_list.yml +43 -0
  26. data/flake.lock +49 -0
  27. data/flake.nix +31 -0
  28. data/justfile +56 -0
  29. data/lefthook.yml +14 -0
  30. data/lib/mailersend/email/email.rb +10 -0
  31. data/lib/mailersend/emails/emails.rb +44 -0
  32. data/lib/mailersend/version.rb +1 -1
  33. data/lib/mailersend/whatsapp/whatsapp.rb +47 -0
  34. data/lib/mailersend/whatsapp_activities/whatsapp_activities.rb +45 -0
  35. data/lib/mailersend/whatsapp_inbound_messages/whatsapp_inbound_messages.rb +47 -0
  36. data/lib/mailersend/whatsapp_items/whatsapp_items.rb +57 -0
  37. data/lib/mailersend/whatsapp_messages/whatsapp_messages.rb +47 -0
  38. data/lib/mailersend/whatsapp_recipient/whatsapp_recipient.rb +38 -0
  39. data/lib/mailersend/whatsapp_templates/whatsapp_templates.rb +44 -0
  40. data/lib/mailersend.rb +8 -0
  41. data/mailersend-ruby.gemspec +1 -1
  42. data/spec/email_rspec.rb +15 -0
  43. data/spec/emails_rspec.rb +175 -0
  44. data/spec/whatsapp_activities_rspec.rb +38 -0
  45. data/spec/whatsapp_inbound_messages_rspec.rb +49 -0
  46. data/spec/whatsapp_items_rspec.rb +52 -0
  47. data/spec/whatsapp_messages_rspec.rb +50 -0
  48. data/spec/whatsapp_recipient_rspec.rb +40 -0
  49. data/spec/whatsapp_rspec.rb +65 -0
  50. data/spec/whatsapp_templates_rspec.rb +48 -0
  51. metadata +47 -5
  52. data/CHANGELOG.md +0 -148
@@ -0,0 +1,175 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::Emails do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:emails) { Mailersend::Emails.new(client) }
16
+
17
+ # The three required arguments, reused by every example.
18
+ let(:domain_id) { 'jpzkmgq7e5vl059v' }
19
+ let(:date_from) { 1_756_252_800 }
20
+ let(:date_to) { 1_756_339_200 }
21
+
22
+ describe '#list' do
23
+ # VCR matches on method + URI, so the `uri:` recorded in the cassette is itself the
24
+ # assertion that `list` hits `v1/emails` with domain_id, date_from, date_to, limit and page.
25
+ it 'returns a list of emails' do
26
+ VCR.use_cassette('emails/emails_list_emails', match_requests_on: %i[method uri]) do
27
+ response = emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to, page: 1, limit: 10)
28
+ parsed_response = JSON.parse(response.body)
29
+
30
+ expect(response.status).to eq(200)
31
+ expect(parsed_response['data']).to be_an(Array)
32
+
33
+ email = parsed_response['data'].first
34
+
35
+ expect(email['id']).to eq('6a8fa9b1902fab56e0ce50dd')
36
+ expect(email['from']).to eq('sender@example.com')
37
+ expect(email['to']).to eq('rcpt@example.org')
38
+ expect(email['status']).to eq('sent')
39
+ expect(email['tags']).to eq(['newsletter'])
40
+ expect(email['interaction']).to eq(['opened'])
41
+ expect(email['suppression_reason']).to be_nil
42
+ expect(email['headers']).to eq([{ 'name' => 'X-Custom', 'value' => 'foo' }])
43
+
44
+ # List rows never carry content — it is only returned by `single`.
45
+ expect(email['text']).to be_nil
46
+ expect(email['html']).to be_nil
47
+
48
+ expect(parsed_response['links']['first']).to eq('https://api.mailersend.com/v1/emails?page=1')
49
+ expect(parsed_response['links']['last']).to be_nil
50
+ expect(parsed_response['meta']['current_page']).to eq(1)
51
+ expect(parsed_response['meta']['per_page']).to eq(10)
52
+ end
53
+ end
54
+
55
+ it 'returns an empty page past the end of the result set' do
56
+ VCR.use_cassette('emails/emails_list_emails_empty_page', match_requests_on: %i[method uri]) do
57
+ response = emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to, page: 2, limit: 10)
58
+ parsed_response = JSON.parse(response.body)
59
+
60
+ expect(response.status).to eq(200)
61
+ expect(parsed_response['data']).to eq([])
62
+ expect(parsed_response['links']['prev']).to eq('https://api.mailersend.com/v1/emails?page=1')
63
+ expect(parsed_response['links']['next']).to be_nil
64
+ expect(parsed_response['meta']['current_page']).to eq(2)
65
+ expect(parsed_response['meta']['from']).to be_nil
66
+ expect(parsed_response['meta']['to']).to be_nil
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#single' do
72
+ # The path is singular (`v1/email/{id}`) while `list` is plural (`v1/emails`); the cassette
73
+ # URI pins that difference.
74
+ it 'returns a single email with its recipient and activity' do
75
+ VCR.use_cassette('emails/emails_single_email', match_requests_on: %i[method uri]) do
76
+ response = emails.single(email_id: '6a8fa9b1902fab56e0ce50dd')
77
+ parsed_response = JSON.parse(response.body)
78
+
79
+ expect(response.status).to eq(200)
80
+ expect(parsed_response['data']).to be_a(Hash)
81
+ expect(parsed_response['data']['id']).to eq('6a8fa9b1902fab56e0ce50dd')
82
+
83
+ # `single` adds content, the recipient object and the activity array on top of a list row.
84
+ expect(parsed_response['data']['text']).to eq('Welcome aboard.')
85
+ expect(parsed_response['data']['html']).to eq('<p>Welcome aboard.</p>')
86
+ expect(parsed_response['data']['recipient']).to be_a(Hash)
87
+ expect(parsed_response['data']['recipient']['email']).to eq('rcpt@example.org')
88
+
89
+ activity = parsed_response['data']['activity']
90
+
91
+ expect(activity).to be_an(Array)
92
+ expect(activity.length).to eq(3)
93
+ expect(activity.first).to include('id', 'type', 'created_at')
94
+ expect(activity.first['type']).to eq('opened')
95
+ expect(activity.map { |event| event['type'] }).to eq(%w[opened delivered sent])
96
+ end
97
+ end
98
+ end
99
+
100
+ # These examples assert the URI the SDK builds rather than replaying a cassette, because query
101
+ # serialization is the contract that matters most here: the API rejects a scalar `status` or
102
+ # `interaction` with 422, so both must go out as repeated `status[]` / `interaction[]` params and
103
+ # never as a single comma-joined value.
104
+ describe 'query serialization' do
105
+ let(:http) { double('http') }
106
+ let(:requested_urls) { [] }
107
+
108
+ before do
109
+ allow(client).to receive(:http).and_return(http)
110
+ allow(http).to receive(:get) { |url| requested_urls << url.to_s }
111
+ end
112
+
113
+ it 'sends status and interaction as repeated array params' do
114
+ emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to, limit: 10, page: 1,
115
+ status: %w[sent delivered], interaction: %w[opened clicked])
116
+
117
+ expect(requested_urls.last).to eq(
118
+ 'https://api.mailersend.com/v1/emails' \
119
+ '?domain_id=jpzkmgq7e5vl059v&date_from=1756252800&date_to=1756339200&limit=10&page=1' \
120
+ '&status%5B%5D=sent&status%5B%5D=delivered' \
121
+ '&interaction%5B%5D=opened&interaction%5B%5D=clicked'
122
+ )
123
+
124
+ # One key per value, and no comma-joined value anywhere (%2C is an encoded comma).
125
+ expect(requested_urls.last.scan('status%5B%5D=').length).to eq(2)
126
+ expect(requested_urls.last.scan('interaction%5B%5D=').length).to eq(2)
127
+ expect(requested_urls.last).not_to include('%2C')
128
+ end
129
+
130
+ it 'sends a scalar status and interaction in array form too' do
131
+ emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to,
132
+ status: 'sent', interaction: 'opened')
133
+
134
+ expect(requested_urls.last).to eq(
135
+ 'https://api.mailersend.com/v1/emails' \
136
+ '?domain_id=jpzkmgq7e5vl059v&date_from=1756252800&date_to=1756339200' \
137
+ '&status%5B%5D=sent&interaction%5B%5D=opened'
138
+ )
139
+ end
140
+
141
+ it 'includes every optional filter when set' do
142
+ emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to, limit: 25, page: 2,
143
+ status: %w[sent], interaction: %w[opened], recipient_email: 'rcpt@example.org',
144
+ message_id: '6a8fa9b1902fab56e0ce50aa', template_id: '7nxe3yjmeq28vp0k',
145
+ subject: 'Welcome', tag: 'newsletter')
146
+
147
+ expect(requested_urls.last).to eq(
148
+ 'https://api.mailersend.com/v1/emails' \
149
+ '?domain_id=jpzkmgq7e5vl059v&date_from=1756252800&date_to=1756339200&limit=25&page=2' \
150
+ '&status%5B%5D=sent&interaction%5B%5D=opened' \
151
+ '&recipient_email=rcpt%40example.org&message_id=6a8fa9b1902fab56e0ce50aa' \
152
+ '&template_id=7nxe3yjmeq28vp0k&subject=Welcome&tag=newsletter'
153
+ )
154
+ end
155
+
156
+ it 'omits every optional filter that is nil' do
157
+ emails.list(domain_id: domain_id, date_from: date_from, date_to: date_to)
158
+
159
+ expect(requested_urls.last).to eq(
160
+ 'https://api.mailersend.com/v1/emails?domain_id=jpzkmgq7e5vl059v&date_from=1756252800&date_to=1756339200'
161
+ )
162
+
163
+ %w[limit page status interaction recipient_email message_id template_id subject tag].each do |param|
164
+ expect(requested_urls.last).not_to include(param)
165
+ end
166
+ end
167
+
168
+ it 'requests the singular v1/email/{id} path for a single email' do
169
+ emails.single(email_id: '6a8fa9b1902fab56e0ce50dd')
170
+
171
+ expect(requested_urls.last).to eq('https://api.mailersend.com/v1/email/6a8fa9b1902fab56e0ce50dd')
172
+ expect(requested_urls.last).not_to include('/v1/emails/')
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,38 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppActivities do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_activities) { Mailersend::WhatsAppActivities.new(client) }
16
+
17
+ it 'returns a list of WhatsApp activities' do
18
+ VCR.use_cassette('whatsapp_activities/whatsapp_activities_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_activities.list(
20
+ whatsapp_item_id: '67f91abe2202f3705540234a',
21
+ whatsapp_message_id: '67f91abd69f79df391e9d78d',
22
+ recipient: '48600000001',
23
+ type: %w[delivered read],
24
+ date_from: 1_791_936_000,
25
+ date_to: 1_792_022_400,
26
+ page: 1,
27
+ limit: 25
28
+ )
29
+ parsed_response = JSON.parse(response.body)
30
+
31
+ expect(response.status).to eq(200)
32
+ expect(parsed_response['data']).to be_an(Array)
33
+ expect(parsed_response['data'].map { |activity| activity['type'] }).to eq(%w[read delivered])
34
+ expect(parsed_response['links']['last']).to be_nil
35
+ expect(parsed_response['meta']).not_to have_key('total')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppInboundMessages do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_inbound_messages) { Mailersend::WhatsAppInboundMessages.new(client) }
16
+
17
+ it 'returns a list of WhatsApp inbound messages' do
18
+ VCR.use_cassette('whatsapp_inbound_messages/whatsapp_inbound_messages_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_inbound_messages.list(
20
+ whatsapp_account_id: '3enl6x27wmrxrl2v',
21
+ from: '48600000001',
22
+ type: %w[text image],
23
+ date_from: 1_790_000_000,
24
+ date_to: 1_790_086_400,
25
+ page: 1,
26
+ limit: 25
27
+ )
28
+ parsed_response = JSON.parse(response.body)
29
+
30
+ expect(response.status).to eq(200)
31
+ expect(parsed_response['data']).to be_an(Array)
32
+ expect(parsed_response['data'][0]['meta']['body']).to eq('Hello, I would like to check my order status.')
33
+ expect(parsed_response['data'][1]).not_to have_key('context')
34
+ expect(parsed_response['links']['last']).to be_nil
35
+ expect(parsed_response['meta']).not_to have_key('total')
36
+ end
37
+ end
38
+
39
+ it 'returns a single WhatsApp inbound message' do
40
+ VCR.use_cassette('whatsapp_inbound_messages/whatsapp_inbound_messages_get') do
41
+ response = whatsapp_inbound_messages.get(whatsapp_inbound_message_id: '62f114a3165fe0d8db0288d1')
42
+ parsed_response = JSON.parse(response.body)
43
+
44
+ expect(response.status).to eq(200)
45
+ expect(parsed_response['data']['meta']['reply_type']).to eq('list_reply')
46
+ expect(parsed_response['data']['context']['message_id']).to start_with('wamid.')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,52 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppItems do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_items) { Mailersend::WhatsAppItems.new(client) }
16
+
17
+ it 'returns a list of WhatsApp items' do
18
+ VCR.use_cassette('whatsapp_items/whatsapp_items_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_items.list(
20
+ recipient: '48600000002',
21
+ whatsapp_message_id: '67f91abd69f79df391e9d78d',
22
+ status: %w[failed read],
23
+ whatsapp_account_id: '3enl6x27wmrxrl2v',
24
+ from: '15550001234',
25
+ template_id: '23zxk54v6gjy6v7m',
26
+ date_from: 1_791_936_000,
27
+ date_to: 1_792_022_400,
28
+ page: 1,
29
+ limit: 25
30
+ )
31
+ parsed_response = JSON.parse(response.body)
32
+
33
+ expect(response.status).to eq(200)
34
+ expect(parsed_response['data']).to be_an(Array)
35
+ expect(parsed_response['data'][0]['status']).to eq('failed')
36
+ expect(parsed_response['data'][0]['error_code']).to eq(131_026)
37
+ expect(parsed_response['links']['last']).to be_nil
38
+ expect(parsed_response['meta']).not_to have_key('total')
39
+ end
40
+ end
41
+
42
+ it 'returns a single WhatsApp item' do
43
+ VCR.use_cassette('whatsapp_items/whatsapp_items_get') do
44
+ response = whatsapp_items.get(whatsapp_item_id: '67f91abe2202f3705540234a')
45
+ parsed_response = JSON.parse(response.body)
46
+
47
+ expect(response.status).to eq(200)
48
+ expect(parsed_response['data']['recipient']['id']).to eq('67f91abe2202f37055402301')
49
+ expect(parsed_response['data']['activity'].map { |activity| activity['type'] }).to eq(%w[queued sent delivered read])
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppMessages do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_messages) { Mailersend::WhatsAppMessages.new(client) }
16
+
17
+ it 'returns a list of WhatsApp messages' do
18
+ VCR.use_cassette('whatsapp_messages/whatsapp_messages_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_messages.list(
20
+ whatsapp_account_id: '3enl6x27wmrxrl2v',
21
+ from: '15550001234',
22
+ template_id: '23zxk54v6gjy6v7m',
23
+ date_from: 1_791_936_000,
24
+ date_to: 1_792_022_400,
25
+ page: 1,
26
+ limit: 25
27
+ )
28
+ parsed_response = JSON.parse(response.body)
29
+
30
+ expect(response.status).to eq(200)
31
+ expect(parsed_response['data']).to be_an(Array)
32
+ expect(parsed_response['data'][0]['to']).to eq(%w[48600000001 48600000002])
33
+ expect(parsed_response['data'][0]).not_to have_key('items')
34
+ expect(parsed_response['links']['last']).to be_nil
35
+ expect(parsed_response['meta']).not_to have_key('total')
36
+ expect(parsed_response['meta']).not_to have_key('last_page')
37
+ end
38
+ end
39
+
40
+ it 'returns a single WhatsApp message' do
41
+ VCR.use_cassette('whatsapp_messages/whatsapp_messages_get') do
42
+ response = whatsapp_messages.get(whatsapp_message_id: '67f91abd69f79df391e9d78d')
43
+ parsed_response = JSON.parse(response.body)
44
+
45
+ expect(response.status).to eq(200)
46
+ expect(parsed_response['data']['items']).to be_an(Array)
47
+ expect(parsed_response['data']['items'].map { |item| item['status'] }).to eq(%w[read failed])
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppRecipient do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_recipient) { Mailersend::WhatsAppRecipient.new(client) }
16
+
17
+ it 'returns a list of WhatsApp recipients' do
18
+ VCR.use_cassette('whatsapp_recipient/whatsapp_recipient_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_recipient.list(status: 'active', phone_number: '48600000001', page: 1, limit: 25)
20
+ parsed_response = JSON.parse(response.body)
21
+
22
+ expect(response.status).to eq(200)
23
+ expect(parsed_response['data']).to be_an(Array)
24
+ expect(parsed_response['data'][0]).not_to have_key('bsuid')
25
+ expect(parsed_response['links']['last']).to be_nil
26
+ expect(parsed_response['meta']).not_to have_key('total')
27
+ end
28
+ end
29
+
30
+ it 'returns a single WhatsApp recipient' do
31
+ VCR.use_cassette('whatsapp_recipient/whatsapp_recipient_get') do
32
+ response = whatsapp_recipient.get(whatsapp_recipient_id: '67f91abe2202f37055402301')
33
+ parsed_response = JSON.parse(response.body)
34
+
35
+ expect(response.status).to eq(200)
36
+ expect(parsed_response['data']['items']).to be_an(Array)
37
+ expect(parsed_response['data']['items'][0]['whatsapp_message_id']).to eq('67f91abd69f79df391e9d78d')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,65 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsApp do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp) { Mailersend::WhatsApp.new(client) }
16
+
17
+ it 'sends a WhatsApp message' do
18
+ VCR.use_cassette('whatsapp/whatsapp_send') do
19
+ whatsapp.add_from('15550001234')
20
+ whatsapp.add_to('+48600000001')
21
+ whatsapp.add_template_id('23zxk54v6gjy6v7m')
22
+
23
+ response = whatsapp.send
24
+ parsed_response = JSON.parse(response.body)
25
+
26
+ expect(response.status).to eq(202)
27
+ expect(parsed_response['data']['id']).to eq('67f91abd69f79df391e9d78d')
28
+ end
29
+ end
30
+
31
+ it 'includes the personalization in the request body when set' do
32
+ # Cassette is matched on the request body, so this passes only when
33
+ # the serialized payload contains the personalization field.
34
+ VCR.use_cassette('whatsapp/whatsapp_send_personalization', match_requests_on: %i[method uri body]) do
35
+ whatsapp.add_from('15550001234')
36
+ whatsapp.add_to('+48600000001')
37
+ whatsapp.add_template_id('23zxk54v6gjy6v7m')
38
+ whatsapp.add_personalization(
39
+ {
40
+ 'to' => '+48600000001',
41
+ 'data' => {
42
+ 'header' => ['Order #12345'],
43
+ 'body' => ['John', 'December 31, 2026'],
44
+ 'buttons' => ['orders/12345']
45
+ }
46
+ }
47
+ )
48
+
49
+ response = whatsapp.send
50
+ expect(response.status).to eq(202)
51
+ end
52
+ end
53
+
54
+ it 'sends to multiple recipients' do
55
+ VCR.use_cassette('whatsapp/whatsapp_send_multiple_recipients', match_requests_on: %i[method uri body]) do
56
+ whatsapp.add_from('15550001234')
57
+ whatsapp.add_to('+48600000001')
58
+ whatsapp.add_to('+48600000002')
59
+ whatsapp.add_template_id('23zxk54v6gjy6v7m')
60
+
61
+ response = whatsapp.send
62
+ expect(response.status).to eq(202)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,48 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'json'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = './fixtures'
7
+ config.hook_into :webmock
8
+ config.filter_sensitive_data('<AUTH>') do |interaction|
9
+ interaction.request.headers['Authorization'][0]
10
+ end
11
+ end
12
+
13
+ RSpec.describe Mailersend::WhatsAppTemplates do
14
+ let(:client) { Mailersend::Client.new(API_TOKEN) }
15
+ let(:whatsapp_templates) { Mailersend::WhatsAppTemplates.new(client) }
16
+
17
+ it 'returns a list of WhatsApp templates' do
18
+ VCR.use_cassette('whatsapp_templates/whatsapp_templates_list', match_requests_on: %i[method host path query]) do
19
+ response = whatsapp_templates.list(
20
+ whatsapp_account_id: '3enl6x27wmrxrl2v',
21
+ status: 'approved',
22
+ category: 'UTILITY',
23
+ language: 'en_US',
24
+ page: 1,
25
+ limit: 25
26
+ )
27
+ parsed_response = JSON.parse(response.body)
28
+
29
+ expect(response.status).to eq(200)
30
+ expect(parsed_response['data']).to be_an(Array)
31
+ expect(parsed_response['data'][1]['components']['header']).to be_nil
32
+ expect(parsed_response['links']['last']).to be_nil
33
+ expect(parsed_response['meta']).not_to have_key('total')
34
+ end
35
+ end
36
+
37
+ it 'returns a single WhatsApp template' do
38
+ VCR.use_cassette('whatsapp_templates/whatsapp_templates_get') do
39
+ response = whatsapp_templates.get(whatsapp_template_id: '23zxk54v6gjy6v7m')
40
+ parsed_response = JSON.parse(response.body)
41
+
42
+ expect(response.status).to eq(200)
43
+ expect(parsed_response['data']['name']).to eq('order_confirmation')
44
+ expect(parsed_response['data']['components']['header']).to eq({ 'format' => 'TEXT', 'text' => '{{1}}' })
45
+ expect(parsed_response['data']['components']['buttons'][0]['url']).to eq('https://shop.example.com/{{1}}')
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailersend-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikola Milojević
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-19 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: http
@@ -62,13 +63,14 @@ extensions: []
62
63
  extra_rdoc_files: []
63
64
  files:
64
65
  - ".env.example"
66
+ - ".envrc"
65
67
  - ".github/CODEOWNERS"
66
68
  - ".github/workflows/main.yml"
67
69
  - ".github/workflows/publish_gem.yml"
68
70
  - ".gitignore"
69
71
  - ".rspec"
70
72
  - ".rubocop.yml"
71
- - CHANGELOG.md
73
+ - ".vesnik.yaml"
72
74
  - Gemfile
73
75
  - LICENSE.txt
74
76
  - README.md
@@ -97,6 +99,10 @@ files:
97
99
  - fixtures/domains/domains_single.yml
98
100
  - fixtures/domains/domains_verify.yml
99
101
  - fixtures/email/email_send.yml
102
+ - fixtures/email/email_send_template_language.yml
103
+ - fixtures/emails/emails_list_emails.yml
104
+ - fixtures/emails/emails_list_emails_empty_page.yml
105
+ - fixtures/emails/emails_single_email.yml
100
106
  - fixtures/inbound_routing/inbound_routing_delete.yml
101
107
  - fixtures/inbound_routing/inbound_routing_list.yml
102
108
  - fixtures/inbound_routing/inbound_routing_single.yml
@@ -149,6 +155,24 @@ files:
149
155
  - fixtures/webhooks/webhooks_delete.yml
150
156
  - fixtures/webhooks/webhooks_list.yml
151
157
  - fixtures/webhooks/webhooks_single.yml
158
+ - fixtures/whatsapp/whatsapp_send.yml
159
+ - fixtures/whatsapp/whatsapp_send_multiple_recipients.yml
160
+ - fixtures/whatsapp/whatsapp_send_personalization.yml
161
+ - fixtures/whatsapp_activities/whatsapp_activities_list.yml
162
+ - fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_get.yml
163
+ - fixtures/whatsapp_inbound_messages/whatsapp_inbound_messages_list.yml
164
+ - fixtures/whatsapp_items/whatsapp_items_get.yml
165
+ - fixtures/whatsapp_items/whatsapp_items_list.yml
166
+ - fixtures/whatsapp_messages/whatsapp_messages_get.yml
167
+ - fixtures/whatsapp_messages/whatsapp_messages_list.yml
168
+ - fixtures/whatsapp_recipient/whatsapp_recipient_get.yml
169
+ - fixtures/whatsapp_recipient/whatsapp_recipient_list.yml
170
+ - fixtures/whatsapp_templates/whatsapp_templates_get.yml
171
+ - fixtures/whatsapp_templates/whatsapp_templates_list.yml
172
+ - flake.lock
173
+ - flake.nix
174
+ - justfile
175
+ - lefthook.yml
152
176
  - lib/mailersend-ruby.rb
153
177
  - lib/mailersend.rb
154
178
  - lib/mailersend/activity/activity.rb
@@ -160,6 +184,7 @@ files:
160
184
  - lib/mailersend/domains/domains.rb
161
185
  - lib/mailersend/email/email.rb
162
186
  - lib/mailersend/email_verification/email_verification.rb
187
+ - lib/mailersend/emails/emails.rb
163
188
  - lib/mailersend/inbound_routing/inbound_routing.rb
164
189
  - lib/mailersend/messages/messages.rb
165
190
  - lib/mailersend/recipients/recipients.rb
@@ -177,6 +202,13 @@ files:
177
202
  - lib/mailersend/tokens/tokens.rb
178
203
  - lib/mailersend/version.rb
179
204
  - lib/mailersend/webhooks/webhooks.rb
205
+ - lib/mailersend/whatsapp/whatsapp.rb
206
+ - lib/mailersend/whatsapp_activities/whatsapp_activities.rb
207
+ - lib/mailersend/whatsapp_inbound_messages/whatsapp_inbound_messages.rb
208
+ - lib/mailersend/whatsapp_items/whatsapp_items.rb
209
+ - lib/mailersend/whatsapp_messages/whatsapp_messages.rb
210
+ - lib/mailersend/whatsapp_recipient/whatsapp_recipient.rb
211
+ - lib/mailersend/whatsapp_templates/whatsapp_templates.rb
180
212
  - mailersend-ruby.gemspec
181
213
  - renovate.json
182
214
  - spec/activity_rspec.rb
@@ -185,6 +217,7 @@ files:
185
217
  - spec/dmarc_monitoring_rspec.rb
186
218
  - spec/domains_rspec.rb
187
219
  - spec/email_rspec.rb
220
+ - spec/emails_rspec.rb
188
221
  - spec/inbound_routing_rspec.rb
189
222
  - spec/messages_rspec.rb
190
223
  - spec/recipients_rspec.rb
@@ -200,6 +233,13 @@ files:
200
233
  - spec/templates_rspec.rb
201
234
  - spec/tokens_rspec.rb
202
235
  - spec/webhooks_rspec.rb
236
+ - spec/whatsapp_activities_rspec.rb
237
+ - spec/whatsapp_inbound_messages_rspec.rb
238
+ - spec/whatsapp_items_rspec.rb
239
+ - spec/whatsapp_messages_rspec.rb
240
+ - spec/whatsapp_recipient_rspec.rb
241
+ - spec/whatsapp_rspec.rb
242
+ - spec/whatsapp_templates_rspec.rb
203
243
  homepage: https://www.mailersend.com
204
244
  licenses:
205
245
  - MIT
@@ -207,8 +247,9 @@ metadata:
207
247
  allowed_push_host: https://rubygems.org
208
248
  homepage_uri: https://www.mailersend.com
209
249
  source_code_uri: https://github.com/mailersend/mailersend-ruby
210
- changelog_uri: https://github.com/mailersend/mailersend-ruby/blob/main/CHANGELOG.md
250
+ changelog_uri: https://github.com/mailersend/mailersend-ruby/releases
211
251
  rubygems_mfa_required: 'true'
252
+ post_install_message:
212
253
  rdoc_options: []
213
254
  require_paths:
214
255
  - lib
@@ -223,7 +264,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
264
  - !ruby/object:Gem::Version
224
265
  version: '0'
225
266
  requirements: []
226
- rubygems_version: 3.6.9
267
+ rubygems_version: 3.3.27
268
+ signing_key:
227
269
  specification_version: 4
228
270
  summary: MailerSend's official Ruby SDK
229
271
  test_files: []