From f2bd2404d1882a6244afea0836614146331dab56 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sun, 5 May 2013 11:38:54 -0700 Subject: [PATCH] Revert "Updated gem spec to require json rather than multi_json" This reverts commits: 66638b25d76a5eb737c9a41ed9b4847841549d50, 3f0314dbd1972051e0f705e8f83813e7e2305e46, and 18ce4b7eca41ea75d45564466e4d44076128981e. Since google-api-client was added as a dependency in afa9b025e9a1c47488, multi_json is a de facto dependency of fog, so this is a needless layer. If #1034 is still an issue, I'd be happy to ship a version of multi_json that requires rubygems >= 1.3.5. --- Gemfile | 2 - fog.gemspec | 2 +- lib/fog/core/json.rb | 54 ++-------------- lib/fog/dreamhost/dns.rb | 4 +- lib/fog/hp.rb | 2 +- lib/fog/openstack/identity.rb | 3 +- lib/fog/openstack/image.rb | 5 +- lib/fog/openstack/network.rb | 4 +- .../requests/compute/allocate_address.rb | 2 +- .../requests/compute/attach_volume.rb | 2 +- .../requests/compute/boot_from_snapshot.rb | 2 +- .../requests/compute/create_flavor.rb | 2 +- .../requests/compute/create_key_pair.rb | 2 +- .../requests/compute/create_security_group.rb | 2 +- .../compute/create_security_group_rule.rb | 2 +- .../requests/compute/create_volume.rb | 2 +- .../compute/create_volume_snapshot.rb | 2 +- .../requests/compute/list_tenants.rb | 2 +- .../requests/compute/update_quota.rb | 2 +- .../identity/create_ec2_credential.rb | 2 +- .../requests/identity/create_role.rb | 2 +- .../requests/identity/create_user.rb | 2 +- .../requests/identity/update_user.rb | 2 +- .../requests/image/update_image_members.rb | 2 +- .../requests/volume/create_volume.rb | 2 +- .../requests/volume/create_volume_snapshot.rb | 2 +- lib/fog/openstack/volume.rb | 5 +- lib/fog/rackspace.rb | 2 +- lib/fog/rackspace/compute_v2.rb | 12 ++-- lib/fog/riakcs.rb | 4 +- lib/fog/riakcs/provisioning.rb | 4 +- .../requests/provisioning/create_user.rb | 4 +- .../riakcs/requests/provisioning/get_user.rb | 2 +- .../requests/provisioning/list_users.rb | 2 +- lib/fog/riakcs/requests/usage/get_usage.rb | 2 +- lib/fog/riakcs/usage.rb | 1 + lib/tasks/changelog_task.rb | 1 + tests/core/json_tests.rb | 62 ------------------- 38 files changed, 61 insertions(+), 152 deletions(-) delete mode 100644 tests/core/json_tests.rb diff --git a/Gemfile b/Gemfile index d08351613..b4e2a20bb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source "https://rubygems.org" gemspec - -gem "multi_json", '~>1.0' diff --git a/fog.gemspec b/fog.gemspec index 3187a6241..6c2705be7 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_dependency('builder') s.add_dependency('excon', '~>0.20') s.add_dependency('formatador', '~>0.2.0') - s.add_dependency('json', '~>1.7') + s.add_dependency('multi_json', '~>1.0') s.add_dependency('mime-types') s.add_dependency('net-scp', '~>1.1') s.add_dependency('net-ssh', '>=2.1.3') diff --git a/lib/fog/core/json.rb b/lib/fog/core/json.rb index e7b8a75c2..7048854d8 100644 --- a/lib/fog/core/json.rb +++ b/lib/fog/core/json.rb @@ -1,51 +1,7 @@ -require 'singleton' -require 'fog/core/logger' +require 'multi_json' module Fog - class JSON - include Singleton - - class LoadError < StandardError - attr_reader :data - def initialize(message='', backtrace=[], data='') - super(message) - self.set_backtrace(backtrace) - @data = data - end - end - - module LegacyJSON - def encode(obj) - ::JSON.generate(obj) - end - - def decode(obj) - ::JSON.parse(obj) - rescue ::JSON::ParserError => e - raise LoadError.new(e.message, e.backtrace, obj) - end - end - - module NewJSON - def encode(obj) - ::MultiJson.encode(obj) - end - - def decode(obj) - ::MultiJson.decode(obj) - rescue MultiJson::LoadError => e - raise LoadError.new(e.message, e.backtrace, obj) - end - end - - begin - require 'multi_json' - include NewJSON - rescue Exception - Fog::Logger.deprecation "Defaulting to json library for json parsing. Please consider using multi_json library for the greatest performance/flexibility." - require 'json' - include LegacyJSON - end + module JSON def self.sanitize(data) case data @@ -64,12 +20,14 @@ module Fog # Do the MultiJson introspection at this level so we can define our encode/decode methods and perform # the introspection only once rather than once per call. + def self.encode(obj) - Fog::JSON.instance.encode(obj) + MultiJson.encode(obj) end def self.decode(obj) - Fog::JSON.instance.decode(obj) + MultiJson.decode(obj) end + end end diff --git a/lib/fog/dreamhost/dns.rb b/lib/fog/dreamhost/dns.rb index a297cc132..2dc8b4f07 100644 --- a/lib/fog/dreamhost/dns.rb +++ b/lib/fog/dreamhost/dns.rb @@ -47,6 +47,8 @@ module Fog class Real def initialize(options={}) + require 'multi_json' + @dreamhost_api_key = options[:dreamhost_api_key] if options[:dreamhost_url] uri = URI.parse(options[:dreamhost_url]) @@ -71,7 +73,7 @@ module Fog response = @connection.request(params) unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end if response.body['result'] != 'success' raise response.body['data'] diff --git a/lib/fog/hp.rb b/lib/fog/hp.rb index 26c51a2ab..d90e2747a 100644 --- a/lib/fog/hp.rb +++ b/lib/fog/hp.rb @@ -25,7 +25,7 @@ module Fog if message.nil? and !data.values.first.nil? message = data.values.first['message'] end - rescue Fog::JSON::LoadError + rescue MultiJson::DecodeError message = error.response.body #### body is not in JSON format, so just return as is end end diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index be7527651..5edfe0095 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -95,6 +95,7 @@ module Fog end def initialize(options={}) + require 'multi_json' @openstack_username = options[:openstack_username] || 'admin' @openstack_tenant = options[:openstack_tenant] || 'admin' @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @@ -245,7 +246,7 @@ module Fog end end unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index df9eca4bc..e252f4109 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -46,6 +46,7 @@ module Fog end def initialize(options={}) + require 'multi_json' @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @@ -93,6 +94,8 @@ module Fog attr_reader :current_tenant def initialize(options={}) + require 'multi_json' + @openstack_auth_token = options[:openstack_auth_token] unless @openstack_auth_token @@ -165,7 +168,7 @@ module Fog end end unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/openstack/network.rb b/lib/fog/openstack/network.rb index c3fb3a88f..1a39a3e4b 100644 --- a/lib/fog/openstack/network.rb +++ b/lib/fog/openstack/network.rb @@ -113,6 +113,8 @@ module Fog attr_reader :current_tenant def initialize(options={}) + require 'multi_json' + @openstack_auth_token = options[:openstack_auth_token] unless @openstack_auth_token @@ -185,7 +187,7 @@ module Fog end end unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/openstack/requests/compute/allocate_address.rb b/lib/fog/openstack/requests/compute/allocate_address.rb index 5d1cb4085..a86f25662 100644 --- a/lib/fog/openstack/requests/compute/allocate_address.rb +++ b/lib/fog/openstack/requests/compute/allocate_address.rb @@ -6,7 +6,7 @@ module Fog def allocate_address(pool = nil) request( - :body => Fog::JSON.encode({'pool' => pool}), + :body => MultiJson.encode({'pool' => pool}), :expects => [200, 202], :method => 'POST', :path => 'os-floating-ips.json' diff --git a/lib/fog/openstack/requests/compute/attach_volume.rb b/lib/fog/openstack/requests/compute/attach_volume.rb index 3a45abaa3..f29a45d9d 100644 --- a/lib/fog/openstack/requests/compute/attach_volume.rb +++ b/lib/fog/openstack/requests/compute/attach_volume.rb @@ -11,7 +11,7 @@ module Fog } } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "servers/%s/os-volume_attachments" % [server_id] diff --git a/lib/fog/openstack/requests/compute/boot_from_snapshot.rb b/lib/fog/openstack/requests/compute/boot_from_snapshot.rb index a79fb0d81..7911239d1 100644 --- a/lib/fog/openstack/requests/compute/boot_from_snapshot.rb +++ b/lib/fog/openstack/requests/compute/boot_from_snapshot.rb @@ -29,7 +29,7 @@ module Fog end request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => '/os-volumes_boot.json' diff --git a/lib/fog/openstack/requests/compute/create_flavor.rb b/lib/fog/openstack/requests/compute/create_flavor.rb index 8bf01e4e7..bd81c8394 100644 --- a/lib/fog/openstack/requests/compute/create_flavor.rb +++ b/lib/fog/openstack/requests/compute/create_flavor.rb @@ -35,7 +35,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => 200, :method => 'POST', :path => 'flavors' diff --git a/lib/fog/openstack/requests/compute/create_key_pair.rb b/lib/fog/openstack/requests/compute/create_key_pair.rb index e53efb9cf..e8a601ab0 100644 --- a/lib/fog/openstack/requests/compute/create_key_pair.rb +++ b/lib/fog/openstack/requests/compute/create_key_pair.rb @@ -14,7 +14,7 @@ module Fog data['keypair']['public_key'] = public_key unless public_key.nil? request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => 200, :method => 'POST', :path => 'os-keypairs.json' diff --git a/lib/fog/openstack/requests/compute/create_security_group.rb b/lib/fog/openstack/requests/compute/create_security_group.rb index 1a266e12c..10fd45915 100644 --- a/lib/fog/openstack/requests/compute/create_security_group.rb +++ b/lib/fog/openstack/requests/compute/create_security_group.rb @@ -12,7 +12,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => 200, :method => 'POST', :path => 'os-security-groups.json' diff --git a/lib/fog/openstack/requests/compute/create_security_group_rule.rb b/lib/fog/openstack/requests/compute/create_security_group_rule.rb index 1903902ab..84d3e5f6a 100644 --- a/lib/fog/openstack/requests/compute/create_security_group_rule.rb +++ b/lib/fog/openstack/requests/compute/create_security_group_rule.rb @@ -18,7 +18,7 @@ module Fog request( :expects => 200, :method => 'POST', - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :path => 'os-security-group-rules.json' ) end diff --git a/lib/fog/openstack/requests/compute/create_volume.rb b/lib/fog/openstack/requests/compute/create_volume.rb index 6449d8504..829e2d7c3 100644 --- a/lib/fog/openstack/requests/compute/create_volume.rb +++ b/lib/fog/openstack/requests/compute/create_volume.rb @@ -17,7 +17,7 @@ module Fog data['volume'][key] = options[key] end request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "os-volumes" diff --git a/lib/fog/openstack/requests/compute/create_volume_snapshot.rb b/lib/fog/openstack/requests/compute/create_volume_snapshot.rb index f2e1ced98..c5f9a9e47 100644 --- a/lib/fog/openstack/requests/compute/create_volume_snapshot.rb +++ b/lib/fog/openstack/requests/compute/create_volume_snapshot.rb @@ -14,7 +14,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "os-snapshots" diff --git a/lib/fog/openstack/requests/compute/list_tenants.rb b/lib/fog/openstack/requests/compute/list_tenants.rb index ae37267ed..d840ebe57 100644 --- a/lib/fog/openstack/requests/compute/list_tenants.rb +++ b/lib/fog/openstack/requests/compute/list_tenants.rb @@ -11,7 +11,7 @@ module Fog :method => 'GET', :path => '/v2.0/tenants' }) - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) response end end diff --git a/lib/fog/openstack/requests/compute/update_quota.rb b/lib/fog/openstack/requests/compute/update_quota.rb index 51f59b296..f5217d490 100644 --- a/lib/fog/openstack/requests/compute/update_quota.rb +++ b/lib/fog/openstack/requests/compute/update_quota.rb @@ -6,7 +6,7 @@ module Fog def update_quota(tenant_id, options = {}) options['tenant_id'] = tenant_id request( - :body => Fog::JSON.encode({ 'quota_set' => options }), + :body => MultiJson.encode({ 'quota_set' => options }), :expects => 200, :method => 'PUT', :path => "/os-quota-sets/#{tenant_id}" diff --git a/lib/fog/openstack/requests/identity/create_ec2_credential.rb b/lib/fog/openstack/requests/identity/create_ec2_credential.rb index dc20e9896..2bf9e24a3 100644 --- a/lib/fog/openstack/requests/identity/create_ec2_credential.rb +++ b/lib/fog/openstack/requests/identity/create_ec2_credential.rb @@ -26,7 +26,7 @@ module Fog data = { 'tenant_id' => tenant_id } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "users/#{user_id}/credentials/OS-EC2" diff --git a/lib/fog/openstack/requests/identity/create_role.rb b/lib/fog/openstack/requests/identity/create_role.rb index 79c25a66c..1223128e3 100644 --- a/lib/fog/openstack/requests/identity/create_role.rb +++ b/lib/fog/openstack/requests/identity/create_role.rb @@ -10,7 +10,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => '/OS-KSADM/roles' diff --git a/lib/fog/openstack/requests/identity/create_user.rb b/lib/fog/openstack/requests/identity/create_user.rb index c4996af8b..1e0104898 100644 --- a/lib/fog/openstack/requests/identity/create_user.rb +++ b/lib/fog/openstack/requests/identity/create_user.rb @@ -15,7 +15,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => '/users' diff --git a/lib/fog/openstack/requests/identity/update_user.rb b/lib/fog/openstack/requests/identity/update_user.rb index a1f8fbab1..4a11bd44d 100644 --- a/lib/fog/openstack/requests/identity/update_user.rb +++ b/lib/fog/openstack/requests/identity/update_user.rb @@ -6,7 +6,7 @@ module Fog def update_user(user_id, options = {}) url = options.delete('url') || "/users/#{user_id}" request( - :body => Fog::JSON.encode({ 'user' => options }), + :body => MultiJson.encode({ 'user' => options }), :expects => 200, :method => 'PUT', :path => url diff --git a/lib/fog/openstack/requests/image/update_image_members.rb b/lib/fog/openstack/requests/image/update_image_members.rb index 741cf9ad1..a7010fd61 100644 --- a/lib/fog/openstack/requests/image/update_image_members.rb +++ b/lib/fog/openstack/requests/image/update_image_members.rb @@ -11,7 +11,7 @@ module Fog data = { 'memberships' => members } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'PUT', :path => "images/#{image_id}/members" diff --git a/lib/fog/openstack/requests/volume/create_volume.rb b/lib/fog/openstack/requests/volume/create_volume.rb index 4a71799d0..116aa8a56 100644 --- a/lib/fog/openstack/requests/volume/create_volume.rb +++ b/lib/fog/openstack/requests/volume/create_volume.rb @@ -17,7 +17,7 @@ module Fog data['volume'][key] = options[key] end request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "volumes" diff --git a/lib/fog/openstack/requests/volume/create_volume_snapshot.rb b/lib/fog/openstack/requests/volume/create_volume_snapshot.rb index ada07c8e9..1d202eb04 100644 --- a/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +++ b/lib/fog/openstack/requests/volume/create_volume_snapshot.rb @@ -14,7 +14,7 @@ module Fog } request( - :body => Fog::JSON.encode(data), + :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "snapshots" diff --git a/lib/fog/openstack/volume.rb b/lib/fog/openstack/volume.rb index bb2b0b7a9..9b66e2e84 100644 --- a/lib/fog/openstack/volume.rb +++ b/lib/fog/openstack/volume.rb @@ -56,6 +56,7 @@ module Fog end def initialize(options={}) + require 'multi_json' @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @@ -102,6 +103,8 @@ module Fog attr_reader :current_tenant def initialize(options={}) + require 'multi_json' + @openstack_auth_token = options[:openstack_auth_token] unless @openstack_auth_token @@ -174,7 +177,7 @@ module Fog end end unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 0d2398ba3..7c996369d 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'core') +require 'fog/core' require 'fog/rackspace/mock_data' require 'fog/rackspace/service' require 'fog/rackspace/errors' diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index 165936315..b42a5a739 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -98,7 +98,7 @@ module Fog request :delete_network class Mock < Fog::Rackspace::Service - include Fog::Rackspace::MockData + include Fog::Rackspace::MockData def initialize(options) @rackspace_api_key = options[:rackspace_api_key] @@ -122,7 +122,7 @@ module Fog end class Real < Fog::Rackspace::Service - + def initialize(options = {}) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] @@ -134,7 +134,7 @@ module Fog authenticate deprecation_warnings(options) - + @persistent = options[:persistent] || false @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end @@ -163,13 +163,13 @@ module Fog unless response.body.empty? begin response.body = Fog::JSON.decode(response.body) - rescue Fog::JSON::LoadError + rescue MultiJson::DecodeError => e response.body = {} end end response end - + def authenticate options = { :rackspace_api_key => @rackspace_api_key, @@ -228,7 +228,7 @@ module Fog def append_tenant_v1(credentials) account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1] - + endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT @uri = URI.parse(endpoint) @uri.path = "#{@uri.path}/#{account_id}" diff --git a/lib/fog/riakcs.rb b/lib/fog/riakcs.rb index 9d1d13324..d7e8e70b5 100644 --- a/lib/fog/riakcs.rb +++ b/lib/fog/riakcs.rb @@ -71,9 +71,9 @@ module Fog module UserUtils def update_riakcs_user(key_id, user) - response = @s3_connection.put_object('riak-cs', "user/#{key_id}", Fog::JSON.encode(user), { 'Content-Type' => 'application/json' }) + response = @s3_connection.put_object('riak-cs', "user/#{key_id}", MultiJson.encode(user), { 'Content-Type' => 'application/json' }) if !response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/riakcs/provisioning.rb b/lib/fog/riakcs/provisioning.rb index a5e12250e..88765c54b 100644 --- a/lib/fog/riakcs/provisioning.rb +++ b/lib/fog/riakcs/provisioning.rb @@ -48,6 +48,8 @@ module Fog def initialize(options = {}) require 'mime/types' + require 'multi_json' + configure_uri_options(options) @riakcs_access_key_id = options[:riakcs_access_key_id] @riakcs_secret_access_key = options[:riakcs_secret_access_key] @@ -87,7 +89,7 @@ module Fog end end if !response.body.empty? && parse_response - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/riakcs/requests/provisioning/create_user.rb b/lib/fog/riakcs/requests/provisioning/create_user.rb index 969331460..b98fd9dc3 100644 --- a/lib/fog/riakcs/requests/provisioning/create_user.rb +++ b/lib/fog/riakcs/requests/provisioning/create_user.rb @@ -3,7 +3,7 @@ module Fog class Provisioning class Real def create_user(email, name, options = {}) - payload = Fog::JSON.encode({ :email => email, :name => name }) + payload = MultiJson.encode({ :email => email, :name => name }) headers = { 'Content-Type' => 'application/json' } if(options[:anonymous]) @@ -20,7 +20,7 @@ module Fog if !response.body.empty? case response.headers['Content-Type'] when 'application/json' - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end end response diff --git a/lib/fog/riakcs/requests/provisioning/get_user.rb b/lib/fog/riakcs/requests/provisioning/get_user.rb index 914861d7b..793dca95a 100644 --- a/lib/fog/riakcs/requests/provisioning/get_user.rb +++ b/lib/fog/riakcs/requests/provisioning/get_user.rb @@ -7,7 +7,7 @@ module Fog def get_user(key_id) response = @s3_connection.get_object('riak-cs', "user/#{key_id}", { 'Accept' => 'application/json' }) - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) response end end diff --git a/lib/fog/riakcs/requests/provisioning/list_users.rb b/lib/fog/riakcs/requests/provisioning/list_users.rb index cd3a2dba6..c747b8b2d 100644 --- a/lib/fog/riakcs/requests/provisioning/list_users.rb +++ b/lib/fog/riakcs/requests/provisioning/list_users.rb @@ -10,7 +10,7 @@ module Fog boundary = extract_boundary(response.headers['Content-Type']) parts = parse(response.body, boundary) - decoded = parts.map { |part| Fog::JSON.decode(part[:body]) } + decoded = parts.map { |part| MultiJson.decode(part[:body]) } response.body = decoded.flatten diff --git a/lib/fog/riakcs/requests/usage/get_usage.rb b/lib/fog/riakcs/requests/usage/get_usage.rb index 78be7f797..ee35357ed 100644 --- a/lib/fog/riakcs/requests/usage/get_usage.rb +++ b/lib/fog/riakcs/requests/usage/get_usage.rb @@ -37,7 +37,7 @@ module Fog response = @connection.get_object('riak-cs', ["usage", request_uri(access_key_id, options)].join("/")) if !response.body.empty? - response.body = Fog::JSON.decode(response.body) + response.body = MultiJson.decode(response.body) end response end diff --git a/lib/fog/riakcs/usage.rb b/lib/fog/riakcs/usage.rb index 3df9d3802..51df897f0 100644 --- a/lib/fog/riakcs/usage.rb +++ b/lib/fog/riakcs/usage.rb @@ -42,6 +42,7 @@ module Fog def initialize(options = {}) require 'mime/types' + require 'multi_json' configure_uri_options(options) @riakcs_access_key_id = options[:riakcs_access_key_id] diff --git a/lib/tasks/changelog_task.rb b/lib/tasks/changelog_task.rb index f8c9624b8..24b8ad922 100644 --- a/lib/tasks/changelog_task.rb +++ b/lib/tasks/changelog_task.rb @@ -14,6 +14,7 @@ module Fog changelog << ('=' * changelog[0].length) changelog << '' + require 'multi_json' github_repo_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog', :headers => {'User-Agent' => 'geemus'}).body) data = github_repo_data.reject {|key, value| !['forks', 'open_issues', 'watchers'].include?(key)} github_collaborator_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog/collaborators', :headers => {'User-Agent' => 'geemus'}).body) diff --git a/tests/core/json_tests.rb b/tests/core/json_tests.rb deleted file mode 100644 index 480003c40..000000000 --- a/tests/core/json_tests.rb +++ /dev/null @@ -1,62 +0,0 @@ -Shindo.tests('Fog#JSON', 'core') do - -TEST_HASH = {'quantity' => 4} -VALID_JSON = "{\"quantity\":4}" - - tests('LegacyJSON') do - - begin - require 'json' - rescue => e - returns('Failed to load JSON library', true) { false } - end - - pending? unless defined? ::JSON - - class LegacyJSONTester - include Fog::JSON::LegacyJSON - end - - @tester = LegacyJSONTester.new - tests('encode').returns(VALID_JSON) do - @tester.encode(TEST_HASH) - end - - tests('decode').returns(TEST_HASH) do - @tester.decode(VALID_JSON) - end - - tests('invalid decode').raises(Fog::JSON::LoadError) do - @tester.decode("I am not json") - end - end - - tests('NewJSON') do - - begin - require 'multi_json' - rescue => e - returns('Failed to load multi_json library', true) { false } - end - - pending unless defined? ::MultiJson - - class NewJSONTester - include Fog::JSON::NewJSON - end - - @tester = NewJSONTester.new - tests('encode').returns(VALID_JSON) do - @tester.encode(TEST_HASH) - end - - tests('decode').returns(TEST_HASH) do - @tester.decode(VALID_JSON) - end - - tests('invalid decode').raises(Fog::JSON::LoadError) do - @tester.decode("I am not json") - end - - end -end \ No newline at end of file