gridhook 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/gridhook/events_controller.rb +1 -1
- data/lib/gridhook/event.rb +10 -3
- data/lib/gridhook/version.rb +1 -1
- data/test/gridlock/event_test.rb +10 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d791609c5397b321d7f9df288063a033f854dd23
|
4
|
+
data.tar.gz: b6927324b781fafb331fbf19a806e14329f86095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8acb4edbd86e175b7c6201eedc633e729283d7e963ae4c95dd896669b5cb9b49d659ace8e99ea86dc35f005d0553cb61b8ad8120aab019358a22af501f0ff1e3
|
7
|
+
data.tar.gz: 221de705910f0162ec166c7597de9824ecf58ce86bebef3dbaea406d000cdbb649a8c4233ccfa52cd71b2fab372cb349651c4d88543f8016b5670dd1e7a331f8
|
data/lib/gridhook/event.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/hash/except'
|
2
|
+
|
1
3
|
module Gridhook
|
2
4
|
class Event
|
3
5
|
|
@@ -7,7 +9,7 @@ module Gridhook
|
|
7
9
|
# body - A String or stream for Yajl to parse
|
8
10
|
#
|
9
11
|
# Returns nothing.
|
10
|
-
def self.process(body)
|
12
|
+
def self.process(body, params = {})
|
11
13
|
parser = Yajl::Parser.new
|
12
14
|
parser.on_parse_complete = proc do |event|
|
13
15
|
if event.is_a?(Array)
|
@@ -16,7 +18,11 @@ module Gridhook
|
|
16
18
|
process_event event
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
21
|
+
begin
|
22
|
+
parser.parse(body)
|
23
|
+
rescue Yajl::ParseError
|
24
|
+
process_event params.except(:controller, :action)
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
# The original Hash of attributes received from SendGrid.
|
@@ -31,10 +37,11 @@ module Gridhook
|
|
31
37
|
def name
|
32
38
|
attributes[:event]
|
33
39
|
end
|
40
|
+
alias event name
|
34
41
|
|
35
42
|
# Returns a new Time object from the event timestamp.
|
36
43
|
def timestamp
|
37
|
-
Time.at
|
44
|
+
Time.at((attributes[:timestamp] || Time.now).to_i)
|
38
45
|
end
|
39
46
|
|
40
47
|
# A helper for accessing the original values sent from
|
data/lib/gridhook/version.rb
CHANGED
data/test/gridlock/event_test.rb
CHANGED
@@ -37,10 +37,18 @@ class EventTest < TestCase
|
|
37
37
|
assert_equal 2, @events.size
|
38
38
|
end
|
39
39
|
|
40
|
+
test 'ensure we fallback to request parameters if invalid JSON found in body' do
|
41
|
+
process('email=test@gmail.com&arg2=2&arg1=1&category=testing&event=processed',
|
42
|
+
{ :email => 'test@gmail.com', :arg2 => '2', :arg1 => '1', :category => 'testing',
|
43
|
+
:event => 'processed', :controller => 'sendgrid', :action => 'receive'})
|
44
|
+
assert_equal 1, @events.size
|
45
|
+
assert_equal 'processed', @events.first.event
|
46
|
+
end
|
47
|
+
|
40
48
|
private
|
41
49
|
|
42
|
-
def process(str)
|
43
|
-
Gridhook::Event.process(str)
|
50
|
+
def process(str, params = {})
|
51
|
+
Gridhook::Event.process(str, params)
|
44
52
|
end
|
45
53
|
|
46
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gridhook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Jarvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.0.
|
162
|
+
rubygems_version: 2.0.1
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: A SendGrid webhook endpoint
|