Merge pull request #106 from stripe/replace-multi-json-with-json

Replace multi_json with json
This commit is contained in:
Andrew Thorp 2014-01-29 17:49:41 -08:00
commit 9b3a3a020b
6 changed files with 14 additions and 36 deletions

View File

@ -15,12 +15,12 @@ If you want to build the gem from source:
* Ruby 1.8.7 or above. (Ruby 1.8.6 may work if you load
ActiveSupport.)
* rest-client, multi_json
* rest-client, json
== Mirrors
The stripe gem is mirrored on Rubygems, so you should be able to
install it via <tt>gem install stripe</tt> if desired. We recommend using
install it via <tt>gem install stripe</tt> if desired. We recommend using
the https://code.stripe.com mirror so all code is fetched over SSL.
Note that if you are installing via bundler, you should be sure to use the https
@ -29,7 +29,7 @@ comprimised in transit and alter the code of gems fetched securely over https:
source 'https://code.stripe.com'
source 'https://rubygems.org'
gem 'rails'
gem 'stripe'

View File

@ -4,7 +4,7 @@ require 'cgi'
require 'set'
require 'openssl'
require 'rest_client'
require 'multi_json'
require 'json'
# Version
require 'stripe/version'
@ -17,7 +17,6 @@ require 'stripe/api_operations/list'
# Resources
require 'stripe/util'
require 'stripe/json'
require 'stripe/stripe_object'
require 'stripe/api_resource'
require 'stripe/singleton_api_resource'
@ -180,7 +179,7 @@ module Stripe
headers[:stripe_version] = api_version if api_version
begin
headers.update(:x_stripe_client_user_agent => Stripe::JSON.dump(user_agent))
headers.update(:x_stripe_client_user_agent => JSON.generate(user_agent))
rescue => e
headers.update(:x_stripe_client_raw_user_agent => user_agent.inspect,
:error => "#{e} (#{e.class})")
@ -195,8 +194,8 @@ module Stripe
begin
# Would use :symbolize_names => true, but apparently there is
# some library out there that makes symbolize_names not work.
response = Stripe::JSON.load(response.body)
rescue MultiJson::DecodeError
response = JSON.parse(response.body)
rescue JSON::ParserError
raise general_api_error(response.code, response.body)
end
@ -210,11 +209,11 @@ module Stripe
def self.handle_api_error(rcode, rbody)
begin
error_obj = Stripe::JSON.load(rbody)
error_obj = JSON.parse(rbody)
error_obj = Util.symbolize_names(error_obj)
error = error_obj[:error] or raise StripeError.new # escape from parsing
rescue MultiJson::DecodeError, StripeError
rescue JSON::ParserError, StripeError
raise general_api_error(rcode, rbody)
end

View File

@ -1,21 +0,0 @@
module Stripe
module JSON
if MultiJson.respond_to?(:dump)
def self.dump(*args)
MultiJson.dump(*args)
end
def self.load(*args)
MultiJson.load(*args)
end
else
def self.dump(*args)
MultiJson.encode(*args)
end
def self.load(*args)
MultiJson.decode(*args)
end
end
end
end

View File

@ -36,12 +36,12 @@ module Stripe
end
def to_s(*args)
Stripe::JSON.dump(@values, :pretty => true)
JSON.pretty_generate(@values)
end
def inspect()
id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + Stripe::JSON.dump(@values, :pretty => true)
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
end
def refresh_from(values, api_key, partial=false)
@ -87,7 +87,7 @@ module Stripe
end
def to_json(*a)
Stripe::JSON.dump(@values)
JSON.generate(@values)
end
def as_json(*a)

View File

@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency('rest-client', '~> 1.4')
s.add_dependency('mime-types', '~> 1.25')
s.add_dependency('multi_json', '>= 1.0.4', '< 2')
s.add_dependency('json', '~> 1.8.1')
s.add_development_dependency('mocha', '~> 0.13.2')
s.add_development_dependency('shoulda', '~> 3.4.0')

View File

@ -26,7 +26,7 @@ end
def test_response(body, code=200)
# When an exception is raised, restclient clobbers method_missing. Hence we
# can't just use the stubs interface.
body = MultiJson.dump(body) if !(body.kind_of? String)
body = JSON.generate(body) if !(body.kind_of? String)
m = mock
m.instance_variable_set('@stripe_values', { :body => body, :code => code })
def m.body; @stripe_values[:body]; end