mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Use fog-json
This extracts the JSON encoding/decoding wrappers around MultiJson to a separate gem. Providers can use this shared behaviour in their standalone modules as we work through things.
This commit is contained in:
parent
79dd002c0f
commit
6f7e286d68
2 changed files with 2 additions and 48 deletions
|
@ -42,10 +42,11 @@ Gem::Specification.new do |s|
|
|||
## List your runtime dependencies here. Runtime dependencies are those
|
||||
## that are needed for an end user to actually USE your code.
|
||||
s.add_dependency("fog-core")
|
||||
s.add_dependency("fog-json")
|
||||
|
||||
s.add_dependency('builder')
|
||||
s.add_dependency('excon', '~>0.31.0')
|
||||
s.add_dependency('formatador', '~>0.2.0')
|
||||
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')
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
require "multi_json"
|
||||
|
||||
module Fog
|
||||
|
||||
# @note Extracting JSON components out of core is a work in progress.
|
||||
#
|
||||
# The {JSON} module includes functionality that is common between APIs using
|
||||
# JSON to send and receive data.
|
||||
#
|
||||
# The intent is to provide common code for provider APIs using JSON but not
|
||||
# require it for those using XML.
|
||||
#
|
||||
module JSON
|
||||
class EncodeError < Fog::Errors::Error; end
|
||||
class DecodeError < Fog::Errors::Error; end
|
||||
|
||||
def self.sanitize(data)
|
||||
case data
|
||||
when Array
|
||||
data.map {|datum| sanitize(datum)}
|
||||
when Hash
|
||||
for key, value in data
|
||||
data[key] = sanitize(value)
|
||||
end
|
||||
when ::Time
|
||||
data.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
# 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)
|
||||
rescue => err
|
||||
raise EncodeError.slurp(err)
|
||||
end
|
||||
|
||||
def self.decode(obj)
|
||||
MultiJson.decode(obj)
|
||||
rescue => err
|
||||
raise DecodeError.slurp(err)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue