1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Updated gem spec to require json rather than multi_json; Fog::JSON will attempt to load and use multi_json first and then fallback to require json; removed hard coded references to multi_json

This commit is contained in:
Kyle Rames 2013-04-03 08:42:45 -05:00
parent 800ef9fbc0
commit 66638b25d7
11 changed files with 43 additions and 30 deletions

View file

@ -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('multi_json', '~>1.0')
s.add_dependency('json', '~>1.7')
s.add_dependency('mime-types')
s.add_dependency('net-scp', '~>1.1')
s.add_dependency('net-ssh', '>=2.1.3')

View file

@ -1,7 +1,38 @@
require 'multi_json'
require 'singleton'
require 'fog/core/logger'
module Fog
module JSON
class JSON
include Singleton
module LegacyJSON
def encode(obj)
::JSON.generate(obj)
end
def decode(obj)
::JSON.parse(obj)
end
end
module NewJSON
def encode(obj)
MultiJson.encode(obj)
end
def decode(obj)
MultiJson.decode(obj)
end
end
begin
require 'multi_json'
include NewJSON
rescue LoadError
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
def self.sanitize(data)
case data
@ -20,15 +51,12 @@ 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)
MultiJson.encode(obj)
Fog::JSON.instance.encode(obj)
end
def self.decode(obj)
MultiJson.decode(obj)
Fog::JSON.instance.decode(obj)
end
end
end

View file

@ -47,8 +47,6 @@ 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])
@ -73,7 +71,7 @@ module Fog
response = @connection.request(params)
unless response.body.empty?
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
if response.body['result'] != 'success'
raise response.body['data']

View file

@ -96,7 +96,6 @@ 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])
@ -249,7 +248,7 @@ module Fog
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
response
end

View file

@ -44,7 +44,6 @@ 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])
@ -92,8 +91,6 @@ module Fog
attr_reader :current_tenant
def initialize(options={})
require 'multi_json'
@openstack_auth_token = options[:openstack_auth_token]
unless @openstack_auth_token
@ -168,7 +165,7 @@ module Fog
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
response
end

View file

@ -112,8 +112,6 @@ module Fog
attr_reader :current_tenant
def initialize(options={})
require 'multi_json'
@openstack_auth_token = options[:openstack_auth_token]
unless @openstack_auth_token
@ -188,7 +186,7 @@ module Fog
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
response
end

View file

@ -47,7 +47,6 @@ 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])
@ -94,8 +93,6 @@ module Fog
attr_reader :current_tenant
def initialize(options={})
require 'multi_json'
@openstack_auth_token = options[:openstack_auth_token]
unless @openstack_auth_token
@ -170,7 +167,7 @@ module Fog
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
response
end

View file

@ -1,4 +1,4 @@
require 'fog/core'
require File.join(File.dirname(__FILE__), 'core')
require 'fog/rackspace/mock_data'
require 'fog/rackspace/service'

View file

@ -48,8 +48,6 @@ 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]
@ -89,7 +87,7 @@ module Fog
end
end
if !response.body.empty? && parse_response
response.body = MultiJson.decode(response.body)
response.body = Fog::JSON.decode(response.body)
end
response
end

View file

@ -42,7 +42,6 @@ module Fog
def initialize(options = {})
require 'mime/types'
require 'multi_json'
configure_uri_options(options)
@riakcs_access_key_id = options[:riakcs_access_key_id]

View file

@ -14,7 +14,6 @@ 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').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').body)