-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates parity between request body parsing and response body rendering. Also delegates web form parsing to Rack::Request. Signed-off-by: Stephen Celis <stephen.celis@gmail.com> Signed-off-by: Evan Owen <kainosnoema@gmail.com>
- Loading branch information
1 parent
8c31b2e
commit 577c636
Showing
10 changed files
with
82 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Crepe | ||
module Parser | ||
|
||
autoload :Simple, 'crepe/parser/simple' | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'multi_json' | ||
require 'multi_xml' | ||
|
||
module Crepe | ||
module Parser | ||
# A base parser class that attempts to parse common MIME types. | ||
class Simple | ||
|
||
attr_reader :endpoint | ||
|
||
def initialize endpoint | ||
@endpoint = endpoint | ||
end | ||
|
||
delegate :error!, :request, to: :endpoint | ||
|
||
def parse body | ||
case request.media_type | ||
when %r{application/x-www-form-urlencoded} | ||
request.POST | ||
when %r{application/json} | ||
begin | ||
MultiJson.load body | ||
rescue MultiJson::DecodeError | ||
error! :bad_request, "Invalid JSON" | ||
end | ||
when %r{application/xml} | ||
begin | ||
MultiXml.parse body | ||
rescue MultiXml::ParseError | ||
error! :bad_request, "Invalid XML" | ||
end | ||
else | ||
error! :unsupported_media_type, | ||
%(Content-Type "#{request.media_type}" not supported) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,3 @@ class RenderError < StandardError | |
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters