-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from excpt/refactor-json-dependency
Remove obsolete json code
- Loading branch information
Showing
1 changed file
with
9 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
require 'json' | ||
|
||
module JWT | ||
# JSON fallback implementation or ruby 1.8.x | ||
module Json | ||
if RUBY_VERSION >= '1.9' && !defined?(MultiJson) | ||
require 'json' | ||
|
||
def decode_json(encoded) | ||
JSON.parse(encoded) | ||
rescue JSON::ParserError | ||
raise JWT::DecodeError, 'Invalid segment encoding' | ||
end | ||
|
||
def encode_json(raw) | ||
JSON.generate(raw) | ||
end | ||
|
||
else | ||
require 'multi_json' | ||
|
||
def decode_json(encoded) | ||
MultiJson.decode(encoded) | ||
rescue MultiJson::LoadError | ||
raise JWT::DecodeError, 'Invalid segment encoding' | ||
end | ||
def decode_json(encoded) | ||
JSON.parse(encoded) | ||
rescue JSON::ParserError | ||
raise JWT::DecodeError, 'Invalid segment encoding' | ||
end | ||
|
||
def encode_json(raw) | ||
MultiJson.encode(raw) | ||
end | ||
def encode_json(raw) | ||
JSON.generate(raw) | ||
end | ||
end | ||
end |