Skip to content

Use this project as an example for creating webhookr plugins.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE.txt
MIT
MIT-LICENSE
Notifications You must be signed in to change notification settings

gerrypower/webhookr-example_plugin

Repository files navigation

Webhookr::ExamplePlugin

Build Status Dependency Status Code Climate Coverage Status

This gem is a plugin for Webhookr that enables your application to accept webhooks from ExamplePlugin.

Installation

Add this line to your application's Gemfile:

gem 'webhookr-example_plugin'

Or install it yourself:

$ gem install webhookr-example_plugin

webhookr is installed as a dependency of webhookr-example_plugin. If you have not setup Webhookr, do so now:

rails g webhookr:add_route

Usage

Once you have the gem installed run the generator to add the code to your initializer. An initializer will be created if you do not have one.

rails g webhookr:example_plugin:init *initializer_name* -s

Run the generator to create an example file to handle example_plugin webhooks.

rails g webhookr:example_plugin:example_hooks

Or create a example_plugin handler class for any event that you want to handle. For example to handle unsubscribes you would create a class as follows:

class example_pluginHooks
  def on_spam(incoming)
    # Your custom logic goes here.
    User.unsubscribe_newletter(incoming.payload.msg.email)
  end
end

For a complete list of events, and the payload format, see below.

Edit config/initializers/initializer_name and change the commented line to point to your custom ExamplePlugin event handling class. If your class was called ExamplePluginHooks the configuration line would look like this:

  Webhookr::ExamplePlugin::Adapter.config.callback = ExamplePluginHooks

To see the list of ExamplePlugin URLs your application can use when you configure example_plugin webhooks, run the provided webhookr rake task:

rake webhookr:services

Example output:

example_plugin:
  GET	/webhookr/events/example_plugin/19xl64emxvn
  POST	/webhookr/events/example_plugin/19xl64emxvn

ExamplePlugin Events & Payload

Events

All webhook events are supported. For further information on these events, see the example_plugin documentation.

ExamplePlugin Event Event Handler
send on_send(incoming)
hard_bounce on_hard_bounce(incoming)
soft_bounce on_soft_bounce(incoming)
open on_open(incoming)
click on_click(incoming)
spam on_spam(incoming)
unsub on_unsub(incoming)
reject on_reject(incoming)

Payload

The payload is the full payload data from as per the example_plugin documentation, converted to an OpenStruct for ease of access. Examples for the method call unsubscribe:

  incoming.payload.msg._id
  incoming.payload.msg.ts
  incoming.payload.msg.email
  incoming.payload.msg.sender
  incoming.payload.msg.subject
  incoming.payload.msg.opens
  incoming.payload.msg.tags
  incoming.payload.msg.state
  incoming.payload.msg.diag
  incoming.payload.msg.bounce_description
  incoming.payload.msg.template

Supported Service - example_plugin

  • [http://help.example_plugin.com/entries/21738186-Introduction-to-Webhooks](example_plugin - v1.0)

Works with:

webhookr-example_plugin works with Rails 3.1, 3.2 and 4.0, and has been tested on the following Ruby implementations:

  • 1.9.3
  • 2.0.0
  • jruby-19mode

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, once this gem reaches a 1.0 release, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'webhookr-example_plugin', '~> 1.0'

While this gem is currently a 0.x release, suggestion is to require the exact version that works for your code:

spec.add_dependency 'webhookr-example_plugin', '0.0.1'

License

webhookr-example_plugin is released under the MIT license.

Author

About

Use this project as an example for creating webhookr plugins.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE.txt
MIT
MIT-LICENSE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages