Project

kani_laser

0.0
No commit activity in last 3 years
No release in over 3 years
SendGrid v3 Mail Send API Ruby Client that validates API request body using JSON Schema.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

 Project Readme

KaniLaser

SendGrid v3 Mail Send API Ruby Client that validates API request body using JSON Schema.

Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'kani_laser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kani_laser

Usage

require 'kani_laser'

client = KaniLaser::Client.new(api_key: 'ZAPZAPZAP')

# see https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
client.send_mail(
  personalizations: [
    {
      to: [
        {
          email: 'john@example.com'
        }
      ],
      subject: 'Hello, World!'
    }
  ],
  from: {
    email: 'from_address@example.com'
  },
  content: [
    {
      type: 'text/plain',
      value: 'Hello, World!'
    }
  ]
)

For testing

client = KaniLaser::Client.new(options) do |faraday|
  faraday.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
    stub.post('/v3/mail/send') do |_env|
      [202, {}, '']
    end
  end
end

client.send_mail(...)

Use On-Behalf-Of

KaniLaser::Client.new(options) do |faraday|
  faraday.headers['On-Behalf-Of'] = '<subuser_username>'
end

Request parameter validation error example

# Invalid Parameter
{
  personalizations: [{ to: [{ email: 'sugawara@winebarrel.jp' }] }],
  subject: 'Hello, World!',
  from: { email: 'from_address@example.com' },
  content: [{ value: 'Hello, World!' }],
}
JSON::Schema::ValidationError: The property '#/content/0' did not contain a required property of 'type'

Update schema

rake schema:update

Related links