fog-json 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +8 -0
- data/fog-json.gemspec +27 -0
- data/lib/fog/json.rb +45 -0
- data/lib/fog/json/version.rb +5 -0
- data/test/json_decode_test.rb +17 -0
- data/test/json_encode_test.rb +17 -0
- data/test/json_sanitize_test.rb +32 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e124040466b4421e3122ba4f1677223dec35fe8
|
4
|
+
data.tar.gz: e32250b78befa011a70da8f6863f6a5408309717
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 684744519501cccbdf33f8b7e25b357d859b4c86ce75dcdb8a72eba3bec4e55aa5427f9a8f33aa5f86bd9efeb2ac31fe0980489f68ff66896e4adb4cba49f6af
|
7
|
+
data.tar.gz: c962308b5ff5d20d3c50fc1cf72a1138085a6eb0bf8dd1e598782610f80f031b97dcbeec7a3620e46d5ea6a5f0277cae7ba6c7a7572019fbc42cc605de33be85
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Wes Beary
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Fog::Json
|
2
|
+
|
3
|
+
Extraction of the JSON parsing tools shared between a number of providers in
|
4
|
+
the 'fog' gem.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem "fog-json"
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install fog-json
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
This gem extracts shared code from the `fog` gem (http://github.com/fog/fog)
|
23
|
+
that allows a standard interface to JSON encoding and decoding on top of
|
24
|
+
MultiJson but with errors support.
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( http://github.com/fog/fog-json/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
33
|
+
|
34
|
+
## Versioning
|
35
|
+
|
36
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
|
37
|
+
of this scheme should be reported as bugs. Specifically, if a minor or patch
|
38
|
+
version is released that breaks backward compatibility, that version should be
|
39
|
+
immediately yanked and/or a new version should be immediately released that
|
40
|
+
restores compatibility. Breaking changes to the public API will only be
|
41
|
+
introduced with new major versions. As a result of this policy, you can (and
|
42
|
+
should) specify a dependency on this gem using the [Pessimistic Version
|
43
|
+
Constraint][pvc] with two digits of precision. For example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
spec.add_dependency "fog-json", "~> 1.0"
|
47
|
+
```
|
48
|
+
|
49
|
+
[semver]: http://semver.org/
|
50
|
+
[pvc]: http://docs.rubygems.org/read/chapter/16#page74
|
data/Rakefile
ADDED
data/fog-json.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fog/json/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fog-json"
|
8
|
+
spec.version = Fog::Json::VERSION
|
9
|
+
spec.authors = ["Wesley Beary (geemus)", "Paul Thornthwaite (tokengeek)", "The fog team"]
|
10
|
+
spec.email = ["geemus@gmail.com", "tokengeek@gmail.com"]
|
11
|
+
spec.summary = %q{JSON parsing for fog providers}
|
12
|
+
spec.description = %q{Extraction of the JSON parsing tools shared between a
|
13
|
+
number of providers in the 'fog' gem.}
|
14
|
+
spec.homepage = "http://github.com/fog/fog-json"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "multi_json", "~> 1.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "minitest"
|
27
|
+
end
|
data/lib/fog/json.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "fog/json/version"
|
2
|
+
require "fog/core"
|
3
|
+
require "multi_json"
|
4
|
+
|
5
|
+
module Fog
|
6
|
+
# The {JSON} module includes functionality that is common between APIs using JSON to send and
|
7
|
+
# receive data.
|
8
|
+
#
|
9
|
+
# The intent is to provide common code for provider APIs using JSON but not require it for those
|
10
|
+
# using XML.
|
11
|
+
#
|
12
|
+
module JSON
|
13
|
+
class EncodeError < Fog::Errors::Error; end
|
14
|
+
class DecodeError < Fog::Errors::Error; end
|
15
|
+
|
16
|
+
# This cleans up Time objects to be ISO8601 format
|
17
|
+
#
|
18
|
+
def self.sanitize(data)
|
19
|
+
case data
|
20
|
+
when Array
|
21
|
+
data.map { |datum| sanitize(datum) }
|
22
|
+
when Hash
|
23
|
+
data.each { |key, value| data[key] = sanitize(value) }
|
24
|
+
when ::Time
|
25
|
+
data.strftime("%Y-%m-%dT%H:%M:%SZ")
|
26
|
+
else
|
27
|
+
data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Do the MultiJson introspection at this level so we can define our encode/decode methods and
|
32
|
+
# perform the introspection only once rather than once per call.
|
33
|
+
def self.encode(obj)
|
34
|
+
MultiJson.encode(obj)
|
35
|
+
rescue => err
|
36
|
+
raise EncodeError.slurp(err)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.decode(obj)
|
40
|
+
MultiJson.decode(obj)
|
41
|
+
rescue => err
|
42
|
+
raise DecodeError.slurp(err)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fog/json"
|
3
|
+
|
4
|
+
class TestJSONDecoding < Minitest::Test
|
5
|
+
def test_decode_with_valid_string
|
6
|
+
@json = %q{{"key":"value", "array": ["one", "two", "three"]}}
|
7
|
+
@expected = {
|
8
|
+
"key" => "value",
|
9
|
+
"array" => %W(one two three)
|
10
|
+
}
|
11
|
+
assert_equal @expected, Fog::JSON.decode(@json)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_decode_with_nil
|
15
|
+
assert_raises(Fog::JSON::DecodeError) { Fog::JSON.decode(nil) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fog/json"
|
3
|
+
|
4
|
+
class TestJSONEncoding < Minitest::Test
|
5
|
+
def test_encode_with_valid_hash
|
6
|
+
@hash = {
|
7
|
+
"key" => "value",
|
8
|
+
"array" => %W(one two three)
|
9
|
+
}
|
10
|
+
@expected = %q{{"key":"value","array":["one","two","three"]}}
|
11
|
+
assert_equal @expected, Fog::JSON.encode(@hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_encode_with_bad_input
|
15
|
+
assert_raises(Fog::JSON::EncodeError) { Fog::JSON.encode("\x82\xAC\xEF") }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fog/json"
|
3
|
+
|
4
|
+
class TestJSONSanitizing < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@time = Time.utc(2014, 02, 14, 12, 34, 56)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_sanitize_with_array
|
10
|
+
@data = [@time]
|
11
|
+
@expected = ["2014-02-14T12:34:56Z"]
|
12
|
+
assert_equal @expected, Fog::JSON.sanitize(@data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_sanitize_with_hash
|
16
|
+
@data = { "key" => @time }
|
17
|
+
@expected = { "key" => "2014-02-14T12:34:56Z" }
|
18
|
+
assert_equal @expected, Fog::JSON.sanitize(@data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_sanitize_with_time
|
22
|
+
@data = @time
|
23
|
+
@expected = "2014-02-14T12:34:56Z"
|
24
|
+
assert_equal @expected, Fog::JSON.sanitize(@data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_sanitize_with_string
|
28
|
+
@data = "fog"
|
29
|
+
@expected = "fog"
|
30
|
+
assert_equal @expected, Fog::JSON.sanitize(@data)
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fog-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wesley Beary (geemus)
|
8
|
+
- Paul Thornthwaite (tokengeek)
|
9
|
+
- The fog team
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: multi_json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.5'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.5'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: minitest
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: |-
|
72
|
+
Extraction of the JSON parsing tools shared between a
|
73
|
+
number of providers in the 'fog' gem.
|
74
|
+
email:
|
75
|
+
- geemus@gmail.com
|
76
|
+
- tokengeek@gmail.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- ".gitignore"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- fog-json.gemspec
|
87
|
+
- lib/fog/json.rb
|
88
|
+
- lib/fog/json/version.rb
|
89
|
+
- test/json_decode_test.rb
|
90
|
+
- test/json_encode_test.rb
|
91
|
+
- test/json_sanitize_test.rb
|
92
|
+
homepage: http://github.com/fog/fog-json
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: JSON parsing for fog providers
|
116
|
+
test_files:
|
117
|
+
- test/json_decode_test.rb
|
118
|
+
- test/json_encode_test.rb
|
119
|
+
- test/json_sanitize_test.rb
|
120
|
+
has_rdoc:
|