Skip to content

Commit

Permalink
Rails parses JSON automatically when proper headers are present
Browse files Browse the repository at this point in the history
  • Loading branch information
stereoscott committed Sep 21, 2013
1 parent 3608487 commit 8e9e56c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ end
```

## Changelog
v0.2.1 Use built-in rails JSON parser.

v0.2.0 Supports version 3 of the Sendgrid webhook released on
September 6th, 2013, which provides the proper headers and JSON post body
without hacks or middleware. If upgrading to this version, please make sure
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gridhook/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Gridhook
class EventsController < ActionController::Base
def create
Gridhook::Event.process(request.body, params)
Gridhook::Event.process(params)
head :ok
end
end
Expand Down
1 change: 0 additions & 1 deletion gridhook.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
spec.require_paths = ['app', 'lib']

spec.add_dependency 'rails', '>= 3.1.0'
spec.add_dependency 'multi_json', '>= 1.3.0'

spec.add_development_dependency 'bundler', '~> 1.2'
spec.add_development_dependency 'rake'
Expand Down
13 changes: 4 additions & 9 deletions lib/gridhook/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ class Event
# body - A String or stream for MultiJson to parse
#
# Returns nothing.
def self.process(body, params = {})
begin
event = MultiJson.load(body)
if event.is_a?(Array)
process_events event
else
process_event event
end
rescue MultiJson::LoadError
def self.process(params = {})
if params.has_key? "_json"
process_events params["_json"]
else
process_event params.except(:controller, :action)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gridhook/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gridhook
VERSION = '0.2.0'
VERSION = '0.2.1'
end

0 comments on commit 8e9e56c

Please sign in to comment.