gridhook 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd1b5b0d7fdd8ee2aabe014129eb68735f7e2559
4
- data.tar.gz: aff3bde4721b9444ef3e1d33963438a40e5fdd8b
3
+ metadata.gz: 839428d1167c2c442e70a17e9bc6bdecd3a4cd9a
4
+ data.tar.gz: a75f9a9e050b1abf48d96349a402d3ba2f298e3f
5
5
  SHA512:
6
- metadata.gz: be176c7e538cd9edd0d87681aee4b95176f594ff1e05db89da37d1abf47aa49a7567e8c7521d2fa576e4dce7ac1fd308987b9bd6271fa1e998aa26c6cf93b314
7
- data.tar.gz: 48cec9955b1ac5884010856e1dd38729bec8d2111173d0b15d23a124aeb74388c1557969756d10523dc834a6bde2c4d92a99d9b9e417e23e0dc84d6c678ce38d
6
+ metadata.gz: e500c033309351375601d64a73797e8937e3f28010ac88bf763785bee0b33819a703b739869499e94a9f7aed61b068f69af5af29cff7331d4a689072c01ba81e
7
+ data.tar.gz: 1e5584c7006688438f7813f418cdb9ea2d06ffd774e96465d05e206817d53e26d08c005c4c6e4ebb6bb67aae3b63f1ab4eef442e5b149a288c42ffcad4b76b4e
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
1
  # Gridhook
2
2
 
3
- A Rails engine providing an endpoint for handling incoming SendGrid
4
- webhook events.
3
+ Gridhook is a Rails engine providing an endpoint for handling incoming
4
+ SendGrid webhook events.
5
+
6
+ This engine supports both batched and non-batched events from SendGrid.
7
+
8
+ Looking to handle incoming email from the SendGrid Parse API? Gridhook
9
+ will eventually support that, until then, you should check out
10
+ [Griddler](https://github.com/thoughtbot/griddler). It's awesome.
5
11
 
6
12
  ## Installation
7
13
 
@@ -49,5 +55,6 @@ end
49
55
 
50
56
  ## More Information
51
57
 
58
+ * [Gridhook API Documentation](http://injekt.github.com/rdoc/gridhook/)
52
59
  * [SendGrid Webhooks](http://sendgrid.com/docs/API_Reference/Webhooks/index.html)
53
60
  * [SendGrid Webhooks/Event](http://sendgrid.com/docs/API_Reference/Webhooks/event.html)
@@ -1,6 +1,8 @@
1
1
  require 'rails/engine'
2
2
  require 'yajl'
3
+ require 'yajl/json_gem'
3
4
  require 'action_view'
5
+ require 'action_dispatch'
4
6
 
5
7
  require 'gridhook/engine'
6
8
  require 'gridhook/config'
@@ -1,18 +1,17 @@
1
1
  module Gridhook
2
2
 
3
+ # Returns a new Config instance.
3
4
  def self.config
4
5
  @config ||= Config.new
5
6
  end
6
7
 
8
+ # A helper method for providing a configure block.
7
9
  def self.configure
8
10
  yield config
9
11
  end
10
12
 
13
+ # This class handles storing Gridhooks configuration variables.
11
14
  class Config < Struct.new(:event_processor, :event_receive_path)
12
- def initialize(*)
13
- self.event_receive_path = '/sendgrid/event'
14
- super
15
- end
16
15
  end
17
16
 
18
17
  end
@@ -2,6 +2,8 @@ require 'gridhook/unfortunate_sendgrid_fix'
2
2
 
3
3
  module Gridhook
4
4
  class Engine < ::Rails::Engine
5
- config.app_middleware.insert_before ActionDispatch::ParamsParser, 'UnfortunateSendgridFix'
5
+ # Insert our SendGrid JSON fix middleware before ParamsParser
6
+ # attempts to encode the JSON.
7
+ config.app_middleware.insert_before ActionDispatch::ParamsParser, 'Gridhook::UnfortunateSendgridFix'
6
8
  end
7
9
  end
@@ -2,6 +2,7 @@ module Gridhook
2
2
  class Error < StandardError
3
3
  end
4
4
 
5
+ # Raised if Gridhook.config.event_processor does not respond to #call.
5
6
  class InvalidEventProcessor < Error
6
7
  end
7
8
  end
@@ -1,6 +1,12 @@
1
1
  module Gridhook
2
2
  class Event
3
3
 
4
+ # Process a String or stream of JSON and execute our
5
+ # event processor.
6
+ #
7
+ # body - A String or stream for Yajl to parse
8
+ #
9
+ # Returns nothing.
4
10
  def self.process(body)
5
11
  parser = Yajl::Parser.new
6
12
  parser.on_parse_complete = proc do |event|
@@ -13,20 +19,32 @@ module Gridhook
13
19
  parser.parse(body)
14
20
  end
15
21
 
22
+ # The original Hash of attributes received from SendGrid.
16
23
  attr_reader :attributes
17
24
 
18
25
  def initialize(attributes)
19
26
  @attributes = attributes.with_indifferent_access
20
27
  end
21
28
 
29
+ # An alias for returning the type of this event, ie:
30
+ # sent, delivered, bounced, etc
22
31
  def name
23
32
  attributes[:event]
24
33
  end
25
34
 
35
+ # Returns a new Time object from the event timestamp.
26
36
  def timestamp
27
37
  Time.at (attributes[:timestamp] || Time.now).to_i
28
38
  end
29
39
 
40
+ # A helper for accessing the original values sent from
41
+ # SendGrid, ie
42
+ #
43
+ # Example:
44
+ #
45
+ # event = Event.new(event: 'sent', email: 'lee@example.com')
46
+ # event[:event] #=> 'sent'
47
+ # event['email'] #=> 'lee@example.com' # indifferent access
30
48
  def [](key)
31
49
  attributes[key]
32
50
  end
@@ -1,12 +1,14 @@
1
- class UnfortunateSendgridFix
2
- def initialize(app)
3
- @app = app
4
- end
1
+ module Gridhook
2
+ class UnfortunateSendgridFix
3
+ def initialize(app)
4
+ @app = app
5
+ end
5
6
 
6
- def call(env)
7
- if env['PATH_INFO'] == Gridhook.config.event_receive_path
8
- env['CONTENT_TYPE'] = 'text/plain'
7
+ def call(env)
8
+ if env['PATH_INFO'] == Gridhook.config.event_receive_path
9
+ env['CONTENT_TYPE'] = 'text/plain'
10
+ end
11
+ @app.call(env)
9
12
  end
10
- @app.call(env)
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module Gridhook
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path '../dummy/config/environment', __FILE__
2
+ # require File.expand_path '../dummy/config/environment', __FILE__
3
3
 
4
4
  require 'minitest/autorun'
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis