easy-jsonapi 1.0.1 → 1.0.2

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.
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: '2.7.0'
3
+ TargetRubyVersion: '3.0.0'
4
4
  SuggestExtensions: false
5
5
 
6
6
  Metrics/AbcSize:
@@ -61,4 +61,4 @@ Metrics/ModuleLength:
61
61
  Enabled: false
62
62
 
63
63
  Layout/ArgumentAlignment:
64
- Enabled: false
64
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 1.0.1 - 2020-03-25
3
+ ## 1.0.2 - 2020-03-25
4
4
 
5
5
  - Updated README and fix READE broken links
6
6
  - Reorganization of README files into docs file.
7
7
  - Make easy-jsonapi compatible with ruby versions >= 2.5
8
+ - Added wrapper around Oj usage so all raised errors are found in the JSONAPI::Exceptions module
8
9
 
9
10
  ## 1.0.0 - 2020-03-24
10
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy-jsonapi (1.0.0)
4
+ easy-jsonapi (1.0.2)
5
5
  oj (~> 3.10)
6
6
 
7
7
  GEM
@@ -20,9 +20,9 @@ GEM
20
20
  rexml
21
21
  kramdown-parser-gfm (1.1.0)
22
22
  kramdown (~> 2.0)
23
- mini_portile2 (2.5.0)
24
- nokogiri (1.11.2)
25
- mini_portile2 (~> 2.5.0)
23
+ nokogiri (1.11.2-x86_64-darwin)
24
+ racc (~> 1.4)
25
+ nokogiri (1.11.2-x86_64-linux)
26
26
  racc (~> 1.4)
27
27
  oj (3.11.3)
28
28
  parallel (1.20.1)
@@ -50,7 +50,7 @@ GEM
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.10.0)
52
52
  rspec-support (3.10.2)
53
- rubocop (1.11.0)
53
+ rubocop (1.12.0)
54
54
  parallel (~> 1.10)
55
55
  parser (>= 3.0.0.0)
56
56
  rainbow (>= 2.2.2, < 4.0)
@@ -82,13 +82,14 @@ GEM
82
82
  thor (~> 1.0)
83
83
  tilt (~> 2.0)
84
84
  yard (~> 0.9, >= 0.9.24)
85
- thor (1.0.1)
85
+ thor (1.1.0)
86
86
  tilt (2.0.10)
87
87
  unicode-display_width (2.0.0)
88
88
  yard (0.9.26)
89
89
 
90
90
  PLATFORMS
91
- ruby
91
+ x86_64-darwin-19
92
+ x86_64-linux
92
93
 
93
94
  DEPENDENCIES
94
95
  codecov (~> 0.4)
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  ![](https://ruby-gem-downloads-badge.herokuapp.com/easy-jsonapi?type=total&color=brightgreen)
10
10
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
11
11
  [![License](https://img.shields.io/github/license/Curatess/easy-jsonapi)](https://img.shields.io)
12
- <!-- [![Build Status](https://secure.travis-ci.org/ -->
12
+ [![Build Status](https://img.shields.io/codecov/c/github/curatess/easy-jsonapi)](https://img.shields.io/codecov/c/github/curatess/easy-jsonapi)
13
13
 
14
14
  The gem that makes using [JSON:API](https://jsonapi.org/) ***EASY***!
15
15
 
@@ -128,7 +128,7 @@ When the middleware is in development mode it will raise an exception wherever i
128
128
 
129
129
  The types of exceptions it will raise are:
130
130
 
131
- - `Oj::ParserError` when an included body is not valid JSON
131
+ - `JSONAPI::Exceptions::JSONParseError` when an included body is not valid JSON
132
132
  - `JSONAPI::Exceptions::HeaderExceptions::InvalidHeader` when an included header is non-compliant
133
133
  - `JSONAPI::Exceptions::QueryParamExceptions::InvalidQueryParam` when an included query parameter is non-compliant
134
134
  - `JSONAPI::Exceptions::DocumentExceptions::InvalidDocument` when the body is included and non-compliant
data/easy-jsonapi.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'easy-jsonapi'
5
- spec.version = '1.0.1'
5
+ spec.version = '1.0.2'
6
6
  spec.authors = ['Joshua DeMoss, Joe Viscomi']
7
7
  spec.email = ['demoss.joshua@gmail.com']
8
8
 
@@ -4,6 +4,8 @@ require 'easy/jsonapi/exceptions/document_exceptions'
4
4
  require 'easy/jsonapi/exceptions/headers_exceptions'
5
5
  require 'easy/jsonapi/exceptions/naming_exceptions'
6
6
  require 'easy/jsonapi/exceptions/query_params_exceptions'
7
+ require 'easy/jsonapi/exceptions/user_defined_exceptions'
8
+ require 'easy/jsonapi/exceptions/json_parse_error'
7
9
 
8
10
  module JSONAPI
9
11
  # Namespace for the gem's Exceptions
@@ -23,5 +25,9 @@ module JSONAPI
23
25
  # Checking for JSONAPI naming rules compliance
24
26
  module NamingExceptions
25
27
  end
28
+
29
+ # Checking for User Defined Exceptions
30
+ module UserDefinedExceptions
31
+ end
26
32
  end
27
33
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'easy/jsonapi/parser/json_parser'
3
4
  require 'easy/jsonapi/exceptions/naming_exceptions'
4
5
  require 'easy/jsonapi/exceptions/user_defined_exceptions'
5
6
 
@@ -57,7 +58,7 @@ module JSONAPI
57
58
  # @param opts [Hash] Includes path, http_method, sparse_fieldsets
58
59
  # @raise InvalidDocument if any part of the spec is not observed
59
60
  def self.check_compliance(document, config_manager = nil, opts = {})
60
- document = Oj.load(document, symbol_keys: true) if document.is_a? String
61
+ document = JSONAPI::Parser::JSONParser.parse(document) if document.is_a? String
61
62
  ensure!(!document.nil?, 'A document cannot be nil')
62
63
 
63
64
  check_essentials(document, opts[:http_method])
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JSONAPI
4
+ module Exceptions
5
+
6
+ # Error to raise when error found while parsing json
7
+ class JSONParseError < StandardError
8
+ end
9
+ end
10
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'easy/jsonapi/exceptions'
4
4
  require 'easy/jsonapi/config_manager'
5
- require 'oj'
5
+ require 'easy/jsonapi/parser/json_parser'
6
6
 
7
7
  module JSONAPI
8
8
 
@@ -137,7 +137,7 @@ module JSONAPI
137
137
  raise if environment_development?(env)
138
138
 
139
139
  [e.status_code, {}, []]
140
- rescue Oj::ParseError
140
+ rescue JSONAPI::Exceptions::JSONParseError
141
141
  raise if environment_development?(env)
142
142
 
143
143
  [400, {}, []]
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'easy/jsonapi/document'
4
- require 'oj'
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 = Oj.load(req_body, symbol_keys: true) # parse json string into 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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua DeMoss, Joe Viscomi
@@ -132,7 +132,8 @@ extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
134
  - ".dockerignore"
135
- - ".github/workflows/publish-gem.yml"
135
+ - ".github/workflows/codecov.yml"
136
+ - ".github/workflows/publish.yml"
136
137
  - ".gitignore"
137
138
  - ".rspec"
138
139
  - ".rspec_status"
@@ -197,6 +198,7 @@ files:
197
198
  - lib/easy/jsonapi/exceptions.rb
198
199
  - lib/easy/jsonapi/exceptions/document_exceptions.rb
199
200
  - lib/easy/jsonapi/exceptions/headers_exceptions.rb
201
+ - lib/easy/jsonapi/exceptions/json_parse_error.rb
200
202
  - lib/easy/jsonapi/exceptions/naming_exceptions.rb
201
203
  - lib/easy/jsonapi/exceptions/query_params_exceptions.rb
202
204
  - lib/easy/jsonapi/exceptions/user_defined_exceptions.rb
@@ -210,6 +212,7 @@ files:
210
212
  - lib/easy/jsonapi/parser.rb
211
213
  - lib/easy/jsonapi/parser/document_parser.rb
212
214
  - lib/easy/jsonapi/parser/headers_parser.rb
215
+ - lib/easy/jsonapi/parser/json_parser.rb
213
216
  - lib/easy/jsonapi/parser/rack_req_params_parser.rb
214
217
  - lib/easy/jsonapi/request.rb
215
218
  - 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