Sha256: 4eacf5b70c8409e72213ca0f4a05507ad98cbbf95b8dc9876a37cb6777000144

Contents?: true

Size: 1.14 KB

Versions: 28

Compression:

Stored size: 1.14 KB

Contents

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

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
fog-maestrodev-1.20.0.20140305101839 lib/fog/json.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/json.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/json.rb
fog-1.20.0 lib/fog/json.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/json.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/json.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/json.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/json.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/json.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/json.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/json.rb
fog-1.19.0 lib/fog/json.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/json.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/json.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/json.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/json.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/json.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/json.rb
fog-maestrodev-1.18.0.20131209090811 lib/fog/json.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/json.rb