Skip to content
SendGrid v3 Mail Send API Ruby Client that validates API request body using JSON Schema.
Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin first commit Dec 30, 2019
lib Check personalizations item count Jan 2, 2020
spec Fix spec Jan 2, 2020
tasks Check personalizations item count Jan 2, 2020
.gitignore first commit Dec 30, 2019
.rspec first commit Dec 30, 2019
.rubocop.yml first commit Dec 30, 2019
.travis.yml first commit Dec 30, 2019
Gemfile first commit Dec 30, 2019
Gemfile.lock Update Gemfile.lock Jan 2, 2020
LICENSE.txt first commit Dec 30, 2019
README.md Update README.md Jan 2, 2020
Rakefile first commit Dec 30, 2019
kani_laser.gemspec Update gemspec summary Dec 30, 2019

README.md

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

You can’t perform that action at this time.