0.0
No commit activity in last 3 years
No release in over 3 years
Easily simulate Sendgrid webhooks using Pokey.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
~> 10.0
>= 0

Runtime

~> 1.5
~> 0.2
 Project Readme

Pokey::Sendgrid

Sensible defaults to emulate Sendgrid data on development/QA using Pokey hooks.

Installation

Add this line to your application's Gemfile:

gem 'pokey-sendgrid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pokey-sendgrid

Usage

If this is your first installation (and you're on Rails), run

$ rails g pokey:install

This will create an initializer file that defines your hook_dir (the location where all hooks will be defined). Just create a new file in that directory that inherits from Pokey::Sendgrid::Hook.

Simple example:

class SendgridHook < Pokey::Sendgrid::Hook
  # Your Sendgrid webhook endpoint
  def destination
    # Defaults to /api/sendgrid/events
    "http://localhost:3000/api/sendgrid/events"
  end

  # Time (in seconds) between Pokey requests
  def interval
    5 # Defaults to 5
  end
end

Categories and Unique Arguments

This gem also supports dynamic categories / unique arguments when generating data. To use:

class SendgridHook < Pokey::SendgridHook
  def categories
    [
      ["User", "Welcome Email"],
      ["Billing", "Payment Successful"]
    ]
  end

  def unique_args
    {
      "custom-identifier" => 15
    }
  end
end

Limiting Events

By default, Pokey::Sendgrid will generate all types of SendGrid events:

  • processed
  • dropped
  • delivered
  • deferred
  • bounce
  • open
  • click
  • spam_report
  • unsubscribe
  • group_unsubscribe
  • group_resubscribe

To limit the amount of events your application receives, override the sendgrid_events method like so:

class SendgridHook < Pokey::SendgridHook
  protected

  # Limits events to only "Open" and "Click"
  def sendgrid_events
    ["open", "click"]
  end
end

Start generating data

If you're on rails, just start your server. Otherwise, start your application.

Here's an example request:

 INFO  Pokey::Logger : Made request to localhost:3000 with following data: {"timestamp"=>1439864701, "category"=>nil, "event"=>"dropped", "email"=>"dwight_kerluke@blick.co", "smtp-id"=>"ejaeym5uxil_3v2fm3qjzf0@tremblay.mail"}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ccallebs/pokey-sendgrid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.