easy-jsonapi 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/.github/workflows/publish-gem.yml +60 -0
- data/.github/workflows/rake.yml +35 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +106 -0
- data/LICENSE.txt +21 -0
- data/README.md +209 -0
- data/Rakefile +20 -0
- data/UsingTheRequestObject.md +74 -0
- data/UsingUserConfigurations.md +95 -0
- data/bin/bundle +114 -0
- data/bin/console +15 -0
- data/bin/htmldiff +29 -0
- data/bin/kramdown +29 -0
- data/bin/ldiff +29 -0
- data/bin/license_finder +29 -0
- data/bin/license_finder_pip.py +29 -0
- data/bin/maruku +29 -0
- data/bin/marutex +29 -0
- data/bin/nokogiri +29 -0
- data/bin/racc +29 -0
- data/bin/rackup +29 -0
- data/bin/rake +29 -0
- data/bin/redcarpet +29 -0
- data/bin/reverse_markdown +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/ruby-parse +29 -0
- data/bin/ruby-rewrite +29 -0
- data/bin/setup +8 -0
- data/bin/solargraph +29 -0
- data/bin/thor +29 -0
- data/bin/tilt +29 -0
- data/bin/yard +29 -0
- data/bin/yardoc +29 -0
- data/bin/yri +29 -0
- data/easy-jsonapi.gemspec +39 -0
- data/lib/easy/jsonapi.rb +12 -0
- data/lib/easy/jsonapi/collection.rb +144 -0
- data/lib/easy/jsonapi/config_manager.rb +144 -0
- data/lib/easy/jsonapi/config_manager/config.rb +49 -0
- data/lib/easy/jsonapi/document.rb +71 -0
- data/lib/easy/jsonapi/document/error.rb +48 -0
- data/lib/easy/jsonapi/document/error/error_member.rb +15 -0
- data/lib/easy/jsonapi/document/jsonapi.rb +26 -0
- data/lib/easy/jsonapi/document/jsonapi/jsonapi_member.rb +15 -0
- data/lib/easy/jsonapi/document/links.rb +36 -0
- data/lib/easy/jsonapi/document/links/link.rb +15 -0
- data/lib/easy/jsonapi/document/meta.rb +26 -0
- data/lib/easy/jsonapi/document/meta/meta_member.rb +14 -0
- data/lib/easy/jsonapi/document/resource.rb +56 -0
- data/lib/easy/jsonapi/document/resource/attributes.rb +37 -0
- data/lib/easy/jsonapi/document/resource/attributes/attribute.rb +29 -0
- data/lib/easy/jsonapi/document/resource/relationships.rb +40 -0
- data/lib/easy/jsonapi/document/resource/relationships/relationship.rb +50 -0
- data/lib/easy/jsonapi/document/resource_id.rb +28 -0
- data/lib/easy/jsonapi/exceptions.rb +27 -0
- data/lib/easy/jsonapi/exceptions/document_exceptions.rb +619 -0
- data/lib/easy/jsonapi/exceptions/headers_exceptions.rb +156 -0
- data/lib/easy/jsonapi/exceptions/naming_exceptions.rb +36 -0
- data/lib/easy/jsonapi/exceptions/query_params_exceptions.rb +67 -0
- data/lib/easy/jsonapi/exceptions/user_defined_exceptions.rb +253 -0
- data/lib/easy/jsonapi/field.rb +43 -0
- data/lib/easy/jsonapi/header_collection.rb +38 -0
- data/lib/easy/jsonapi/header_collection/header.rb +11 -0
- data/lib/easy/jsonapi/item.rb +88 -0
- data/lib/easy/jsonapi/middleware.rb +158 -0
- data/lib/easy/jsonapi/name_value_pair.rb +72 -0
- data/lib/easy/jsonapi/name_value_pair_collection.rb +78 -0
- data/lib/easy/jsonapi/parser.rb +38 -0
- data/lib/easy/jsonapi/parser/document_parser.rb +196 -0
- data/lib/easy/jsonapi/parser/headers_parser.rb +33 -0
- data/lib/easy/jsonapi/parser/rack_req_params_parser.rb +117 -0
- data/lib/easy/jsonapi/request.rb +40 -0
- data/lib/easy/jsonapi/request/query_param_collection.rb +56 -0
- data/lib/easy/jsonapi/request/query_param_collection/fields_param.rb +32 -0
- data/lib/easy/jsonapi/request/query_param_collection/fields_param/fieldset.rb +34 -0
- data/lib/easy/jsonapi/request/query_param_collection/filter_param.rb +28 -0
- data/lib/easy/jsonapi/request/query_param_collection/filter_param/filter.rb +34 -0
- data/lib/easy/jsonapi/request/query_param_collection/include_param.rb +119 -0
- data/lib/easy/jsonapi/request/query_param_collection/page_param.rb +55 -0
- data/lib/easy/jsonapi/request/query_param_collection/query_param.rb +47 -0
- data/lib/easy/jsonapi/request/query_param_collection/sort_param.rb +25 -0
- data/lib/easy/jsonapi/response.rb +22 -0
- data/lib/easy/jsonapi/utility.rb +158 -0
- data/lib/easy/jsonapi/version.rb +8 -0
- metadata +248 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 298f88b20aaa28eb454462307efff708596debb01ac01ced51cbee2ad9dee062
|
4
|
+
data.tar.gz: d929641bc947432eae3fee0cdd807809ea72c68dfca3668552041f58959637f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: befec3d31260ef314f461e6c8c0b59219d0bad1bcad2083412d1d6731253e8cd5bb35f555aa30f6336dfb56461a742cecf92b4b8a9c57f57f7928586455697f1
|
7
|
+
data.tar.gz: ba0925a2372ccfeecc478803bb19219b9074e633e1166a77c54a7a581376b13867f62e88be16a8f617cf3587a1410e32961ed9e01ba966669535b8a0aa18d7a9
|
@@ -0,0 +1,60 @@
|
|
1
|
+
name: Test Build and Publish
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['2.7', '3.0']
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
20
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
21
|
+
# uses: ruby/setup-ruby@v1
|
22
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle exec rake
|
28
|
+
build:
|
29
|
+
name: Build + Publish
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
- name: Set up Ruby 3.0
|
35
|
+
uses: actions/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: 3.0.x
|
38
|
+
|
39
|
+
- name: Publish to GPR
|
40
|
+
run: |
|
41
|
+
mkdir -p $HOME/.gem
|
42
|
+
touch $HOME/.gem/credentials
|
43
|
+
chmod 0600 $HOME/.gem/credentials
|
44
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
45
|
+
gem build *.gemspec
|
46
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
47
|
+
env:
|
48
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
49
|
+
OWNER: ${{ github.repository_owner }}
|
50
|
+
|
51
|
+
- name: Publish to RubyGems
|
52
|
+
run: |
|
53
|
+
mkdir -p $HOME/.gem
|
54
|
+
touch $HOME/.gem/credentials
|
55
|
+
chmod 0600 $HOME/.gem/credentials
|
56
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
57
|
+
gem build *.gemspec
|
58
|
+
gem push *.gem
|
59
|
+
env:
|
60
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at joshua.demoss@curatess.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
easy-jsonapi (1.0.0)
|
5
|
+
oj (~> 3.10)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
backport (1.1.2)
|
12
|
+
benchmark (0.1.1)
|
13
|
+
diff-lcs (1.4.4)
|
14
|
+
e2mmap (0.1.0)
|
15
|
+
jaro_winkler (1.5.4)
|
16
|
+
kramdown (2.3.1)
|
17
|
+
rexml
|
18
|
+
kramdown-parser-gfm (1.1.0)
|
19
|
+
kramdown (~> 2.0)
|
20
|
+
license_finder (6.12.0)
|
21
|
+
bundler
|
22
|
+
rubyzip (>= 1, < 3)
|
23
|
+
thor (~> 1.0.1)
|
24
|
+
tomlrb (>= 1.3, < 2.1)
|
25
|
+
with_env (= 1.1.0)
|
26
|
+
xml-simple (~> 1.1.5)
|
27
|
+
mini_portile2 (2.5.0)
|
28
|
+
nokogiri (1.11.2)
|
29
|
+
mini_portile2 (~> 2.5.0)
|
30
|
+
racc (~> 1.4)
|
31
|
+
oj (3.11.3)
|
32
|
+
parallel (1.20.1)
|
33
|
+
parser (3.0.0.0)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
racc (1.5.2)
|
36
|
+
rack (2.2.3)
|
37
|
+
rainbow (3.0.0)
|
38
|
+
rake (13.0.3)
|
39
|
+
redcarpet (3.5.1)
|
40
|
+
regexp_parser (2.1.1)
|
41
|
+
reverse_markdown (2.0.0)
|
42
|
+
nokogiri
|
43
|
+
rexml (3.2.4)
|
44
|
+
rspec (3.10.0)
|
45
|
+
rspec-core (~> 3.10.0)
|
46
|
+
rspec-expectations (~> 3.10.0)
|
47
|
+
rspec-mocks (~> 3.10.0)
|
48
|
+
rspec-core (3.10.1)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-expectations (3.10.1)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-mocks (3.10.2)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.10.0)
|
56
|
+
rspec-support (3.10.2)
|
57
|
+
rubocop (1.11.0)
|
58
|
+
parallel (~> 1.10)
|
59
|
+
parser (>= 3.0.0.0)
|
60
|
+
rainbow (>= 2.2.2, < 4.0)
|
61
|
+
regexp_parser (>= 1.8, < 3.0)
|
62
|
+
rexml
|
63
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
64
|
+
ruby-progressbar (~> 1.7)
|
65
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
66
|
+
rubocop-ast (1.4.1)
|
67
|
+
parser (>= 2.7.1.5)
|
68
|
+
ruby-progressbar (1.11.0)
|
69
|
+
rubyzip (2.3.0)
|
70
|
+
solargraph (0.40.4)
|
71
|
+
backport (~> 1.1)
|
72
|
+
benchmark
|
73
|
+
bundler (>= 1.17.2)
|
74
|
+
e2mmap
|
75
|
+
jaro_winkler (~> 1.5)
|
76
|
+
kramdown (~> 2.3)
|
77
|
+
kramdown-parser-gfm (~> 1.1)
|
78
|
+
parser (~> 3.0)
|
79
|
+
reverse_markdown (>= 1.0.5, < 3)
|
80
|
+
rubocop (>= 0.52)
|
81
|
+
thor (~> 1.0)
|
82
|
+
tilt (~> 2.0)
|
83
|
+
yard (~> 0.9, >= 0.9.24)
|
84
|
+
thor (1.0.1)
|
85
|
+
tilt (2.0.10)
|
86
|
+
tomlrb (2.0.1)
|
87
|
+
unicode-display_width (2.0.0)
|
88
|
+
with_env (1.1.0)
|
89
|
+
xml-simple (1.1.8)
|
90
|
+
yard (0.9.26)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
ruby
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
easy-jsonapi!
|
97
|
+
license_finder (~> 6.10)
|
98
|
+
rack (~> 2.2)
|
99
|
+
rake (~> 13.0)
|
100
|
+
redcarpet (~> 3.5)
|
101
|
+
rspec (~> 3.9)
|
102
|
+
rubocop (~> 1.11)
|
103
|
+
solargraph (~> 0.39)
|
104
|
+
|
105
|
+
BUNDLED WITH
|
106
|
+
2.2.11
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Joshua DeMoss
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
<!--
|
2
|
+
# @markup markdown
|
3
|
+
# @title README
|
4
|
+
-->
|
5
|
+
|
6
|
+
# easy-jsonapi
|
7
|
+
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/easy-jsonapi.svg)](https://badge.fury.io/rb/easy-jsonapi)
|
9
|
+
![](https://ruby-gem-downloads-badge.herokuapp.com/easy-jsonapi?type=total&color=brightgreen)
|
10
|
+
<!-- [![Build Status](https://secure.travis-ci.org/jsonapi-rb/jsonapi-parser.svg?branch=master)](http://travis-ci.org/jsonapi-rb/parser?branch=master) -->
|
11
|
+
|
12
|
+
The gem that makes using [JSON:API](https://jsonapi.org/) ***EASY***!
|
13
|
+
|
14
|
+
Ever wanted the benefits of [JSONAPI](https://jsonapi.org/) without the learning curve of the 34-page [spec](https://jsonapi.org/format/)? Well, now you can! Introducing ***easy-jsonapi***, a fully-compliant, lightweight, and intuitive ruby gem that currently provides 3 main use cases:
|
15
|
+
|
16
|
+
1. A `middleware` for filtering out non-compliant HTTP requests
|
17
|
+
2. A `parser` to interact with requests in a typical Object-Oriented Fashion, providing convenient and efficient access to headers, query parameters, and document members.
|
18
|
+
3. A `validator` to check your serialized responses for [JSONAPI](https://jsonapi.org/) compliance.
|
19
|
+
|
20
|
+
With its only gem dependency being [Oj](https://github.com/ohler55/oj), ***easy-jsonapi*** is a lightweight, dependable tool, featuring comprehensive error messages and over 500 unit tests allowing developers to spend less time debugging and more time creating.
|
21
|
+
|
22
|
+
As a bonus, flexible user configurations can be added to the middleware providing custom screening on all requests or individual requests depending on the resource type of the endpoint and the given document, header, or query param restrictions from the user.
|
23
|
+
|
24
|
+
## Links
|
25
|
+
|
26
|
+
- [*Documentation*](tbd)
|
27
|
+
|
28
|
+
- [*RubyGems* *repo*](tbd)
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add this ine to your applications' Gemfile:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
# Gemfile
|
36
|
+
gem 'easy-jsonapi'
|
37
|
+
```
|
38
|
+
|
39
|
+
then execute:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
$ bundle
|
43
|
+
# ...
|
44
|
+
```
|
45
|
+
|
46
|
+
or manually via
|
47
|
+
|
48
|
+
```bash
|
49
|
+
$ gem install easy-jsonapi
|
50
|
+
# ...
|
51
|
+
```
|
52
|
+
|
53
|
+
## Quick Start
|
54
|
+
|
55
|
+
1. Set up the middleware
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
use JSONAPI::Middleware
|
59
|
+
```
|
60
|
+
|
61
|
+
2. Parse the rack environment variable and get access to request components
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
j_req = JSONAPI::Parser.parse_request(env)
|
65
|
+
|
66
|
+
j_req.headers.content_type # => "application/vnd.api+json"
|
67
|
+
j_req.params.page.offset # => "1"
|
68
|
+
j_req.body.data.type # => "person"
|
69
|
+
```
|
70
|
+
|
71
|
+
3. Validate your serialized JSON:API before returning it to your clients.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
begin
|
75
|
+
JSONAPI::Response.validate(headers, body)
|
76
|
+
rescue => error
|
77
|
+
# ...
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
## Using The Middleware
|
82
|
+
|
83
|
+
### Setup
|
84
|
+
|
85
|
+
Add the middleware to the stack in order to activate it.
|
86
|
+
|
87
|
+
Sintra:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# app.rb
|
91
|
+
use JSONAPI::Middleware
|
92
|
+
```
|
93
|
+
|
94
|
+
Rails:
|
95
|
+
|
96
|
+
Edit `config/environments/development.rb`.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# config/environments/development.rb
|
100
|
+
|
101
|
+
MyApp::Application.configure do
|
102
|
+
# Add JSONAPI::Middleware to the bottom of the middleware stack
|
103
|
+
config.middleware.insert_after ActionDispatch::Static, JSONAPI::Middleware
|
104
|
+
|
105
|
+
# or, if you're using better_errors:
|
106
|
+
config.middleware.insert_before Rack::Lock, JSONAPI::Middleware
|
107
|
+
|
108
|
+
# ...
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
Rack Apps:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
# config.ru
|
116
|
+
use JSONAPI::Middleware
|
117
|
+
```
|
118
|
+
|
119
|
+
### Functionality
|
120
|
+
|
121
|
+
The easy-jsonapi middleware can opperate in development or production mode.
|
122
|
+
|
123
|
+
If `ENV['RACK_ENV']` is set to `:development` or not set at all, the middleware will be opperating in development mode.
|
124
|
+
|
125
|
+
When the middleware is in development mode it will raise an exception wherever it finds the http request to be non JSONAPI compliant.
|
126
|
+
|
127
|
+
The types of exceptions it will raise are:
|
128
|
+
|
129
|
+
- `Oj::ParserError` when an included body is not valid JSON
|
130
|
+
- `JSONAPI::Exceptions::HeaderExceptions::InvalidHeader` when an included header is non-compliant
|
131
|
+
- `JSONAPI::Exceptions::QueryParamExceptions::InvalidQueryParam` when an included query parameter is non-compliant
|
132
|
+
- `JSONAPI::Exceptions::DocumentExceptions::InvalidDocument` when the body is included and non-compliant
|
133
|
+
|
134
|
+
If `ENV['RACK_ENV']` is set to something other than `:development`, then the middleware will return the appropriate status code error given the JSON:API clause the headers, query params, or document violates.
|
135
|
+
|
136
|
+
### User Configurations
|
137
|
+
|
138
|
+
***easy-jsonapi*** has a fair amount of flexibility when it comes to user configurations and plenty of room for extending the current user configurations to include more features. To see the currently available configurations see [UsingUserConfigurations](https://github.com/Curatess/easy-jsonapi/UsingUserConfigurations.md) and to propose a new feature create a pull request or ticket on [the github repository](https://github.com/Curatess/easy-jsonapi)
|
139
|
+
|
140
|
+
## Using the Request Parser
|
141
|
+
|
142
|
+
The request parser works by parsing the rack `env` variable.
|
143
|
+
|
144
|
+
With Rails or Sinatra you can access this by using:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
request.env
|
148
|
+
```
|
149
|
+
|
150
|
+
For rack apps you get env from the call method:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
def call(env)
|
154
|
+
|
155
|
+
# ...
|
156
|
+
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
To parse:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
require 'easy/jsonapi'
|
164
|
+
|
165
|
+
# ...
|
166
|
+
|
167
|
+
jsonapi_req = JSONAPI::Parser.parse_request(env)
|
168
|
+
```
|
169
|
+
|
170
|
+
This returns a `JSONAPI::Request` object that can be used to access the collection of query params, collection of headers, and the body of the request. To see example usage, see [Using the Request Object](https://github.com/Curatess/easy-jsonapi/UsingTheRequestObject.md).
|
171
|
+
|
172
|
+
## Using the Serialized Response Validator
|
173
|
+
|
174
|
+
The `JSONAPI::Response` module is responsible for validating whether a serialized response is fully JSONAPI compliant or not.
|
175
|
+
|
176
|
+
The following method is provided to validate the response:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
require 'easy/jsonapi'
|
180
|
+
|
181
|
+
# ... application code
|
182
|
+
|
183
|
+
begin
|
184
|
+
JSONAPI::Response.validate(headers, body)
|
185
|
+
rescue => error
|
186
|
+
# ... handling
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
The `headers` param is a hash of `String => String` or `Symbol => String` of the header keys and values.
|
191
|
+
The `body` param is either the JSON body or a ruby hash representation of the body.
|
192
|
+
|
193
|
+
See the [rubydocs](tbd) for more on the Serialized Response Validator.
|
194
|
+
|
195
|
+
## Releases
|
196
|
+
|
197
|
+
See [{file:CHANGELOG.md}](https://github.com/Curatess/easy-jsonapi/CHANGELOG.md)
|
198
|
+
|
199
|
+
## License
|
200
|
+
|
201
|
+
***easy-jsonapi*** is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
202
|
+
|
203
|
+
## Contributing
|
204
|
+
|
205
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Curatess/easy-jsonapi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Curatess/easy-jsonapi/blob/master/CODE_OF_CONDUCT.md).
|
206
|
+
|
207
|
+
## Code of Conduct
|
208
|
+
|
209
|
+
Everyone interacting in the easy-jsonapi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Curatess/easy-jsonapi/blob/master/CODE_OF_CONDUCT.md).
|