Switch from deprecated MultiJson.{encode,decode} to .{dump,load}

Bump gem dependency accordingly
This commit is contained in:
Evan Broder 2012-04-23 10:18:57 -07:00
parent 2e9693eccf
commit 32e619c04a
3 changed files with 8 additions and 8 deletions

View File

@ -193,11 +193,11 @@ module Stripe
obj obj
end end
def to_s(*args); MultiJson.encode(@values, :pretty => true); end def to_s(*args); MultiJson.dump(@values, :pretty => true); end
def inspect() def inspect()
id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : "" id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + MultiJson.encode(@values, :pretty => true) "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + MultiJson.dump(@values, :pretty => true)
end end
def refresh_from(values, api_key, partial=false) def refresh_from(values, api_key, partial=false)
@ -234,7 +234,7 @@ module Stripe
end end
def keys; @values.keys; end def keys; @values.keys; end
def values; @values.values; end def values; @values.values; end
def to_json(*a); MultiJson.encode(@values); end def to_json(*a); MultiJson.dump(@values); end
def to_hash; @values; end def to_hash; @values; end
def each(&blk); @values.each(&blk); end def each(&blk); @values.each(&blk); end
@ -530,7 +530,7 @@ module Stripe
end end
begin begin
headers = { :x_stripe_client_user_agent => MultiJson.encode(ua) }.merge(headers) headers = { :x_stripe_client_user_agent => MultiJson.dump(ua) }.merge(headers)
rescue => e rescue => e
headers = { headers = {
:x_stripe_client_raw_user_agent => ua.inspect, :x_stripe_client_raw_user_agent => ua.inspect,
@ -578,7 +578,7 @@ module Stripe
begin begin
# Would use :symbolize_names => true, but apparently there is # Would use :symbolize_names => true, but apparently there is
# some library out there that makes symbolize_names not work. # some library out there that makes symbolize_names not work.
resp = MultiJson.decode(rbody) resp = MultiJson.load(rbody)
rescue MultiJson::DecodeError rescue MultiJson::DecodeError
raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})", rcode, rbody) raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})", rcode, rbody)
end end
@ -595,7 +595,7 @@ module Stripe
def self.handle_api_error(rcode, rbody) def self.handle_api_error(rcode, rbody)
begin begin
error_obj = MultiJson.decode(rbody) error_obj = MultiJson.load(rbody)
error_obj = Util.symbolize_names(error_obj) error_obj = Util.symbolize_names(error_obj)
error = error_obj[:error] or raise StripeError.new # escape from parsing error = error_obj[:error] or raise StripeError.new # escape from parsing
rescue MultiJson::DecodeError, StripeError rescue MultiJson::DecodeError, StripeError

View File

@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
s.require_paths = %w{lib} s.require_paths = %w{lib}
s.add_dependency('rest-client', '~> 1.4') s.add_dependency('rest-client', '~> 1.4')
s.add_dependency('multi_json', '1.2.0') s.add_dependency('multi_json', '>= 1.3.0')
s.add_development_dependency('mocha') s.add_development_dependency('mocha')
s.add_development_dependency('shoulda') s.add_development_dependency('shoulda')

View File

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