fog-json-1.0.0/0000755000076400007640000000000012324651061012266 5ustar pravipravifog-json-1.0.0/LICENSE.txt0000644000076400007640000000205212324651061014110 0ustar pravipraviCopyright (c) 2014 Wes Beary MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-json-1.0.0/checksums.yaml.gz0000444000076400007640000000041612324651061015555 0ustar pravipraviGRe;@EYl`,>ͧ_ff #k"WoB-".^^x>;NˏOiTs-f$XjFħeگS_f"4Ϟ08ᣮ< \ek n<<$be*jS'=:kH\d͸=8 afT}k8v1橭)3r";vB-Ia1`%G:#Ȭ-CpO֢*97NPSfog-json-1.0.0/README.md0000644000076400007640000000273312324651061013552 0ustar pravipravi# Fog::Json Extraction of the JSON parsing tools shared between a number of providers in the 'fog' gem. ## Installation Add this line to your application's Gemfile: gem "fog-json" And then execute: $ bundle Or install it yourself as: $ gem install fog-json ## Usage This gem extracts shared code from the `fog` gem (http://github.com/fog/fog) that allows a standard interface to JSON encoding and decoding on top of MultiJson but with errors support. ## Contributing 1. Fork it ( http://github.com/fog/fog-json/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am "Add some feature"`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request ## Versioning This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision. For example: ```ruby spec.add_dependency "fog-json", "~> 1.0" ``` [semver]: http://semver.org/ [pvc]: http://docs.rubygems.org/read/chapter/16#page74 fog-json-1.0.0/test/0000755000076400007640000000000012324651061013245 5ustar pravipravifog-json-1.0.0/test/json_decode_test.rb0000644000076400007640000000066412324651061017113 0ustar pravipravirequire "minitest/autorun" require "fog/json" class TestJSONDecoding < Minitest::Test def test_decode_with_valid_string @json = %q{{"key":"value", "array": ["one", "two", "three"]}} @expected = { "key" => "value", "array" => %W(one two three) } assert_equal @expected, Fog::JSON.decode(@json) end def test_decode_with_nil assert_raises(Fog::JSON::DecodeError) { Fog::JSON.decode(nil) } end end fog-json-1.0.0/test/json_encode_test.rb0000644000076400007640000000067712324651061017131 0ustar pravipravirequire "minitest/autorun" require "fog/json" class TestJSONEncoding < Minitest::Test def test_encode_with_valid_hash @hash = { "key" => "value", "array" => %W(one two three) } @expected = %q{{"key":"value","array":["one","two","three"]}} assert_equal @expected, Fog::JSON.encode(@hash) end def test_encode_with_bad_input assert_raises(Fog::JSON::EncodeError) { Fog::JSON.encode("\x82\xAC\xEF") } end end fog-json-1.0.0/test/json_sanitize_test.rb0000644000076400007640000000137612324651061017517 0ustar pravipravirequire "minitest/autorun" require "fog/json" class TestJSONSanitizing < Minitest::Test def setup @time = Time.utc(2014, 02, 14, 12, 34, 56) end def test_sanitize_with_array @data = [@time] @expected = ["2014-02-14T12:34:56Z"] assert_equal @expected, Fog::JSON.sanitize(@data) end def test_sanitize_with_hash @data = { "key" => @time } @expected = { "key" => "2014-02-14T12:34:56Z" } assert_equal @expected, Fog::JSON.sanitize(@data) end def test_sanitize_with_time @data = @time @expected = "2014-02-14T12:34:56Z" assert_equal @expected, Fog::JSON.sanitize(@data) end def test_sanitize_with_string @data = "fog" @expected = "fog" assert_equal @expected, Fog::JSON.sanitize(@data) end end fog-json-1.0.0/Gemfile0000644000076400007640000000013512324651061013560 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in fog-json.gemspec gemspec fog-json-1.0.0/metadata.yml0000644000076400007640000000541412324651061014575 0ustar pravipravi--- !ruby/object:Gem::Specification name: fog-json version: !ruby/object:Gem::Version version: 1.0.0 platform: ruby authors: - Wesley Beary (geemus) - Paul Thornthwaite (tokengeek) - The fog team autorequire: bindir: bin cert_chain: [] date: 2014-02-13 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: multi_json requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.5' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.5' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: |- Extraction of the JSON parsing tools shared between a number of providers in the 'fog' gem. email: - geemus@gmail.com - tokengeek@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - Gemfile - LICENSE.txt - README.md - Rakefile - fog-json.gemspec - lib/fog/json.rb - lib/fog/json/version.rb - test/json_decode_test.rb - test/json_encode_test.rb - test/json_sanitize_test.rb homepage: http://github.com/fog/fog-json licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.1 signing_key: specification_version: 4 summary: JSON parsing for fog providers test_files: - test/json_decode_test.rb - test/json_encode_test.rb - test/json_sanitize_test.rb has_rdoc: fog-json-1.0.0/lib/0000755000076400007640000000000012324651061013034 5ustar pravipravifog-json-1.0.0/lib/fog/0000755000076400007640000000000012324651061013607 5ustar pravipravifog-json-1.0.0/lib/fog/json.rb0000644000076400007640000000223712324651061015111 0ustar pravipravirequire "fog/json/version" require "fog/core" require "multi_json" module Fog # 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 # This cleans up Time objects to be ISO8601 format # 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:%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 fog-json-1.0.0/lib/fog/json/0000755000076400007640000000000012324651061014560 5ustar pravipravifog-json-1.0.0/lib/fog/json/version.rb0000644000076400007640000000007112324651061016570 0ustar pravipravimodule Fog module Json VERSION = "1.0.0" end end fog-json-1.0.0/fog-json.gemspec0000644000076400007640000000213612324651061015357 0ustar pravipravi# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/json/version' Gem::Specification.new do |spec| spec.name = "fog-json" spec.version = Fog::Json::VERSION spec.authors = ["Wesley Beary (geemus)", "Paul Thornthwaite (tokengeek)", "The fog team"] spec.email = ["geemus@gmail.com", "tokengeek@gmail.com"] spec.summary = %q{JSON parsing for fog providers} spec.description = %q{Extraction of the JSON parsing tools shared between a number of providers in the 'fog' gem.} spec.homepage = "http://github.com/fog/fog-json" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_dependency "multi_json", "~> 1.0" spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "rake" spec.add_development_dependency "minitest" end fog-json-1.0.0/Rakefile0000644000076400007640000000021712324651061013733 0ustar pravipravirequire "bundler/gem_tasks" require "rake/testtask" task :default => [:test] Rake::TestTask.new do |t| t.pattern = "test/**/*_test.rb" end fog-json-1.0.0/.gitignore0000644000076400007640000000023212324651061014253 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp