UniOne (unione.io) integration gem for Ruby
gem install unione-ruby
This library uses 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 'unione-ruby'
unione = UniOne::Client.new(
hostname: 'eu1.unione.io',
api_key: ENV['UNIONE_API_KEY']
)
response = unione.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
By default authentication sent through X-API-KEY header.
For passing API key in parameters, use:
unione = UniOne::Client.new(
hostname: 'eu1.unione.io',
lang: 'en',
api_key: ENV['UNIONE_API_KEY'],
api_key_in_params: true
)
Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
unione.verify_callback_auth!(params)
Use it to substitute webhook handler verification and parsing to directly get list of events.
Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
unione.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
Library using `raise-error' middleware for handling error responses.
Example of work with errors:
require 'unione-ruby'
begin
unione = UniOne::Client.new(
hostname: 'eu1.unione.io',
lang: 'en',
api_key: ENV['UNIONE_API_KEY']
)
response = unione.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
Pass timeout: <seconds>
parameter on creating client, default is 5.
Pass enable_logging: true
parameter on creating client to enable logging, default false.
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