From c651d69674202e1bb521db9dbf49500e250228ce Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Tue, 24 Apr 2012 14:39:25 +0300 Subject: [PATCH] Updated to avoid deprecation of encode and decode methods in multi_json gem. --- lib/google/api_client.rb | 8 ++++---- lib/google/api_client/client_secrets.rb | 4 ++-- lib/google/api_client/reference.rb | 2 +- lib/google/api_client/result.rb | 2 +- spec/google/api_client/discovery_spec.rb | 2 +- tasks/gem.rake | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index f6ece9bb9..84aac1d6d 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -281,7 +281,7 @@ module Google "Expected String or StringIO, got #{discovery_document.class}." end @discovery_documents["#{api}:#{version}"] = - MultiJson.decode(discovery_document) + MultiJson.load(discovery_document) end ## @@ -297,7 +297,7 @@ module Google ) response = self.transmit(:request => request) if response.status >= 200 && response.status < 300 - MultiJson.decode(response.body) + MultiJson.load(response.body) elsif response.status >= 400 case response.status when 400...500 @@ -331,7 +331,7 @@ module Google ) response = self.transmit(:request => request) if response.status >= 200 && response.status < 300 - MultiJson.decode(response.body) + MultiJson.load(response.body) elsif response.status >= 400 case response.status when 400...500 @@ -484,7 +484,7 @@ module Google response = self.transmit(:request => request) if response.status >= 200 && response.status < 300 @certificates.merge!( - Hash[MultiJson.decode(response.body).map do |key, cert| + Hash[MultiJson.load(response.body).map do |key, cert| [key, OpenSSL::X509::Certificate.new(cert)] end] ) diff --git a/lib/google/api_client/client_secrets.rb b/lib/google/api_client/client_secrets.rb index ab299d614..3a4916030 100644 --- a/lib/google/api_client/client_secrets.rb +++ b/lib/google/api_client/client_secrets.rb @@ -39,7 +39,7 @@ module Google search_path = File.expand_path(File.join(search_path, '..')) end end - data = File.open(filename, 'r') { |file| MultiJson.decode(file.read) } + data = File.open(filename, 'r') { |file| MultiJson.load(file.read) } return self.new(data) end @@ -77,7 +77,7 @@ module Google ) def to_json - return MultiJson.encode({ + return MultiJson.dump({ self.flow => ({ 'client_id' => self.client_id, 'client_secret' => self.client_secret, diff --git a/lib/google/api_client/reference.rb b/lib/google/api_client/reference.rb index 4ae201507..5fe0caa85 100644 --- a/lib/google/api_client/reference.rb +++ b/lib/google/api_client/reference.rb @@ -103,7 +103,7 @@ module Google def serialize_body(body) return body.to_json if body.respond_to?(:to_json) - return MultiJson.encode(options[:body_object].to_hash) if body.respond_to?(:to_hash) + return MultiJson.dump(options[:body_object].to_hash) if body.respond_to?(:to_hash) raise TypeError, 'Could not convert body object to JSON.' + 'Must respond to :to_json or :to_hash.' end diff --git a/lib/google/api_client/result.rb b/lib/google/api_client/result.rb index de1bf6014..d516b8034 100644 --- a/lib/google/api_client/result.rb +++ b/lib/google/api_client/result.rb @@ -63,7 +63,7 @@ module Google data = self.body case media_type when 'application/json' - data = MultiJson.decode(data) + data = MultiJson.load(data) # Strip data wrapper, if present data = data['data'] if data.has_key?('data') else diff --git a/spec/google/api_client/discovery_spec.rb b/spec/google/api_client/discovery_spec.rb index fdf1734b1..63bb2a5fb 100644 --- a/spec/google/api_client/discovery_spec.rb +++ b/spec/google/api_client/discovery_spec.rb @@ -289,7 +289,7 @@ describe Google::APIClient do result = @client.execute( @prediction.training.insert, {}, - MultiJson.encode({"id" => "bucket/object"}), + MultiJson.dump({"id" => "bucket/object"}), {'Content-Type' => 'application/json'} ) result.request.headers['Content-Type'].should == 'application/json' diff --git a/tasks/gem.rake b/tasks/gem.rake index 82afdb229..e52b11e42 100644 --- a/tasks/gem.rake +++ b/tasks/gem.rake @@ -28,7 +28,7 @@ namespace :gem do s.add_runtime_dependency('addressable', '>= 2.2.3') s.add_runtime_dependency('autoparse', '>= 0.3.1') s.add_runtime_dependency('faraday', '~> 0.7.0') - s.add_runtime_dependency('multi_json', '>= 1.0.0') + s.add_runtime_dependency('multi_json', '>= 1.3.0') s.add_runtime_dependency('extlib', '>= 0.9.15') # Dependencies used in the CLI