Class: MailganerClient::Client
- Inherits:
-
Object
- Object
- MailganerClient::Client
- Defined in:
- lib/mailganer_client/client.rb
Instance Method Summary collapse
-
#domain_check_verification(domain:, client_name:) ⇒ Object
Checks domain verification status.
-
#domains_add(domain:) ⇒ Object
Adds domain.
-
#domains_list ⇒ Hash
Lists all domains.
-
#domains_remove(domain:) ⇒ Object
Removes domain.
-
#get_fbl_report_by_date(date_from:, date_to:, limit: 5, cursor_next: nil) ⇒ Object
FBL (abuse complaints) by date.
-
#get_fbl_report_by_issue(issue:, limit: 5, cursor_next: nil) ⇒ Object
FBL (abuse complaints) by issue.
-
#get_non_delivery_by_date(date_from:, date_to:, limit: 5, cursor_next: nil, order: nil) ⇒ Object
Non-delivered emails by date.
-
#get_non_delivery_by_issue(issue:, limit: 5, cursor_next: nil, order: nil) ⇒ Object
Non-delivered emails by issue.
-
#get_statistics(date_from:, date_to:, limit: 100, cursor_next: nil, timestamp_from: nil, timestamp_to: nil) ⇒ Object
Retrieves statistics.
-
#initialize(api_key: MailganerClient.configuration&.api_key, smtp_login: MailganerClient.configuration&.smtp_login, api_key_web_portal: MailganerClient.configuration&.api_key_web_portal, host: MailganerClient.configuration&.host || "https://api.samotpravil.ru/", debug: MailganerClient.configuration&.debug || false) ⇒ Client
constructor
Initializes API client.
-
#send_email(to:, subject:, body: nil, from:, name_from: nil, params: nil) ⇒ Hash
Sends a simple email.
-
#send_email_smtp_v1(type:, to:, subject:, body: nil, from:, name_from: nil, template_id: nil, params: nil, attach_files: []) ⇒ Object
Sends email using SMTP v1 (template or raw body).
-
#send_emails_package(users:, subject:, body:, from:, name_from: nil) ⇒ Object
Sends a bulk email package.
-
#status_email_delivery(email: nil, x_track_id: nil, message_id: nil) ⇒ Object
Gets delivery status of a specific message.
-
#status_emails_package(pack_id:) ⇒ Object
Gets status of a bulk package.
-
#stop_emails_package(pack_id:) ⇒ Object
Stops a bulk email package.
-
#stop_list_add(email:, mail_from:) ⇒ Object
Adds email to stop-list.
-
#stop_list_remove(email:, mail_from:) ⇒ Object
Removes email from stop-list.
-
#stop_list_search(email:) ⇒ Object
Searches email in stop-list.
Constructor Details
#initialize(api_key: MailganerClient.configuration&.api_key, smtp_login: MailganerClient.configuration&.smtp_login, api_key_web_portal: MailganerClient.configuration&.api_key_web_portal, host: MailganerClient.configuration&.host || "https://api.samotpravil.ru/", debug: MailganerClient.configuration&.debug || false) ⇒ Client
Initializes API client
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mailganer_client/client.rb', line 18 def initialize( api_key: MailganerClient.configuration&.api_key, smtp_login: MailganerClient.configuration&.smtp_login, api_key_web_portal: MailganerClient.configuration&.api_key_web_portal, host: MailganerClient.configuration&.host || "https://api.samotpravil.ru/", debug: MailganerClient.configuration&.debug || false ) @api_key = api_key @api_key_web_portal = api_key_web_portal @host = host.chomp('/') + '/' @smtp_login = smtp_login @debug = debug end |
Instance Method Details
#domain_check_verification(domain:, client_name:) ⇒ Object
Checks domain verification status
374 375 376 |
# File 'lib/mailganer_client/client.rb', line 374 def domain_check_verification(domain:,client_name:) request('POST',"api/v2/blist/domains/verify", {domain: domain, client: client_name}) end |
#domains_add(domain:) ⇒ Object
Adds domain
381 382 383 384 |
# File 'lib/mailganer_client/client.rb', line 381 def domains_add(domain:) params = { domain: domain } request('POST',"api/v2/blist/domains/add", params) end |
#domains_list ⇒ Hash
Lists all domains
399 400 401 |
# File 'lib/mailganer_client/client.rb', line 399 def domains_list request('GET', "api/v2/blist/domains") end |
#domains_remove(domain:) ⇒ Object
Removes domain
389 390 391 392 |
# File 'lib/mailganer_client/client.rb', line 389 def domains_remove(domain:) params = { domain: domain } request('POST', "api/v2/blist/domains/remove", params) end |
#get_fbl_report_by_date(date_from:, date_to:, limit: 5, cursor_next: nil) ⇒ Object
FBL (abuse complaints) by date
331 332 333 334 |
# File 'lib/mailganer_client/client.rb', line 331 def get_fbl_report_by_date(date_from:, date_to:, limit: 5, cursor_next: nil) params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next }.compact request('GET', "api/v2/blist/report/fbl", params) end |
#get_fbl_report_by_issue(issue:, limit: 5, cursor_next: nil) ⇒ Object
FBL (abuse complaints) by issue
339 340 341 342 |
# File 'lib/mailganer_client/client.rb', line 339 def get_fbl_report_by_issue(issue:, limit: 5, cursor_next: nil) params = { issuen: issue, limit: limit, cursor_next: cursor_next }.compact request('GET', "api/v2/issue/report/fbl?", params) end |
#get_non_delivery_by_date(date_from:, date_to:, limit: 5, cursor_next: nil, order: nil) ⇒ Object
Non-delivered emails by date
315 316 317 318 |
# File 'lib/mailganer_client/client.rb', line 315 def get_non_delivery_by_date(date_from:, date_to:, limit: 5, cursor_next: nil, order: nil) params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next, order: order }.compact request('GET', "api/v2/blist/report/non-delivery", params) end |
#get_non_delivery_by_issue(issue:, limit: 5, cursor_next: nil, order: nil) ⇒ Object
Non-delivered emails by issue
323 324 325 326 |
# File 'lib/mailganer_client/client.rb', line 323 def get_non_delivery_by_issue(issue:, limit: 5, cursor_next: nil, order: nil) params = { issuen: issue, limit: limit, cursor_next: cursor_next, order: order }.compact request('GET', "api/v2/issue/report/non-delivery", params) end |
#get_statistics(date_from:, date_to:, limit: 100, cursor_next: nil, timestamp_from: nil, timestamp_to: nil) ⇒ Object
Retrieves statistics
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/mailganer_client/client.rb', line 289 def get_statistics(date_from:, date_to:, limit: 100, cursor_next: nil, timestamp_from: nil, timestamp_to: nil) #?date_from=2023-11-01&date_to=2023-11-07 #?timestamp_from=1706795600×tamp_to=1706831999& params = { date_from: date_from, date_to: date_to, limit: limit, cursor_next: cursor_next, } if && params[:timestamp_from] = params[:timestamp_to] = elsif date_from && date_to params[:date_from] = date_from params[:date_to] = date_to end params.compact! request('GET', "api/v2/issue/statistics", params) end |
#send_email(to:, subject:, body: nil, from:, name_from: nil, params: nil) ⇒ Hash
Sends a simple email
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/mailganer_client/client.rb', line 135 def send_email(to:, subject:, body: nil, from:, name_from: nil, params: nil) validate_email!(to) validate_email!(from) data = { email_to: to, subject: subject, params: params, message_text: body, email_from: name_from ? "#{name_from} <#{from}>" : from, } request('POST', 'api/v2/mail/send', data) end |
#send_email_smtp_v1(type:, to:, subject:, body: nil, from:, name_from: nil, template_id: nil, params: nil, attach_files: []) ⇒ Object
Sends email using SMTP v1 (template or raw body)
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/mailganer_client/client.rb', line 162 def send_email_smtp_v1(type:, to:, subject:, body: nil, from:, name_from: nil, template_id: nil, params: nil, attach_files: []) validate_email!(to) validate_email!(from) data = { email_to: to, subject: subject, params: params, check_local_stop_list: true, track_open: true, track_click: true, email_from: name_from ? "#{name_from} <#{from}>" : from, attach_files: attach_files, x_track_id: "#{@smtp_login}-#{Time.now.to_i}-#{SecureRandom.hex(6)}", } case type when 'template' data[:template_id] = template_id when 'body' data[:message_text] = body else raise ApiError, "Unsupported type #{type}; select type = template or type = body" end request('POST', "api/v1/smtp_send?key=#{@api_key}", data) end |
#send_emails_package(users:, subject:, body:, from:, name_from: nil) ⇒ Object
Sends a bulk email package
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/mailganer_client/client.rb', line 199 def send_emails_package(users:, subject:, body:, from:, name_from: nil) validate_email!(from) # "users": [ # { # "emailto": "[email protected]", // Имейл получателя # "name": "Вася", // любые переменные # "field1": "400", # "products": [ # { # "name":"foo1", # "price":"bar1", # "link":"baz1" # }, # { # "name":"foo2", # "price":"bar2", # "link":"baz2" # } # ] // пример вложенного массива # }, # { # "emailto": "[email protected]", # "string_array": [ # {"name": "foo1"}, # {"name": "foo2"} # ] // пример массива строк # }, # { # ... # } # ] // массив с получателями data = { email_from: from, name_from: name_from, subject: subject, check_local_stop_list: true, track_open: true, track_click: true, message_text: body, users: users } request('POST', "api/v1/add_json_package?key=#{@api_key}", data) end |
#status_email_delivery(email: nil, x_track_id: nil, message_id: nil) ⇒ Object
Gets delivery status of a specific message
274 275 276 277 |
# File 'lib/mailganer_client/client.rb', line 274 def status_email_delivery(email: nil, x_track_id: nil, message_id: nil) params = { email: email, x_track_id: x_track_id, message_id: }.compact request('GET', "api/v2/issue/status", params) end |
#status_emails_package(pack_id:) ⇒ Object
Gets status of a bulk package
262 263 264 265 |
# File 'lib/mailganer_client/client.rb', line 262 def status_emails_package(pack_id:) params = { issuen: pack_id} request('GET', "api/v2/package/status", params) end |
#stop_emails_package(pack_id:) ⇒ Object
Stops a bulk email package
251 252 253 254 |
# File 'lib/mailganer_client/client.rb', line 251 def stop_emails_package(pack_id:) params = { key: @api_key, pack_id: pack_id } request('GET', "api/v1/package_stop", params) end |
#stop_list_add(email:, mail_from:) ⇒ Object
Adds email to stop-list
357 358 359 360 |
# File 'lib/mailganer_client/client.rb', line 357 def stop_list_add(email:, mail_from:) validate_email!(email) request('POST', "api/v2/stop-list/add?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true) end |
#stop_list_remove(email:, mail_from:) ⇒ Object
Removes email from stop-list
365 366 367 368 |
# File 'lib/mailganer_client/client.rb', line 365 def stop_list_remove(email:, mail_from:) validate_email!(email) request('POST', "api/v2/stop-list/remove?#{URI.encode_www_form(mail_from: mail_from, email: email)}", nil, true) end |
#stop_list_search(email:) ⇒ Object
Searches email in stop-list
349 350 351 352 |
# File 'lib/mailganer_client/client.rb', line 349 def stop_list_search(email:) validate_email!(email) request('GET', 'api/v2/stop-list/search', { email: email }) end |