Skip to content

Commit

Permalink
Replace multi_json with json
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 30, 2013
1 parent eb82864 commit e5fc292
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ Here are some fun facts about this library:
* This gem works on every major Ruby implementation, including JRuby and
Rubinius
* The first version was released on November 26, 2006
* This gem has just three runtime dependencies: `faraday`, `multi_json`, and
`simple_oauth`
* This gem has just two runtime dependencies: `faraday`, and `simple_oauth`
* Previous versions of this gem have been [downloaded over half a million
times][stats]
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'faraday'
require 'multi_json'
require 'json'
require 'twitter/api/direct_messages'
require 'twitter/api/favorites'
require 'twitter/api/friends_and_followers'
Expand All @@ -18,7 +18,7 @@
require 'twitter/api/users'
require 'twitter/configurable'
require 'twitter/error/client_error'
require 'twitter/error/decode_error'
require 'twitter/error/parser_error'
require 'simple_oauth'
require 'base64'
require 'uri'
Expand Down Expand Up @@ -109,8 +109,8 @@ def request(method, path, params={}, signature_params=params)
connection.send(method.to_sym, path, params, &request_setup).env
rescue Faraday::Error::ClientError
raise Twitter::Error::ClientError
rescue MultiJson::DecodeError
raise Twitter::Error::DecodeError
rescue JSON::ParserError
raise Twitter::Error::ParserError
end

# Returns a Faraday::Connection object
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Default
builder.use Faraday::Request::UrlEncoded
# Handle 4xx server responses
builder.use Twitter::Response::RaiseError, Twitter::Error::ClientError
# Parse JSON response bodies using MultiJson
# Parse JSON response bodies
builder.use Twitter::Response::ParseJson
# Handle 5xx server responses
builder.use Twitter::Response::RaiseError, Twitter::Error::ServerError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Twitter
class Error
# Raised when JSON parsing fails
class DecodeError < Twitter::Error
class ParserError < Twitter::Error
end
end
end
4 changes: 2 additions & 2 deletions lib/twitter/response/parse_json.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'faraday'
require 'multi_json'
require 'json'

module Twitter
module Response
Expand All @@ -10,7 +10,7 @@ def parse(body)
when /\A^\s*$\z/, nil
nil
else
MultiJson.decode(body, symbolize_keys: true)
JSON.parse(body, symbolize_names: true)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/twitter/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
subject.stub!(:connection).and_raise(Faraday::Error::ClientError.new("Oops"))
expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error::ClientError
end
it "catches MultiJson::DecodeError errors" do
subject.stub!(:connection).and_raise(MultiJson::DecodeError.new("unexpected token", [], "<!DOCTYPE html>"))
expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error::DecodeError
it "catches JSON::ParserError errors" do
subject.stub!(:connection).and_raise(JSON::ParserError.new("unexpected token"))
expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error::ParserError
end
end

Expand Down
1 change: 0 additions & 1 deletion twitter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require 'twitter/version'

Gem::Specification.new do |spec|
spec.add_dependency 'faraday', ['~> 0.8', '< 0.10']
spec.add_dependency 'multi_json', '~> 1.0'
spec.add_dependency 'simple_oauth', '~> 0.2'
spec.add_development_dependency 'bundler', '~> 1.0'
spec.authors = ["John Nunemaker", "Wynn Netherland", "Erik Michaels-Ober", "Steve Richert", "Steve Agalloco"]
Expand Down

0 comments on commit e5fc292

Please sign in to comment.