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 +4 -4
- data/README.md +9 -2
- data/lib/gridhook.rb +2 -0
- data/lib/gridhook/config.rb +3 -4
- data/lib/gridhook/engine.rb +3 -1
- data/lib/gridhook/errors.rb +1 -0
- data/lib/gridhook/event.rb +18 -0
- data/lib/gridhook/unfortunate_sendgrid_fix.rb +10 -8
- data/lib/gridhook/version.rb +1 -1
- data/test/helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 839428d1167c2c442e70a17e9bc6bdecd3a4cd9a
|
4
|
+
data.tar.gz: a75f9a9e050b1abf48d96349a402d3ba2f298e3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e500c033309351375601d64a73797e8937e3f28010ac88bf763785bee0b33819a703b739869499e94a9f7aed61b068f69af5af29cff7331d4a689072c01ba81e
|
7
|
+
data.tar.gz: 1e5584c7006688438f7813f418cdb9ea2d06ffd774e96465d05e206817d53e26d08c005c4c6e4ebb6bb67aae3b63f1ab4eef442e5b149a288c42ffcad4b76b4e
|
data/README.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# Gridhook
|
2
2
|
|
3
|
-
|
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)
|
data/lib/gridhook.rb
CHANGED
data/lib/gridhook/config.rb
CHANGED
@@ -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
|
data/lib/gridhook/engine.rb
CHANGED
@@ -2,6 +2,8 @@ require 'gridhook/unfortunate_sendgrid_fix'
|
|
2
2
|
|
3
3
|
module Gridhook
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
-
|
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
|
data/lib/gridhook/errors.rb
CHANGED
data/lib/gridhook/event.rb
CHANGED
@@ -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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Gridhook
|
2
|
+
class UnfortunateSendgridFix
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/lib/gridhook/version.rb
CHANGED
data/test/helper.rb
CHANGED