easy-jsonapi 1.0.1 → 1.0.6
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 +4 -4
- data/.github/workflows/codecov.yml +30 -0
- data/.github/workflows/publish.yml +57 -0
- data/.rspec_status +486 -483
- data/.rubocop.yml +2 -2
- data/.travis.yml +8 -0
- data/CHANGELOG.md +22 -1
- data/Gemfile.lock +8 -7
- data/README.md +20 -16
- data/docs/UsingTheRequestObject.md +1 -1
- data/docs/UsingUserConfigurations.md +1 -1
- data/easy-jsonapi.gemspec +1 -1
- data/lib/easy/jsonapi/exceptions.rb +6 -0
- data/lib/easy/jsonapi/exceptions/document_exceptions.rb +2 -1
- data/lib/easy/jsonapi/exceptions/headers_exceptions.rb +19 -17
- data/lib/easy/jsonapi/exceptions/json_parse_error.rb +10 -0
- data/lib/easy/jsonapi/exceptions/query_params_exceptions.rb +1 -1
- data/lib/easy/jsonapi/exceptions/user_defined_exceptions.rb +6 -2
- data/lib/easy/jsonapi/middleware.rb +25 -27
- data/lib/easy/jsonapi/parser/document_parser.rb +2 -2
- data/lib/easy/jsonapi/parser/json_parser.rb +29 -0
- data/lib/easy/jsonapi/request/query_param_collection.rb +9 -3
- metadata +7 -3
- data/.github/workflows/publish-gem.yml +0 -74
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'easy/jsonapi/document'
|
4
|
-
require '
|
4
|
+
require 'easy/jsonapi/parser/json_parser'
|
5
5
|
|
6
6
|
module JSONAPI
|
7
7
|
module Parser
|
@@ -16,7 +16,7 @@ module JSONAPI
|
|
16
16
|
# @raise [JSONAPI::Parser::InvalidDocument] if document is invalid.
|
17
17
|
def self.parse(req_body)
|
18
18
|
return if req_body.nil?
|
19
|
-
document_hash =
|
19
|
+
document_hash = JSONAPI::Parser::JSONParser.parse(req_body) # parse json string into hash
|
20
20
|
parse_hash(document_hash)
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
require 'easy/jsonapi/exceptions/json_parse_error'
|
5
|
+
|
6
|
+
module JSONAPI
|
7
|
+
module Parser
|
8
|
+
# A wrapper class for OJ parser
|
9
|
+
module JSONParser
|
10
|
+
|
11
|
+
# Parse JSON string into a ruby hash
|
12
|
+
# @param document [String] The JSON string to parse
|
13
|
+
# @raise [JSONAPI::Exceptions::JSONParseError]
|
14
|
+
def self.parse(document, symbol_keys: true)
|
15
|
+
Oj.load(document, symbol_keys: symbol_keys)
|
16
|
+
|
17
|
+
rescue Oj::ParseError => e
|
18
|
+
raise JSONAPI::Exceptions::JSONParseError, e.message
|
19
|
+
end
|
20
|
+
|
21
|
+
# Convert ruby hash into JSON
|
22
|
+
# @param ruby_hash [Hash] THe hash to convert into JSON
|
23
|
+
def self.dump(ruby_hash)
|
24
|
+
Oj.dump(ruby_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -8,10 +8,12 @@ module JSONAPI
|
|
8
8
|
# A collection of QueryParam objects
|
9
9
|
class QueryParamCollection < JSONAPI::NameValuePairCollection
|
10
10
|
|
11
|
+
# The special query params defined by the JSON:API specification
|
12
|
+
SPECIAL_QUERY_PARAMS = %i[sorts filters fields page includes].freeze
|
13
|
+
|
11
14
|
# @param param_arr [Array<JSONAPI::Request::QueryParamCollection::QueryParam] The
|
12
15
|
# query params to initialize the collection with
|
13
16
|
def initialize(param_arr = [])
|
14
|
-
@param_names = []
|
15
17
|
super(param_arr, item_type: JSONAPI::Request::QueryParamCollection::QueryParam)
|
16
18
|
end
|
17
19
|
|
@@ -43,8 +45,12 @@ module JSONAPI
|
|
43
45
|
# @param args If any arguments were passed to the method called
|
44
46
|
# @param block If a block was passed to the method called
|
45
47
|
def method_missing(method_name, *args, &block)
|
46
|
-
|
47
|
-
|
48
|
+
included = include?(method_name)
|
49
|
+
super unless included || SPECIAL_QUERY_PARAMS.include?(method_name)
|
50
|
+
if included
|
51
|
+
return get(method_name)
|
52
|
+
end
|
53
|
+
nil
|
48
54
|
end
|
49
55
|
|
50
56
|
# Whether or not method missing should be called.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-jsonapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua DeMoss, Joe Viscomi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -132,13 +132,15 @@ extensions: []
|
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
134
|
- ".dockerignore"
|
135
|
-
- ".github/workflows/
|
135
|
+
- ".github/workflows/codecov.yml"
|
136
|
+
- ".github/workflows/publish.yml"
|
136
137
|
- ".gitignore"
|
137
138
|
- ".rspec"
|
138
139
|
- ".rspec_status"
|
139
140
|
- ".rubocop.yml"
|
140
141
|
- ".ruby-gemset"
|
141
142
|
- ".ruby-version"
|
143
|
+
- ".travis.yml"
|
142
144
|
- CHANGELOG.md
|
143
145
|
- CODE_OF_CONDUCT.md
|
144
146
|
- Gemfile
|
@@ -197,6 +199,7 @@ files:
|
|
197
199
|
- lib/easy/jsonapi/exceptions.rb
|
198
200
|
- lib/easy/jsonapi/exceptions/document_exceptions.rb
|
199
201
|
- lib/easy/jsonapi/exceptions/headers_exceptions.rb
|
202
|
+
- lib/easy/jsonapi/exceptions/json_parse_error.rb
|
200
203
|
- lib/easy/jsonapi/exceptions/naming_exceptions.rb
|
201
204
|
- lib/easy/jsonapi/exceptions/query_params_exceptions.rb
|
202
205
|
- lib/easy/jsonapi/exceptions/user_defined_exceptions.rb
|
@@ -210,6 +213,7 @@ files:
|
|
210
213
|
- lib/easy/jsonapi/parser.rb
|
211
214
|
- lib/easy/jsonapi/parser/document_parser.rb
|
212
215
|
- lib/easy/jsonapi/parser/headers_parser.rb
|
216
|
+
- lib/easy/jsonapi/parser/json_parser.rb
|
213
217
|
- lib/easy/jsonapi/parser/rack_req_params_parser.rb
|
214
218
|
- lib/easy/jsonapi/request.rb
|
215
219
|
- lib/easy/jsonapi/request/query_param_collection.rb
|
@@ -1,74 +0,0 @@
|
|
1
|
-
name: Test Build and Publish
|
2
|
-
on:
|
3
|
-
push:
|
4
|
-
branches: [ production ]
|
5
|
-
pull_request:
|
6
|
-
branches: [ production ]
|
7
|
-
jobs:
|
8
|
-
test:
|
9
|
-
runs-on: ubuntu-latest
|
10
|
-
strategy:
|
11
|
-
matrix:
|
12
|
-
ruby-version: ['2.5', '2.6', '2.7', '3.0']
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@v2
|
15
|
-
- name: Set up Ruby
|
16
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
17
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
18
|
-
uses: ruby/setup-ruby@v1
|
19
|
-
with:
|
20
|
-
ruby-version: ${{ matrix.ruby-version }}
|
21
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
22
|
-
- name: Run tests
|
23
|
-
run: bundle exec rake
|
24
|
-
build_and_publish:
|
25
|
-
name: Build + Publish + Release
|
26
|
-
runs-on: ubuntu-latest
|
27
|
-
steps:
|
28
|
-
- uses: actions/checkout@v2
|
29
|
-
- name: Set up Ruby 3.0
|
30
|
-
uses: actions/setup-ruby@v1
|
31
|
-
with:
|
32
|
-
ruby-version: 3.0.x
|
33
|
-
- name: Publish to GPR
|
34
|
-
run: |
|
35
|
-
mkdir -p $HOME/.gem
|
36
|
-
touch $HOME/.gem/credentials
|
37
|
-
chmod 0600 $HOME/.gem/credentials
|
38
|
-
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
39
|
-
gem build *.gemspec
|
40
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
41
|
-
env:
|
42
|
-
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
43
|
-
OWNER: ${{ github.repository_owner }}
|
44
|
-
|
45
|
-
- name: Publish to RubyGems
|
46
|
-
run: |
|
47
|
-
mkdir -p $HOME/.gem
|
48
|
-
touch $HOME/.gem/credentials
|
49
|
-
chmod 0600 $HOME/.gem/credentials
|
50
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
51
|
-
gem build *.gemspec
|
52
|
-
gem push *.gem
|
53
|
-
env:
|
54
|
-
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
55
|
-
release:
|
56
|
-
name: Create Release
|
57
|
-
runs-on: ubuntu-latest
|
58
|
-
steps:
|
59
|
-
- name: Checkout code
|
60
|
-
uses: actions/checkout@v2
|
61
|
-
- name: Create Release
|
62
|
-
id: create_release
|
63
|
-
uses: actions/create-release@v1
|
64
|
-
env:
|
65
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
|
66
|
-
with:
|
67
|
-
tag_name: ${{ github.ref }}
|
68
|
-
release_name: Release ${{ github.ref }}
|
69
|
-
body: |
|
70
|
-
Changes in this Release
|
71
|
-
- First Change
|
72
|
-
- Second Change
|
73
|
-
draft: false
|
74
|
-
prerelease: false
|