Socket
Book a DemoInstallSign in
Socket

unigo-ruby

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unigo-ruby

1.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

unigo-ruby

Unisender Go (https://go.unisender.ru) integration gem for Ruby

Examples of usage

Installation

gem install unigo-ruby

Working with API responses

This library using faraday gem for making HTTP queries along with mashify middleware for post-processing response body. So, you can use extended syntax for accessing response fields.

Example of work with responses:

require 'unigo-ruby'

unigo = UniGo::Client.new(
  hostname: 'go1.unisender.ru',
  lang: 'ru',
  api_key: ENV['UNIGO_API_KEY']
)

response = unigo.get_dns_records("example.com")

puts response.status
puts response.body.to_h
puts response.headers

# Access fields as hash keys or as object attributes:
puts response.body['status']
puts response.body.status

Passing API key in parameters

By default authentication sent through X-API-KEY header.

For passing API key in parameters, use:

unigo = UniGo::Client.new(
  hostname: 'go1.unisender.ru',
  lang: 'ru',
  api_key: ENV['UNIGO_API_KEY'],
  api_key_in_params: true
)

Verify webhook callback message

Will raise UniGo::Client::InvalidCallbackAuth error unless `auth' field is correct.

unigo.verify_callback_auth!(params)

Webhook callback helper

Use it to substitute webhook handler verification and parsing to directly get list of events.

Will raise UniGo::Client::InvalidCallbackAuth error unless `auth' field is correct.

unigo.callback_helper(params) do |events|
  # [
  #   {
  #     'event_name' => 'transactional_email_status',
  #     'event_data' =>
  #      {
  #        'email' => 'recipient.email@example.com',
  #        'status' => 'sent',
  #        'event_time' => '2015-11-30 15:09:42',
  #       ...
  #      }
  #   },
  #   ...
  # ]
end

Handling API errors

Library using `raise-error' middleware for handling error responses.

Example of work with errors:

require 'unigo-ruby'

begin

  unigo = UniGo::Client.new(
    hostname: 'go1.unisender.ru',
    lang: 'ru',
    api_key: ENV['UNIGO_API_KEY']
  )

  response = unigo.get_dns_records("example.com")

  puts response.status
  puts response.body.to_h
  puts response.headers

rescue Faraday::Error => e

  # Note that exception response has internal format which is a little
  # bit different and body field is not post-processed

  puts e.response[:status]
  puts e.response[:body]
  puts e.response[:headers]

end

HTTP timeout configuration

Pass timeout: <seconds> parameter on creating client, default is 5.

HTTP logging

Pass enable_logging: true parameter on creating client to enable logging, default false.

Testing

You can run tests through included test task and passing methods for test and data inside YAML config file:

rake test DOMAIN APIKEY WEBHOOK_URL FROM_EMAIL ./test/CONFIGFILE.yml

FAQs

Package last updated on 24 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.