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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43deaac095d3476254f00b52a8063f8754e9adee
4
- data.tar.gz: 1b5885bf92c054839372af4504d83e7ed60cd96d
3
+ metadata.gz: d791609c5397b321d7f9df288063a033f854dd23
4
+ data.tar.gz: b6927324b781fafb331fbf19a806e14329f86095
5
5
  SHA512:
6
- metadata.gz: 7ce42a670a616490d15ba22fe4f5be46fd7a48c93f54ec84c3c0d93fc24f2efc65f8cddfe1fe85af4bb308ec6817a9d03d87f41ffb4224d4378897b6cdc4ff76
7
- data.tar.gz: 020513e2ca1876a628b17d217782626db34191583a32e4a7c7a6cd58dccb1bf31195440ce12fcaeb787d8466af82ac0c2e84d030d7516c6f84f6f78620262387
6
+ metadata.gz: 8acb4edbd86e175b7c6201eedc633e729283d7e963ae4c95dd896669b5cb9b49d659ace8e99ea86dc35f005d0553cb61b8ad8120aab019358a22af501f0ff1e3
7
+ data.tar.gz: 221de705910f0162ec166c7597de9824ecf58ce86bebef3dbaea406d000cdbb649a8c4233ccfa52cd71b2fab372cb349651c4d88543f8016b5670dd1e7a331f8
@@ -1,7 +1,7 @@
1
1
  module Gridhook
2
2
  class EventsController < ActionController::Base
3
3
  def create
4
- Gridhook::Event.process(request.body)
4
+ Gridhook::Event.process(request.body, params)
5
5
  head :ok
6
6
  end
7
7
  end
@@ -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
- parser.parse(body)
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 (attributes[:timestamp] || Time.now).to_i
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
@@ -1,3 +1,3 @@
1
1
  module Gridhook
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -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.3
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-08 00:00:00.000000000 Z
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.0
162
+ rubygems_version: 2.0.1
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: A SendGrid webhook endpoint