https://github.com/winebarrel/kani_laser
SendGrid v3 Mail Send API Ruby Client that validates API request body using JSON Schema.
https://github.com/winebarrel/kani_laser
email ruby sendgrid
Last synced: 10 months ago
JSON representation
SendGrid v3 Mail Send API Ruby Client that validates API request body using JSON Schema.
- Host: GitHub
- URL: https://github.com/winebarrel/kani_laser
- Owner: winebarrel
- License: mit
- Created: 2019-12-30T07:29:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-16T00:42:27.000Z (over 5 years ago)
- Last Synced: 2025-07-29T16:29:38.644Z (11 months ago)
- Topics: email, ruby, sendgrid
- Language: Ruby
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# KaniLaser
[SendGrid v3 Mail Send API](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html) Ruby Client that validates API request body using [JSON Schema](https://github.com/winebarrel/kani_laser/blob/master/lib/kani_laser/schema.rb).
[](http://badge.fury.io/rb/kani_laser)
[](https://travis-ci.org/winebarrel/kani_laser)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'kani_laser'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install kani_laser
## Usage
```ruby
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
```ruby
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`
```ruby
KaniLaser::Client.new(options) do |faraday|
faraday.headers['On-Behalf-Of'] = ''
end
```
## Request parameter validation error example
```ruby
# 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
```sh
rake schema:update
```
## Related links
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
* https://sendgrid.api-docs.io/
* https://github.com/sendgrid/sendgrid-oai/