jsonapi 0.1.1.beta2 → 0.1.1.beta6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ced99ef009aee2a4a5473acbc9ee8dc8c53d14b0
4
- data.tar.gz: a9b87f7ef84013e382df467138ebc723790d27d9
3
+ metadata.gz: 988edc569bb3ddbea483619be6102a7126e4a8d4
4
+ data.tar.gz: 784cbf00227eb548ae79feb605b410f9512ba80f
5
5
  SHA512:
6
- metadata.gz: 1b0c8e23de976228e9a08d350d23459d49159422b329c72487261785490f548fa70a14556985d06cb2070c184bbebd1aad0a45505bd482e6ff3710111298f343
7
- data.tar.gz: 6f85d5fe158aa995aa4059166e1143dd7826ddce93d0968aea9e1b7c8f289f4cfc24ab9c9a9c0733d44293d4a5d7df2242ab173e21bc16b0c7552d77493e3876
6
+ metadata.gz: 907eb805965a524ff2ed45729f45d68011589a3de38bda36703425f02df526441e3d4ae49f5cb2d7005b3964ee986400e74a88643ec211456232df0d826ed79e
7
+ data.tar.gz: a4cf7fbebae712a81c0c961f81c8a14cf9c49860fcbac14b463d969314883abe1758de2b053db2ae7fafb7e1c788d701d922b7b1d46c68285e916430800ee97e
data/README.md CHANGED
@@ -1,133 +1,31 @@
1
1
  # jsonapi
2
- Ruby gem for parsing/validating [JSON API](http://jsonapi.org) documents.
2
+ Ruby gem for parsing/rendering [JSON API](http://jsonapi.org) documents.
3
3
 
4
4
  ## Installation
5
-
6
- Add the following to your application's Gemfile:
7
5
  ```ruby
6
+ # In Gemfile
8
7
  gem 'jsonapi'
9
8
  ```
10
- And then execute:
9
+ then
11
10
  ```
12
11
  $ bundle
13
12
  ```
14
- Or install it manually as:
13
+ or manually via
15
14
  ```
16
15
  $ gem install jsonapi
17
16
  ```
18
17
 
19
18
  ## Usage
20
19
 
21
- First, `require` the gem.
20
+ First, require the gem:
22
21
  ```ruby
23
22
  require 'jsonapi'
24
23
  ```
25
24
 
26
- Then, parse a JSON API document:
27
- ```ruby
28
- document = JSONAPI.parse(hash_or_json_string)
29
- ```
30
-
31
- or an [include directive](http://jsonapi.org/format/#fetching-includes):
32
- ```ruby
33
- include_directive = JSONAPI::IncludeDirective.new(include_args)
34
- ```
35
-
36
- ## Examples
37
-
38
- ```ruby
39
- document = JSONAPI.parse(json_document)
40
- # Should the document be invalid, the parse method would fail with an
41
- # InvalidDocument error.
42
-
43
- document.data.links.defined?(:self)
44
- # => true
45
- document.data.links.self.value
46
- # => 'http://example.com/articles/1'
47
- document.data.attributes.keys
48
- # => ['title']
49
- document.data.attributes.defined?(:title)
50
- # => true
51
- document.data.attributes.title
52
- # => 'JSON API paints my bikeshed!'
53
- document.data.relationships.keys
54
- # => ['author', 'comments']
55
- document.data.relationships.defined?(:author)
56
- # => true
57
- document.data.relationships.author.collection?
58
- # => false
59
- document.data.relationships.author.data.id
60
- # => 9
61
- document.data.relationships.author.data.type
62
- # => 'people'
63
- document.data.relationships.author.links.defined?(:self)
64
- # => true
65
- document.data.relationships.author.links.self.value
66
- # => 'http://example.com/articles/1/relationships/author'
67
- document.data.relationships.defined?(:comments)
68
- # => true
69
- document.data.relationships.comments.collection?
70
- # => true
71
- document.data.relationships.comments.data.size
72
- # => 2
73
- document.data.relationships.comments.data[0].id
74
- # => 5
75
- document.data.relationships.comments.data[0].type
76
- # => 'comments'
77
- document.data.relationships.comments.links.defined?(:self)
78
- # => true
79
- document.data.relationships.comments.links.self.value
80
- # => 'http://example.com/articles/1/relationships/comments'
81
-
82
- # for the following document_hash
83
- document_hash = {
84
- 'data' =>
85
- {
86
- 'type' => 'articles',
87
- 'id' => '1',
88
- 'attributes' => {
89
- 'title' => 'JSON API paints my bikeshed!'
90
- },
91
- 'links' => {
92
- 'self' => 'http://example.com/articles/1'
93
- },
94
- 'relationships' => {
95
- 'author' => {
96
- 'links' => {
97
- 'self' => 'http://example.com/articles/1/relationships/author',
98
- 'related' => 'http://example.com/articles/1/author'
99
- },
100
- 'data' => { 'type' => 'people', 'id' => '9' }
101
- },
102
- 'comments' => {
103
- 'links' => {
104
- 'self' => 'http://example.com/articles/1/relationships/comments',
105
- 'related' => 'http://example.com/articles/1/comments'
106
- },
107
- 'data' => [
108
- { 'type' => 'comments', 'id' => '5' },
109
- { 'type' => 'comments', 'id' => '12' }
110
- ]
111
- }
112
- }
113
- }
114
- }
115
- ```
116
-
117
- ## Contributing
118
-
119
- 1. Fork the [official repository](https://github.com/beauby/jsonapi_parser/tree/master).
120
- 2. Make your changes in a topic branch.
121
- 3. Send a pull request.
122
-
123
- Notes:
124
-
125
- * Contributions without tests won't be accepted.
126
- * Please don't update the Gem version.
25
+ Then, see docs for the part you are interested in:
26
+ * [parsing](parser/README.md)
27
+ * [rendering](renderer/README.md)
127
28
 
128
29
  ## License
129
30
 
130
- jsonapi is Copyright © 2016 Lucas Hosseini.
131
-
132
- It is free software, and may be redistributed under the terms specified in the
133
- [LICENSE](LICENSE) file.
31
+ jsonapi is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -1,18 +1,2 @@
1
- require 'jsonapi/exceptions'
2
- require 'jsonapi/version'
3
-
4
- require 'jsonapi/attributes'
5
- require 'jsonapi/document'
6
- require 'jsonapi/error'
7
- require 'jsonapi/jsonapi'
8
- require 'jsonapi/link'
9
- require 'jsonapi/links'
10
- require 'jsonapi/relationship'
11
- require 'jsonapi/relationships'
12
- require 'jsonapi/resource'
13
- require 'jsonapi/resource_identifier'
14
-
15
- require 'jsonapi/parse'
16
-
17
- module JSONAPI
18
- end
1
+ require 'jsonapi/parser'
2
+ require 'jsonapi/renderer'
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.beta2
4
+ version: 0.1.1.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Hosseini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: jsonapi-parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: 0.1.1.beta3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1.beta3
27
+ - !ruby/object:Gem::Dependency
28
+ name: jsonapi-renderer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1.beta1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
25
39
  - !ruby/object:Gem::Version
26
- version: '1.8'
40
+ version: 0.1.1.beta1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,42 +66,14 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.4'
55
- description: Tools for handling JSON API documents
56
- email:
57
- - lucas.hosseini@gmail.com
69
+ description: Efficiently parse and render JSONAPI documents.
70
+ email: lucas.hosseini@gmail.com
58
71
  executables: []
59
72
  extensions: []
60
73
  extra_rdoc_files: []
61
74
  files:
62
- - ".gitignore"
63
- - ".travis.yml"
64
- - Gemfile
65
- - Gemfile.lock
66
- - LICENSE
67
75
  - README.md
68
- - Rakefile
69
- - jsonapi_parser.gemspec
70
76
  - lib/jsonapi.rb
71
- - lib/jsonapi/attributes.rb
72
- - lib/jsonapi/document.rb
73
- - lib/jsonapi/error.rb
74
- - lib/jsonapi/exceptions.rb
75
- - lib/jsonapi/include_directive.rb
76
- - lib/jsonapi/include_directive/parser.rb
77
- - lib/jsonapi/jsonapi.rb
78
- - lib/jsonapi/link.rb
79
- - lib/jsonapi/links.rb
80
- - lib/jsonapi/parse.rb
81
- - lib/jsonapi/relationship.rb
82
- - lib/jsonapi/relationships.rb
83
- - lib/jsonapi/resource.rb
84
- - lib/jsonapi/resource_identifier.rb
85
- - lib/jsonapi/version.rb
86
- - spec/duplicates_spec.rb
87
- - spec/full_linkage_spec.rb
88
- - spec/include_directive/parser_spec.rb
89
- - spec/include_directive_spec.rb
90
- - spec/parser_spec.rb
91
77
  homepage: https://github.com/beauby/jsonapi
92
78
  licenses:
93
79
  - MIT
@@ -108,13 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
94
  version: 1.3.1
109
95
  requirements: []
110
96
  rubyforge_project:
111
- rubygems_version: 2.4.8
97
+ rubygems_version: 2.5.1
112
98
  signing_key:
113
99
  specification_version: 4
114
- summary: Parse and validate JSON API documents
115
- test_files:
116
- - spec/duplicates_spec.rb
117
- - spec/full_linkage_spec.rb
118
- - spec/include_directive/parser_spec.rb
119
- - spec/include_directive_spec.rb
120
- - spec/parser_spec.rb
100
+ summary: Parse and render JSONAPI documents.
101
+ test_files: []
data/.gitignore DELETED
@@ -1,36 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- ## Specific to RubyMotion:
14
- .dat*
15
- .repl_history
16
- build/
17
-
18
- ## Documentation cache and generated files:
19
- /.yardoc/
20
- /_yardoc/
21
- /doc/
22
- /rdoc/
23
-
24
- ## Environment normalization:
25
- /.bundle/
26
- /vendor/bundle
27
- /lib/bundler/man/
28
-
29
- # for a library or gem, you might want to ignore these files since the code is
30
- # intended to run in multiple environments; otherwise, check them in:
31
- # Gemfile.lock
32
- # .ruby-version
33
- # .ruby-gemset
34
-
35
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
- .rvmrc
@@ -1,6 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3.0
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jsonapi (0.1.1.beta2)
5
- json (~> 1.8)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- diff-lcs (1.2.5)
11
- json (1.8.3)
12
- rake (11.1.2)
13
- rspec (3.4.0)
14
- rspec-core (~> 3.4.0)
15
- rspec-expectations (~> 3.4.0)
16
- rspec-mocks (~> 3.4.0)
17
- rspec-core (3.4.4)
18
- rspec-support (~> 3.4.0)
19
- rspec-expectations (3.4.0)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.4.0)
22
- rspec-mocks (3.4.1)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.4.0)
25
- rspec-support (3.4.1)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- jsonapi!
32
- rake (>= 0.9)
33
- rspec (~> 3.4)
34
-
35
- BUNDLED WITH
36
- 1.11.2
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Lucas Hosseini
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task default: :spec
7
- task test: :spec
@@ -1,24 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'jsonapi/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'jsonapi'
7
- spec.version = JSONAPI::VERSION
8
- spec.authors = ['Lucas Hosseini']
9
- spec.email = ['lucas.hosseini@gmail.com']
10
- spec.summary = 'Parse and validate JSON API documents'
11
- spec.description = 'Tools for handling JSON API documents'
12
- spec.homepage = 'https://github.com/beauby/jsonapi'
13
- spec.license = 'MIT'
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(spec)/})
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_dependency 'json', '~>1.8'
21
-
22
- spec.add_development_dependency 'rake', '>=0.9'
23
- spec.add_development_dependency 'rspec', '~>3.4'
24
- end
@@ -1,41 +0,0 @@
1
- module JSONAPI
2
- # c.f. http://jsonapi.org/format/#document-resource-object-attributes
3
- class Attributes
4
- include Enumerable
5
-
6
- def initialize(attributes_hash, options = {})
7
- fail InvalidDocument,
8
- "the value of 'attributes' MUST be an object" unless
9
- attributes_hash.is_a?(Hash)
10
-
11
- @hash = attributes_hash
12
- @attributes = {}
13
- attributes_hash.each do |attr_name, attr_val|
14
- @attributes[attr_name.to_s] = attr_val
15
- define_singleton_method(attr_name) do
16
- @attributes[attr_name.to_s]
17
- end
18
- end
19
- end
20
-
21
- def to_hash
22
- @hash
23
- end
24
-
25
- def each(&block)
26
- @attributes.each(&block)
27
- end
28
-
29
- def [](attr_name)
30
- @attributes[attr_name.to_s]
31
- end
32
-
33
- def defined?(attr_name)
34
- @attributes.key?(attr_name.to_s)
35
- end
36
-
37
- def keys
38
- @attributes.keys
39
- end
40
- end
41
- end