gridhook 0.1.4 → 0.2.0

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: d791609c5397b321d7f9df288063a033f854dd23
4
- data.tar.gz: b6927324b781fafb331fbf19a806e14329f86095
3
+ metadata.gz: 8ad6d5bbe35f5ec6ea021d69e67971e053deb4af
4
+ data.tar.gz: 3eab2c6b882d0f6277b87fa8c8cdb9c2c177519d
5
5
  SHA512:
6
- metadata.gz: 8acb4edbd86e175b7c6201eedc633e729283d7e963ae4c95dd896669b5cb9b49d659ace8e99ea86dc35f005d0553cb61b8ad8120aab019358a22af501f0ff1e3
7
- data.tar.gz: 221de705910f0162ec166c7597de9824ecf58ce86bebef3dbaea406d000cdbb649a8c4233ccfa52cd71b2fab372cb349651c4d88543f8016b5670dd1e7a331f8
6
+ metadata.gz: 087d115559a7a5ab94831ad5a1375a36b933b7612100f4c7e3ed29131d7b844d5ed066c68d64ee8d736a43bc3557b47c8f2c7462fc32f530495bf1b201a281b5
7
+ data.tar.gz: 9d3bf84b34671514fd207e4212dc1f5d2648227c6bb6efe582d7e4f17f86713103dca19d990f9c6f7deb16e995d439a19c02da60d64fde6eaee197566fcbb5f3
data/README.md CHANGED
@@ -48,6 +48,12 @@ Gridhook.configure do |config|
48
48
  end
49
49
  ```
50
50
 
51
+ ## Changelog
52
+ v0.2.0 Supports version 3 of the Sendgrid webhook released on
53
+ September 6th, 2013, which provides the proper headers and JSON post body
54
+ without hacks or middleware. If upgrading to this version, please make sure
55
+ to update the Webhooks settings in your SendGrid App to use V3 of their API.
56
+
51
57
  ## TODO
52
58
 
53
59
  * More tests
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['app', 'lib']
21
21
 
22
22
  spec.add_dependency 'rails', '>= 3.1.0'
23
- spec.add_dependency 'yajl-ruby', '~> 1.1.0'
23
+ spec.add_dependency 'multi_json', '>= 1.3.0'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.2'
26
26
  spec.add_development_dependency 'rake'
@@ -1,6 +1,5 @@
1
1
  require 'rails/engine'
2
- require 'yajl'
3
- require 'yajl/json_gem'
2
+ require 'multi_json'
4
3
  require 'action_view'
5
4
  require 'action_dispatch'
6
5
 
@@ -1,9 +1,4 @@
1
- require 'gridhook/unfortunate_sendgrid_fix'
2
-
3
1
  module Gridhook
4
2
  class Engine < ::Rails::Engine
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'
8
3
  end
9
4
  end
@@ -6,21 +6,18 @@ module Gridhook
6
6
  # Process a String or stream of JSON and execute our
7
7
  # event processor.
8
8
  #
9
- # body - A String or stream for Yajl to parse
9
+ # body - A String or stream for MultiJson to parse
10
10
  #
11
11
  # Returns nothing.
12
12
  def self.process(body, params = {})
13
- parser = Yajl::Parser.new
14
- parser.on_parse_complete = proc do |event|
13
+ begin
14
+ event = MultiJson.load(body)
15
15
  if event.is_a?(Array)
16
16
  process_events event
17
17
  else
18
18
  process_event event
19
19
  end
20
- end
21
- begin
22
- parser.parse(body)
23
- rescue Yajl::ParseError
20
+ rescue MultiJson::LoadError
24
21
  process_event params.except(:controller, :action)
25
22
  end
26
23
  end
@@ -1,3 +1,3 @@
1
1
  module Gridhook
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -18,15 +18,6 @@ class EventTest < TestCase
18
18
  assert_equal 'delivered', @events.first.name
19
19
  end
20
20
 
21
- test 'parsing incoming (invalid) JSON in batches' do
22
- process <<-E
23
- {"email":"foo@bar.com","timestamp":1322000095,"unique_arg":"my unique arg","event":"delivered"}
24
- {"email":"foo@bar.com","timestamp":1322000096,"unique_arg":"my unique arg","event":"open"}
25
- E
26
- assert_kind_of Gridhook::Event, @events.first
27
- assert_equal 2, @events.size
28
- end
29
-
30
21
  # for when sendgrid fix their JSON batch requests
31
22
  test 'parsing incoming (valid) JSON in batches' do
32
23
  obj = [
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
4
+ version: 0.2.0
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 00:00:00.000000000 Z
11
+ date: 2013-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: yajl-ruby
28
+ name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.0
33
+ version: 1.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.0
40
+ version: 1.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +101,6 @@ files:
101
101
  - lib/gridhook/engine.rb
102
102
  - lib/gridhook/errors.rb
103
103
  - lib/gridhook/event.rb
104
- - lib/gridhook/unfortunate_sendgrid_fix.rb
105
104
  - lib/gridhook/version.rb
106
105
  - test/dummy/README.rdoc
107
106
  - test/dummy/Rakefile
@@ -159,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  version: '0'
160
159
  requirements: []
161
160
  rubyforge_project:
162
- rubygems_version: 2.0.1
161
+ rubygems_version: 2.0.2
163
162
  signing_key:
164
163
  specification_version: 4
165
164
  summary: A SendGrid webhook endpoint
@@ -1,14 +0,0 @@
1
- module Gridhook
2
- class UnfortunateSendgridFix
3
- def initialize(app)
4
- @app = app
5
- end
6
-
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)
12
- end
13
- end
14
- end