module Fog::JSON
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.
Public Class Methods
decode(obj)
click to toggle source
# File lib/fog/json.rb, line 39 def self.decode(obj) MultiJson.decode(obj) rescue => err raise DecodeError.slurp(err) end
encode(obj)
click to toggle source
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.
# File lib/fog/json.rb, line 33 def self.encode(obj) MultiJson.encode(obj) rescue => err raise EncodeError.slurp(err) end
sanitize(data)
click to toggle source
This cleans up Time objects to be ISO8601 format
# File lib/fog/json.rb, line 18 def self.sanitize(data) case data when Array data.map { |datum| sanitize(datum) } when Hash data.each { |key, value| data[key] = sanitize(value) } when ::Time data.strftime("%Y-%m-%dT%H:%M:%S%:z") else data end end