mailganer-client 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50c26307907b4bef90ebe1b4daa6ffd346d0f6004388bda060ec6a2e3a13d723
4
- data.tar.gz: 5b0d78aebd7f2d8e4b4b01822de2152535cbf777b9142dba3188192642ca5ff7
3
+ metadata.gz: 9d70d0b9baaa83780ba084df26a10b57f20774deb16f64ce9deb20ba5d08f70b
4
+ data.tar.gz: a2bf3c7cb83d9ac09f4535647fcf253a76bfe817d9cdb66f80434ce119b83b93
5
5
  SHA512:
6
- metadata.gz: 8bf65344a758e33f61c58b91af7c91e2ce678be97504c07fe4151e8c5484376971b5a5966811d04603df18590359049718f14eb2e23945ced487e230ac48e5b1
7
- data.tar.gz: 72ea6ddee8baefc7979edd9cf576bcb9d1a49052ec082ce4d0a68d3a646d3503eee377888f086415ff3a8b4ff45190e2b8302487967099038e4d704dd54bc752
6
+ metadata.gz: cfa5af60fc010e9d814b2a7d40fb04a65fe1bb87da3da89cfb763d3794ab09ad1ff30237dd9e82cb81d8f616054388b05f449db9d16a8c412ecc4609023cf701
7
+ data.tar.gz: 58cc68eb15e70e2a08cee7c2b5ec0d793048cc5e02bfeca7796e967db02462e920f40311c142c5fdc582e94f9f781e5f797474e730e03a7a4306d0d55ade0335
data/README.md CHANGED
@@ -30,9 +30,9 @@ gem install mailganer-client
30
30
  require "mailganer_client"
31
31
 
32
32
  MailganerClient.configure do |config|
33
- config.api_key: "your-smtp-api-key",
34
- config.smtp_login: "xxx",
35
- config.api_key_web_portal: "your-web-portal-api-key"
33
+ config.api_key = "your-smtp-api-key",
34
+ config.smtp_login = "xxx",
35
+ config.api_key_web_portal = "your-web-portal-api-key"
36
36
  end
37
37
 
38
38
  client = MailganerClient.new
@@ -0,0 +1,403 @@
1
+ # frozen_string_literal: true
2
+ require "net/http"
3
+ require "uri"
4
+ require "json"
5
+
6
+ module MailganerClient
7
+ class Client
8
+ ##
9
+ # Initializes API client
10
+ #
11
+ # @param api_key [String] SMTP API key for sending
12
+ # @param smtp_login [String] SMTP login
13
+ # @param api_key_web_portal [String] API key for web portal
14
+ # @param debug [Boolean] enable HTTP debug logging
15
+ # @param host [String] base API URL
16
+ #
17
+
18
+ def initialize(
19
+ api_key: MailganerClient.configuration&.api_key,
20
+ smtp_login: MailganerClient.configuration&.smtp_login,
21
+ api_key_web_portal: MailganerClient.configuration&.api_key_web_portal,
22
+ host: MailganerClient.configuration&.host || "https://api.samotpravil.ru/",
23
+ debug: MailganerClient.configuration&.debug || false
24
+ )
25
+ @api_key = api_key
26
+ @api_key_web_portal = api_key_web_portal
27
+ @host = host.chomp('/') + '/'
28
+ @smtp_login = smtp_login
29
+ @debug = debug
30
+ end
31
+
32
+ private
33
+
34
+ ##
35
+ # Executes a HTTP request
36
+ #
37
+ # @param method [String] HTTP method (GET/POST)
38
+ # @param endpoint [String] API endpoint
39
+ # @param data [Hash,nil] request body
40
+ # @param without_content_type [Boolean] remove Content-Type header
41
+ #
42
+ # @return [Hash] parsed JSON response
43
+ # @raise [ApiError] if API returns an error
44
+ #
45
+
46
+ def request(method, endpoint, data = nil, without_content_type = false)
47
+ uri = URI.join(@host, endpoint)
48
+
49
+ if (method.upcase == 'GET' && data)
50
+ uri.query = URI.encode_www_form(data)
51
+ end
52
+
53
+ http = Net::HTTP.new(uri.host, uri.port)
54
+ http.use_ssl = uri.scheme == 'https'
55
+ http.read_timeout = 10
56
+
57
+ req = case method.upcase
58
+ when 'GET' then Net::HTTP::Get.new(uri)
59
+ when 'POST' then Net::HTTP::Post.new(uri)
60
+ else raise ApiError, "Unsupported method #{method}"
61
+ end
62
+
63
+ if !without_content_type
64
+ req['Content-Type'] = 'application/json'
65
+ end
66
+ req['Authorization'] = @api_key
67
+ req['Mg-Api-Key'] = @api_key_web_portal
68
+
69
+ req.body = data.to_json if data
70
+
71
+ if (@debug)
72
+ puts "==== HTTP DEBUG ===="
73
+ puts "Method: #{method.upcase}"
74
+ puts "URL: #{uri}"
75
+ puts "Headers: #{req.each_header.to_h}"
76
+ puts "Body: #{req.body}" if req.body
77
+ puts "==================="
78
+ end
79
+
80
+ begin
81
+ res = http.request(req)
82
+ rescue Timeout::Error
83
+ raise ApiError, 'Request timed out'
84
+ rescue SocketError => e
85
+ raise ApiError, e&.message
86
+ end
87
+
88
+ json = JSON.parse(res.body, symbolize_names: true)
89
+
90
+ unless res.code.to_i == 200 && json[:status].to_s.downcase == "ok"
91
+ message = json[:message] || "API error"
92
+
93
+ if message.include?("550 bounced check filter")
94
+ raise StopListError, message
95
+ elsif message.include?("from domain not trusted")
96
+ raise DomainNotTrustedError, message
97
+ elsif res.code.to_i == 403
98
+ raise AuthorizationError, message
99
+ elsif res.code.to_i == 400
100
+ raise BadRequestError, message
101
+ else
102
+ raise ApiError, message
103
+ end
104
+ end
105
+
106
+ json
107
+ end
108
+
109
+ ##
110
+ # Validates email format
111
+ #
112
+ # @param email [String]
113
+ # @raise [ApiError] if invalid
114
+ #
115
+
116
+ def validate_email!(email)
117
+ raise ApiError, 'Invalid email' unless email =~ URI::MailTo::EMAIL_REGEXP
118
+ end
119
+
120
+ public
121
+
122
+ ##
123
+ # Sends a simple email
124
+ #
125
+ # @param to [String] recipient email
126
+ # @param subject [String] subject line
127
+ # @param body [String,nil] message body
128
+ # @param from [String] sender email
129
+ # @param name_from [String,nil] sender name
130
+ # @param params [Hash,nil] template params
131
+ #
132
+ # @return [Hash]
133
+ #
134
+
135
+ def send_email(to:, subject:, body: nil, from:, name_from: nil, params: nil)
136
+ validate_email!(to)
137
+ validate_email!(from)
138
+
139
+ data = {
140
+ email_to: to,
141
+ subject: subject,
142
+ params: params,
143
+ message_text: body,
144
+ email_from: name_from ? "#{name_from} <#{from}>" : from,
145
+ }
146
+ request('POST', 'api/v2/mail/send', data)
147
+ end
148
+
149
+ ##
150
+ # Sends email using SMTP v1 (template or raw body)
151
+ #
152
+ # @param type [String] "template" or "body"
153
+ # @param to [String]
154
+ # @param subject [String]
155
+ # @param body [String,nil]
156
+ # @param from [String]
157
+ # @param name_from [String,nil]
158
+ # @param template_id [Integer,nil]
159
+ # @param params [Hash,nil]
160
+ # @param attach_files [Array]
161
+ #
162
+ def send_email_smtp_v1(type:, to:, subject:, body: nil, from:, name_from: nil, template_id: nil, params: nil, attach_files: [])
163
+ validate_email!(to)
164
+ validate_email!(from)
165
+
166
+ data = {
167
+ email_to: to,
168
+ subject: subject,
169
+ params: params,
170
+ check_local_stop_list: true,
171
+ track_open: true,
172
+ track_click: true,
173
+ email_from: name_from ? "#{name_from} <#{from}>" : from,
174
+ attach_files: attach_files,
175
+ x_track_id: "#{@smtp_login}-#{Time.now.to_i}-#{SecureRandom.hex(6)}",
176
+ }
177
+
178
+ case type
179
+ when 'template'
180
+ data[:template_id] = template_id
181
+ when 'body'
182
+ data[:message_text] = body
183
+ else
184
+ raise ApiError, "Unsupported type #{type}; select type = template or type = body"
185
+ end
186
+
187
+ request('POST', "api/v1/smtp_send?key=#{@api_key}", data)
188
+ end
189
+
190
+ ##
191
+ # Sends a bulk email package
192
+ #
193
+ # @param users [Array<Hash>] recipient data
194
+ # @param subject [String]
195
+ # @param body [String]
196
+ # @param from [String]
197
+ # @param name_from [String,nil]
198
+ #
199
+ def send_emails_package(users:, subject:, body:, from:, name_from: nil)
200
+ validate_email!(from)
201
+
202
+ # "users": [
203
+ # {
204
+ # "emailto": "to1@domain.com", // Имейл получателя
205
+ # "name": "Вася", // любые переменные
206
+ # "field1": "400",
207
+ # "products": [
208
+ # {
209
+ # "name":"foo1",
210
+ # "price":"bar1",
211
+ # "link":"baz1"
212
+ # },
213
+ # {
214
+ # "name":"foo2",
215
+ # "price":"bar2",
216
+ # "link":"baz2"
217
+ # }
218
+ # ] // пример вложенного массива
219
+ # },
220
+ # {
221
+ # "emailto": "to2@domain.com",
222
+ # "string_array": [
223
+ # {"name": "foo1"},
224
+ # {"name": "foo2"}
225
+ # ] // пример массива строк
226
+ # },
227
+ # {
228
+ # ...
229
+ # }
230
+ # ] // массив с получателями
231
+
232
+ data = {
233
+ email_from: from,
234
+ name_from: name_from,
235
+ subject: subject,
236
+ check_local_stop_list: true,
237
+ track_open: true,
238
+ track_click: true,
239
+ message_text: body,
240
+ users: users
241
+ }
242
+
243
+ request('POST', "api/v1/add_json_package?key=#{@api_key}", data)
244
+ end
245
+
246
+ ##
247
+ # Stops a bulk email package
248
+ #
249
+ # @param pack_id [Integer]
250
+ #
251
+ def stop_emails_package(pack_id:)
252
+ params = { key: @api_key, pack_id: pack_id }
253
+ request('GET', "api/v1/package_stop", params)
254
+ end
255
+
256
+
257
+ ##
258
+ # Gets status of a bulk package
259
+ #
260
+ # @param pack_id [Integer]
261
+ #
262
+ def status_emails_package(pack_id:)
263
+ params = { issuen: pack_id}
264
+ request('GET', "api/v2/package/status", params)
265
+ end
266
+
267
+ ##
268
+ # Gets delivery status of a specific message
269
+ #
270
+ # @param email [String,nil]
271
+ # @param x_track_id [String,nil]
272
+ # @param message_id [String,nil]
273
+ #
274
+ def status_email_delivery(email: nil, x_track_id: nil, message_id: nil)
275
+ params = { email: email, x_track_id: x_track_id, message_id: message_id }.compact
276
+ request('GET', "api/v2/issue/status", params)
277
+ end
278
+
279
+ ##
280
+ # Retrieves statistics
281
+ #
282
+ # @param date_from [String]
283
+ # @param date_to [String]
284
+ # @param limit [Integer]
285
+ # @param cursor_next [String,nil]
286
+ # @param timestamp_from [Integer,nil]
287
+ # @param timestamp_to [Integer,nil]
288
+ #
289
+ def get_statistics(date_from:, date_to:, limit: 100, cursor_next: nil, timestamp_from: nil, timestamp_to: nil)
290
+ #?date_from=2023-11-01&date_to=2023-11-07
291
+ #?timestamp_from=1706795600&timestamp_to=1706831999&
292
+ params = {
293
+ date_from: date_from,
294
+ date_to: date_to,
295
+ limit: limit,
296
+ cursor_next: cursor_next,
297
+ }
298
+
299
+ if timestamp_from && timestamp_to
300
+ params[:timestamp_from] = timestamp_from
301
+ params[:timestamp_to] = timestamp_to
302
+ elsif date_from && date_to
303
+ params[:date_from] = date_from
304
+ params[:date_to] = date_to
305
+ end
306
+
307
+ params.compact!
308
+ request('GET', "api/v2/issue/statistics", params)
309
+ end
310
+
311
+
312
+ ##
313
+ # Non-delivered emails by date
314
+ #
315
+ def get_non_delivery_by_date(date_from:, date_to:, limit: 5, cursor_next: nil, order: nil)
316
+ params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next, order: order }.compact
317
+ request('GET', "api/v2/blist/report/non-delivery", params)
318
+ end
319
+
320
+ ##
321
+ # Non-delivered emails by issue
322
+ #
323
+ def get_non_delivery_by_issue(issue:, limit: 5, cursor_next: nil, order: nil)
324
+ params = { issuen: issue, limit: limit, cursor_next: cursor_next, order: order }.compact
325
+ request('GET', "api/v2/issue/report/non-delivery", params)
326
+ end
327
+
328
+ ##
329
+ # FBL (abuse complaints) by date
330
+ #
331
+ def get_fbl_report_by_date(date_from:, date_to:, limit: 5, cursor_next: nil)
332
+ params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next }.compact
333
+ request('GET', "api/v2/blist/report/fbl", params)
334
+ end
335
+
336
+ ##
337
+ # FBL (abuse complaints) by issue
338
+ #
339
+ def get_fbl_report_by_issue(issue:, limit: 5, cursor_next: nil)
340
+ params = { issuen: issue, limit: limit, cursor_next: cursor_next }.compact
341
+ request('GET', "api/v2/issue/report/fbl?", params)
342
+ end
343
+
344
+ ##
345
+ # Searches email in stop-list
346
+ #
347
+ # @param email [String]
348
+ #
349
+ def stop_list_search(email:)
350
+ validate_email!(email)
351
+ request('GET', 'api/v2/stop-list/search', { email: email })
352
+ end
353
+
354
+ ##
355
+ # Adds email to stop-list
356
+ #
357
+ def stop_list_add(email:, mail_from:)
358
+ validate_email!(email)
359
+ request('POST', "api/v2/stop-list/add?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true)
360
+ end
361
+
362
+ ##
363
+ # Removes email from stop-list
364
+ #
365
+ def stop_list_remove(email:, mail_from:)
366
+ validate_email!(email)
367
+ request('POST', "api/v2/stop-list/remove?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true)
368
+ end
369
+
370
+
371
+ ##
372
+ # Checks domain verification status
373
+ #
374
+ def domain_check_verification(domain:,client_name:)
375
+ request('POST',"api/v2/blist/domains/verify", {domain: domain, client: client_name})
376
+ end
377
+
378
+ ##
379
+ # Adds domain
380
+ #
381
+ def domains_add(domain:)
382
+ params = { domain: domain }
383
+ request('POST',"api/v2/blist/domains/add", params)
384
+ end
385
+
386
+ ##
387
+ # Removes domain
388
+ #
389
+ def domains_remove(domain:)
390
+ params = { domain: domain }
391
+ request('POST', "api/v2/blist/domains/remove", params)
392
+ end
393
+
394
+ ##
395
+ # Lists all domains
396
+ #
397
+ # @return [Hash]
398
+ #
399
+ def domains_list
400
+ request('GET', "api/v2/blist/domains")
401
+ end
402
+ end
403
+ end
@@ -0,0 +1,10 @@
1
+ module MailganerClient
2
+ class Configuration
3
+ attr_accessor :api_key, :smtp_login, :api_key_web_portal, :host, :debug
4
+
5
+ def initialize
6
+ @debug = false
7
+ @host = "https://api.samotpravil.ru/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module MailganerClient
3
+ class ApiError < StandardError
4
+ attr_reader :code, :body
5
+ end
6
+ class StopListError < ApiError; end
7
+ class DomainNotTrustedError < ApiError; end
8
+ class AuthorizationError < ApiError; end
9
+ class BadRequestError < ApiError; end
10
+ end
@@ -0,0 +1,3 @@
1
+ module MailganerClient
2
+ VERSION = "0.1.3"
3
+ end
@@ -1,36 +1,9 @@
1
- # frozen_string_literal: true
2
- require "net/http"
3
- require "uri"
4
- require "json"
5
-
6
- ##
7
- # Client for interacting with the Mailganer API.
8
- #
9
- # Provides sending emails, bulk mailing, stop-list operations,
10
- # statistics, domain management, and delivery status checks.
11
- #
12
- # @example Sending a simple email
13
- # client = MailganerClient.new(
14
- # api_key: "...",
15
- # smtp_login: "...",
16
- # api_key_web_portal: "..."
17
- # )
18
- # client.send_email(
19
- # to: "user@example.com",
20
- # subject: "Hello",
21
- # body: "Email body",
22
- # from: "sender@example.com"
23
- #
24
- class MailganerClient
25
- class ApiError < StandardError
26
- attr_reader :code, :body
27
- end
28
- class StopListError < ApiError; end
29
- class DomainNotTrustedError < ApiError; end
30
- class AuthorizationError < ApiError; end
31
- class BadRequestError < ApiError; end
32
-
1
+ require_relative "mailganer_client/version"
2
+ require_relative "mailganer_client/errors"
3
+ require_relative "mailganer_client/client"
4
+ require_relative "mailganer_client/configuration"
33
5
 
6
+ module MailganerClient
34
7
  class << self
35
8
  attr_accessor :configuration
36
9
  end
@@ -39,403 +12,4 @@ class MailganerClient
39
12
  self.configuration ||= Configuration.new
40
13
  yield(configuration)
41
14
  end
42
-
43
- class Configuration
44
- attr_accessor :api_key, :smtp_login, :api_key_web_portal, :host, :debug
45
- end
46
-
47
- ##
48
- # Initializes API client
49
- #
50
- # @param api_key [String] SMTP API key for sending
51
- # @param smtp_login [String] SMTP login
52
- # @param api_key_web_portal [String] API key for web portal
53
- # @param debug [Boolean] enable HTTP debug logging
54
- # @param host [String] base API URL
55
- #
56
-
57
- def initialize(
58
- api_key: MailganerClient.configuration&.api_key,
59
- smtp_login: MailganerClient.configuration&.smtp_login,
60
- api_key_web_portal: MailganerClient.configuration&.api_key_web_portal,
61
- host: MailganerClient.configuration&.host || "https://api.samotpravil.ru/",
62
- debug: MailganerClient.configuration&.debug || false
63
- )
64
- @api_key = api_key
65
- @api_key_web_portal = api_key_web_portal
66
- @host = host.chomp('/') + '/'
67
- @smtp_login = smtp_login
68
- @debug = debug
69
- end
70
-
71
- private
72
-
73
- ##
74
- # Executes a HTTP request
75
- #
76
- # @param method [String] HTTP method (GET/POST)
77
- # @param endpoint [String] API endpoint
78
- # @param data [Hash,nil] request body
79
- # @param without_content_type [Boolean] remove Content-Type header
80
- #
81
- # @return [Hash] parsed JSON response
82
- # @raise [ApiError] if API returns an error
83
- #
84
-
85
- def request(method, endpoint, data = nil, without_content_type = false)
86
- uri = URI.join(@host, endpoint)
87
-
88
- if (method.upcase == 'GET' && data)
89
- uri.query = URI.encode_www_form(data)
90
- end
91
-
92
- http = Net::HTTP.new(uri.host, uri.port)
93
- http.use_ssl = uri.scheme == 'https'
94
- http.read_timeout = 10
95
-
96
- req = case method.upcase
97
- when 'GET' then Net::HTTP::Get.new(uri)
98
- when 'POST' then Net::HTTP::Post.new(uri)
99
- else raise ApiError, "Unsupported method #{method}"
100
- end
101
-
102
- if !without_content_type
103
- req['Content-Type'] = 'application/json'
104
- end
105
- req['Authorization'] = @api_key
106
- req['Mg-Api-Key'] = @api_key_web_portal
107
-
108
- req.body = data.to_json if data
109
-
110
- if (@debug)
111
- puts "==== HTTP DEBUG ===="
112
- puts "Method: #{method.upcase}"
113
- puts "URL: #{uri}"
114
- puts "Headers: #{req.each_header.to_h}"
115
- puts "Body: #{req.body}" if req.body
116
- puts "==================="
117
- end
118
-
119
- begin
120
- res = http.request(req)
121
- rescue Timeout::Error
122
- raise ApiError, 'Request timed out'
123
- rescue SocketError => e
124
- raise ApiError, e&.message
125
- end
126
-
127
- json = JSON.parse(res.body, symbolize_names: true)
128
-
129
- unless res.code.to_i == 200 && json[:status].to_s.downcase == "ok"
130
- message = json[:message] || "API error"
131
-
132
- if message.include?("550 bounced check filter")
133
- raise StopListError, message
134
- elsif message.include?("from domain not trusted")
135
- raise DomainNotTrustedError, message
136
- elsif res.code.to_i == 403
137
- raise AuthorizationError, message
138
- elsif res.code.to_i == 400
139
- raise BadRequestError, message
140
- else
141
- raise ApiError, message
142
- end
143
- end
144
-
145
- json
146
- end
147
-
148
- ##
149
- # Validates email format
150
- #
151
- # @param email [String]
152
- # @raise [ApiError] if invalid
153
- #
154
-
155
- def validate_email!(email)
156
- raise ApiError, 'Invalid email' unless email =~ URI::MailTo::EMAIL_REGEXP
157
- end
158
-
159
- public
160
-
161
- ##
162
- # Sends a simple email
163
- #
164
- # @param to [String] recipient email
165
- # @param subject [String] subject line
166
- # @param body [String,nil] message body
167
- # @param from [String] sender email
168
- # @param name_from [String,nil] sender name
169
- # @param params [Hash,nil] template params
170
- #
171
- # @return [Hash]
172
- #
173
-
174
- def send_email(to:, subject:, body: nil, from:, name_from: nil, params: nil)
175
- validate_email!(to)
176
- validate_email!(from)
177
-
178
- data = {
179
- email_to: to,
180
- subject: subject,
181
- params: params,
182
- message_text: body,
183
- email_from: name_from ? "#{name_from} <#{from}>" : from,
184
- }
185
- request('POST', 'api/v2/mail/send', data)
186
- end
187
-
188
- ##
189
- # Sends email using SMTP v1 (template or raw body)
190
- #
191
- # @param type [String] "template" or "body"
192
- # @param to [String]
193
- # @param subject [String]
194
- # @param body [String,nil]
195
- # @param from [String]
196
- # @param name_from [String,nil]
197
- # @param template_id [Integer,nil]
198
- # @param params [Hash,nil]
199
- # @param attach_files [Array]
200
- #
201
- def send_email_smtp_v1(type:, to:, subject:, body: nil, from:, name_from: nil, template_id: nil, params: nil, attach_files: [])
202
- validate_email!(to)
203
- validate_email!(from)
204
-
205
- data = {
206
- email_to: to,
207
- subject: subject,
208
- params: params,
209
- check_local_stop_list: true,
210
- track_open: true,
211
- track_click: true,
212
- email_from: name_from ? "#{name_from} <#{from}>" : from,
213
- attach_files: attach_files,
214
- x_track_id: "#{@smtp_login}-#{Time.now.to_i}-#{SecureRandom.hex(6)}",
215
- }
216
-
217
- case type
218
- when 'template'
219
- data[:template_id] = template_id
220
- when 'body'
221
- data[:message_text] = body
222
- else
223
- raise ApiError, "Unsupported type #{type}; select type = template or type = body"
224
- end
225
-
226
- request('POST', "api/v1/smtp_send?key=#{@api_key}", data)
227
- end
228
-
229
- ##
230
- # Sends a bulk email package
231
- #
232
- # @param users [Array<Hash>] recipient data
233
- # @param subject [String]
234
- # @param body [String]
235
- # @param from [String]
236
- # @param name_from [String,nil]
237
- #
238
- def send_emails_package(users:, subject:, body:, from:, name_from: nil)
239
- validate_email!(from)
240
-
241
- # "users": [
242
- # {
243
- # "emailto": "to1@domain.com", // Имейл получателя
244
- # "name": "Вася", // любые переменные
245
- # "field1": "400",
246
- # "products": [
247
- # {
248
- # "name":"foo1",
249
- # "price":"bar1",
250
- # "link":"baz1"
251
- # },
252
- # {
253
- # "name":"foo2",
254
- # "price":"bar2",
255
- # "link":"baz2"
256
- # }
257
- # ] // пример вложенного массива
258
- # },
259
- # {
260
- # "emailto": "to2@domain.com",
261
- # "string_array": [
262
- # {"name": "foo1"},
263
- # {"name": "foo2"}
264
- # ] // пример массива строк
265
- # },
266
- # {
267
- # ...
268
- # }
269
- # ] // массив с получателями
270
-
271
- data = {
272
- email_from: from,
273
- name_from: name_from,
274
- subject: subject,
275
- check_local_stop_list: true,
276
- track_open: true,
277
- track_click: true,
278
- message_text: body,
279
- users: users
280
- }
281
-
282
- request('POST', "api/v1/add_json_package?key=#{@api_key}", data)
283
- end
284
-
285
- ##
286
- # Stops a bulk email package
287
- #
288
- # @param pack_id [Integer]
289
- #
290
- def stop_emails_package(pack_id:)
291
- params = { key: @api_key, pack_id: pack_id }
292
- request('GET', "api/v1/package_stop", params)
293
- end
294
-
295
-
296
- ##
297
- # Gets status of a bulk package
298
- #
299
- # @param pack_id [Integer]
300
- #
301
- def status_emails_package(pack_id:)
302
- params = { issuen: pack_id}
303
- request('GET', "api/v2/package/status", params)
304
- end
305
-
306
- ##
307
- # Gets delivery status of a specific message
308
- #
309
- # @param email [String,nil]
310
- # @param x_track_id [String,nil]
311
- # @param message_id [String,nil]
312
- #
313
- def status_email_delivery(email: nil, x_track_id: nil, message_id: nil)
314
- params = { email: email, x_track_id: x_track_id, message_id: message_id }.compact
315
- request('GET', "api/v2/issue/status", params)
316
- end
317
-
318
- ##
319
- # Retrieves statistics
320
- #
321
- # @param date_from [String]
322
- # @param date_to [String]
323
- # @param limit [Integer]
324
- # @param cursor_next [String,nil]
325
- # @param timestamp_from [Integer,nil]
326
- # @param timestamp_to [Integer,nil]
327
- #
328
- def get_statistics(date_from:, date_to:, limit: 100, cursor_next: nil, timestamp_from: nil, timestamp_to: nil)
329
- #?date_from=2023-11-01&date_to=2023-11-07
330
- #?timestamp_from=1706795600&timestamp_to=1706831999&
331
- params = {
332
- date_from: date_from,
333
- date_to: date_to,
334
- limit: limit,
335
- cursor_next: cursor_next,
336
- }
337
-
338
- if timestamp_from.present? && timestamp_to.present?
339
- params[:timestamp_from] = timestamp_from
340
- params[:timestamp_to] = timestamp_to
341
- elsif date_from.present? && date_to.present?
342
- params[:date_from] = date_from
343
- params[:date_to] = date_to
344
- end
345
-
346
- params.compact!
347
- request('GET', "api/v2/issue/statistics", params)
348
- end
349
-
350
-
351
- ##
352
- # Non-delivered emails by date
353
- #
354
- def get_non_delivery_by_date(date_from:, date_to:, limit: 5, cursor_next: nil, order: nil)
355
- params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next, order: order }.compact
356
- request('GET', "api/v2/blist/report/non-delivery", params)
357
- end
358
-
359
- ##
360
- # Non-delivered emails by issue
361
- #
362
- def get_non_delivery_by_issue(issue:, limit: 5, cursor_next: nil, order: nil)
363
- params = { issuen: issue, limit: limit, cursor_next: cursor_next, order: order }.compact
364
- request('GET', "api/v2/issue/report/non-delivery", params)
365
- end
366
-
367
- ##
368
- # FBL (abuse complaints) by date
369
- #
370
- def get_fbl_report_by_date(date_from:, date_to:, limit: 5, cursor_next: nil)
371
- params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next }.compact
372
- request('GET', "api/v2/blist/report/fbl", params)
373
- end
374
-
375
- ##
376
- # FBL (abuse complaints) by issue
377
- #
378
- def get_fbl_report_by_issue(issue:, limit: 5, cursor_next: nil)
379
- params = { issuen: issue, limit: limit, cursor_next: cursor_next }.compact
380
- request('GET', "api/v2/issue/report/fbl?", params)
381
- end
382
-
383
- ##
384
- # Searches email in stop-list
385
- #
386
- # @param email [String]
387
- #
388
- def stop_list_search(email:)
389
- validate_email!(email)
390
- request('GET', 'api/v2/stop-list/search', { email: email })
391
- end
392
-
393
- ##
394
- # Adds email to stop-list
395
- #
396
- def stop_list_add(email:, mail_from:)
397
- validate_email!(email)
398
- request('POST', "api/v2/stop-list/add?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true)
399
- end
400
-
401
- ##
402
- # Removes email from stop-list
403
- #
404
- def stop_list_remove(email:, mail_from:)
405
- validate_email!(email)
406
- request('POST', "api/v2/stop-list/remove?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true)
407
- end
408
-
409
-
410
- ##
411
- # Checks domain verification status
412
- #
413
- def domain_check_verification(domain:,client_name:)
414
- request('POST',"api/v2/blist/domains/verify", {domain: domain, client: client_name})
415
- end
416
-
417
- ##
418
- # Adds domain
419
- #
420
- def domains_add(domain:)
421
- params = { domain: domain }
422
- request('POST',"api/v2/blist/domains/add", params)
423
- end
424
-
425
- ##
426
- # Removes domain
427
- #
428
- def domains_remove(domain:)
429
- params = { domain: domain }
430
- request('POST', "api/v2/blist/domains/remove", params)
431
- end
432
-
433
- ##
434
- # Lists all domains
435
- #
436
- # @return [Hash]
437
- #
438
- def domains_list
439
- request('GET', "api/v2/blist/domains")
440
- end
441
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailganer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yetisamurai
@@ -48,6 +48,10 @@ extra_rdoc_files:
48
48
  files:
49
49
  - README.md
50
50
  - lib/mailganer_client.rb
51
+ - lib/mailganer_client/client.rb
52
+ - lib/mailganer_client/configuration.rb
53
+ - lib/mailganer_client/errors.rb
54
+ - lib/mailganer_client/version.rb
51
55
  homepage: https://github.com/yetisamurai/mailganer_client
52
56
  licenses:
53
57
  - CC0-1.0