easy-jsonapi 1.0.2 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81df918d7bbe739357e3c8d35a390d1ff0a211769500fd5bc5f1974dc1842279
4
- data.tar.gz: bcd42cf1f5bb09d2c090d2f0f9486b5700b96924640d3048985d9414778be469
3
+ metadata.gz: f068c7e615a06af4b308f446745623cb7da1800c2bd795ef7dcd9bf5ba4f689c
4
+ data.tar.gz: 1105e6c8ad9d9844c62a14ae7e21ed019ceb72a9b9fb499be974112048090061
5
5
  SHA512:
6
- metadata.gz: 756a9f470097d686190065edc98d31dca2f2534cbdab5a738adfcf99561b7038736eeaaee3fdbf817c3650803ca262647fb9d1af5dc3e88038396c9bd98ef522
7
- data.tar.gz: a8e85b906235ca238b264ce2b08e0da9562c277f9d76e8010f298242906df5aa0f67825e19c66ffc13be8458b5615e0f2eaf4b39013b70a62ade3e07ecefdcfd
6
+ metadata.gz: 52d519c1b8df1c3254620583130b8aab22206eb48c999fe3f7cd27dfc2d25c5eb91874d09aee23b96870fe147b89b5198b5f1526857966572130b93f618655e0
7
+ data.tar.gz: 64e42ef8deda94c76a74bfc2fc6b46fc391570e30d472a86bbfdae188230c9c3e52fe3e24b56d4e4129faa9792103efb7d50049f49530b242257922ac1667dba
@@ -25,5 +25,6 @@ jobs:
25
25
  gem install bundler
26
26
  bundler install
27
27
  bundle exec rspec
28
+ bash <(curl -s https://codecov.io/bash)
28
29
  env:
29
30
  CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
@@ -51,13 +51,7 @@ jobs:
51
51
  env:
52
52
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
53
53
  with:
54
- tag_name: ${{ github.ref }}
55
- release_name: Release ${{ github.ref }}
56
- body: |
57
- Changes in this Release
58
- - Updated README and fix READE broken links
59
- - Reorganization of README files into docs file.
60
- - Make easy-jsonapi compatible with ruby versions >= 2.5
61
- - Added wrapper around Oj usage so all raised errors are found in the JSONAPI::Exceptions module
54
+ tag_name: 1.0.7
55
+ release_name: Release 1.0.7
62
56
  draft: false
63
57
  prerelease: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 3.0.0
5
+ before_install:
6
+ - gem install bundler
7
+ - bundler install
8
+ script: bundle exec rake build
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.7 - 2020-03-31
4
+
5
+ - Fixed bug in JSONAPI::Parser::JSONParser that would serialize hashes with symbol key values instead of string
6
+
7
+ ## 1.0.6 - 2020-03-30
8
+
9
+ - Fixed bug in JSONAPI::Middleware that was not checking for environment variables properly
10
+
11
+ ## 1.0.5 - 2020-03-30
12
+
13
+ - Fixed bug in JSONAPI::Exceptions::HeadersExceptions that didn't check for user required headers requirements
14
+ - Fixed bug in JSONAPI::Exceptions::QueryParamExceptions that didn't check for user required query param requirements
15
+ - Added more tests to the middleware
16
+ - Updated Documentation
17
+
18
+ ## 1.0.4 - 2020-03-28
19
+
20
+ - Fixed JSONAPI::ExceptionsHeadersExceptions bug
21
+ - Updated README files
22
+
23
+ ## 1.0.3 - 2020-03-25
24
+
25
+ - Updated JSONAPI::Exceptions::HeadersExceptions to allow wildcard matching for Accept header
26
+
3
27
  ## 1.0.2 - 2020-03-25
4
28
 
5
29
  - Updated README and fix READE broken links
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy-jsonapi (1.0.2)
4
+ easy-jsonapi (1.0.7)
5
5
  oj (~> 3.10)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -5,11 +5,13 @@
5
5
 
6
6
  # easy-jsonapi
7
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
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
11
- [![License](https://img.shields.io/github/license/Curatess/easy-jsonapi)](https://img.shields.io)
12
- [![Build Status](https://img.shields.io/codecov/c/github/curatess/easy-jsonapi)](https://img.shields.io/codecov/c/github/curatess/easy-jsonapi)
8
+ ![Gem Version](https://badge.fury.io/rb/easy-jsonapi.svg)
9
+ ![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/easy-jsonapi?type=total&color=brightgreen)
10
+ ![Build Status](https://img.shields.io/travis/Curatess/easy-jsonapi/production)
11
+ ![Code Coverage](https://img.shields.io/codecov/c/github/curatess/easy-jsonapi)
12
+ ![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)
13
+ ![License](https://img.shields.io/github/license/Curatess/easy-jsonapi)
14
+
13
15
 
14
16
  The gem that makes using [JSON:API](https://jsonapi.org/) ***EASY***!
15
17
 
@@ -19,9 +21,9 @@ Ever wanted the benefits of [JSONAPI](https://jsonapi.org/) without the learning
19
21
  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.
20
22
  3. A `validator` to check your serialized responses for [JSONAPI](https://jsonapi.org/) compliance.
21
23
 
22
- 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.
24
+ 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 ***525 unit tests*** allowing developers to spend less time debugging and more time creating.
23
25
 
24
- 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.
26
+ 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 user-defined document, header, or query param restrictions.
25
27
 
26
28
  ## Links
27
29
 
@@ -54,13 +56,15 @@ $ gem install easy-jsonapi
54
56
 
55
57
  ## Quick Start
56
58
 
57
- 1. Set up the middleware
59
+ ***easy-jsonapi's*** 3 main use cases can be used together or separately, so to get started quickly, do any of the 3 below to begin enjoying the convenience of the library.
60
+
61
+ - Set up the middleware
58
62
 
59
63
  ```ruby
60
64
  use JSONAPI::Middleware
61
65
  ```
62
66
 
63
- 2. Parse the rack environment variable and get access to request components
67
+ - Parse the rack environment variable and get access to request components (assumes valid JSON:API requests -- use with middleware to ensure valid requests)
64
68
 
65
69
  ```ruby
66
70
  j_req = JSONAPI::Parser.parse_request(env)
@@ -70,7 +74,7 @@ $ gem install easy-jsonapi
70
74
  j_req.body.data.type # => "person"
71
75
  ```
72
76
 
73
- 3. Validate your serialized JSON:API before returning it to your clients.
77
+ - Validate your serialized JSON:API before returning it to your clients.
74
78
 
75
79
  ```ruby
76
80
  begin
@@ -120,9 +124,9 @@ use JSONAPI::Middleware
120
124
 
121
125
  ### Functionality
122
126
 
123
- The easy-jsonapi middleware can opperate in development or production mode.
127
+ The easy-jsonapi middleware can operate in development or production mode.
124
128
 
125
- If `ENV['RACK_ENV']` is set to `:development` or not set at all, the middleware will be opperating in development mode.
129
+ If `ENV['RACK_ENV']` is set to `'development'` or not set at all, the middleware will be operating in development mode.
126
130
 
127
131
  When the middleware is in development mode it will raise an exception wherever it finds the http request to be non JSONAPI compliant.
128
132
 
@@ -133,11 +137,11 @@ The types of exceptions it will raise are:
133
137
  - `JSONAPI::Exceptions::QueryParamExceptions::InvalidQueryParam` when an included query parameter is non-compliant
134
138
  - `JSONAPI::Exceptions::DocumentExceptions::InvalidDocument` when the body is included and non-compliant
135
139
 
136
- 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.
140
+ 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.
137
141
 
138
142
  ### User Configurations
139
143
 
140
- ***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/blob/production/docs/UsingUserConfigurations.md) and to propose a new feature create a pull request or ticket on [the github repository](https://github.com/Curatess/easy-jsonapi)
144
+ ***easy-jsonapi*** has a fair amount of flexibility when it comes to user configurations but also plenty of room for to add more features. To see the currently available configurations see [UsingUserConfigurations](https://github.com/Curatess/easy-jsonapi/blob/production/docs/UsingUserConfigurations.md) and to propose a new feature create a pull request or ticket on the [dev repository](https://github.com/Curatess/easy-jsonapi/tree/dev).
141
145
 
142
146
  ## Using the Request Parser
143
147
 
@@ -196,7 +200,7 @@ See the [rubydocs](https://rubydoc.info/github/Curatess/easy-jsonapi/proudction)
196
200
 
197
201
  ## Acknowledgements
198
202
 
199
- The exception checking strategy for `JSONAPI::Exceptions::DocumentExceptions` and some innitial compliance checks are based off [jsonapi-parser](https://github.com/jsonapi-rb/jsonapi-parser). We would like to thank the [jsonapi-rb](https://github.com/jsonapi-rb) team for the document validation work and to all our contributors and users for the continuous support!
203
+ The exception checking strategy for `JSONAPI::Exceptions::DocumentExceptions` and some initial compliance checks are based off [jsonapi-parser](https://github.com/jsonapi-rb/jsonapi-parser). We would like to thank the [jsonapi-rb](https://github.com/jsonapi-rb) team for the document validation work and to all our contributors and users for the continuous support!
200
204
 
201
205
  ## Releases
202
206
 
@@ -69,6 +69,6 @@ j_req.body.jsonapi # The JSONAPI jsonapi member
69
69
  j_req.body.to_s # serialized JSONAPI
70
70
  j_req.body.to_h # ruby hash representation of JSONAPI
71
71
 
72
- # NOTE: j_req.body.data returns a resoure or an array of resources depending on the request
72
+ # NOTE: j_req.body.data returns a resource or an array of resources depending on the request
73
73
  j_req.body.data # JSONAPI::Document::Resource or [JSONAPI::Document::Resource]
74
74
  ```
@@ -17,7 +17,7 @@ use JSONAPI::Middleware do |config_manager|
17
17
  end
18
18
  ```
19
19
 
20
- To add restrictions to ALL requests use default global config included with the Config Manager:
20
+ To add restrictions to ALL requests use the default global config included with the Config Manager:
21
21
 
22
22
  ```ruby
23
23
  use JSONAPI::Middleware do |config_manager|
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.2'
5
+ spec.version = '1.0.7'
6
6
  spec.authors = ['Joshua DeMoss, Joe Viscomi']
7
7
  spec.email = ['demoss.joshua@gmail.com']
8
8
 
@@ -25,9 +25,11 @@ module JSONAPI
25
25
 
26
26
  # Check http verb vs included headers
27
27
  # @param env [Hash] The rack environment variable
28
+ # @param config_manager [JSONAPI::ConfigManager] The manager of user configurations
29
+ # @param opts [Hash] Includes http_method, path, and contains_body values
28
30
  def self.check_request(env, config_manager = nil, opts = {})
29
31
  check_compliance(env, config_manager, opts)
30
- check_http_method_against_headers(env)
32
+ check_http_method_against_headers(env, opts[:contains_body])
31
33
  end
32
34
 
33
35
  # Check jsonapi compliance
@@ -39,7 +41,7 @@ module JSONAPI
39
41
  hdrs = JSONAPI::Parser::HeadersParser.parse(env)
40
42
  usr_opts = { http_method: opts[:http_method], path: opts[:path] }
41
43
  err_msg = JSONAPI::Exceptions::UserDefinedExceptions.check_user_header_requirements(hdrs, config_manager, usr_opts)
42
- return err_msg unless err_msg.nil?
44
+ raise err_msg unless err_msg.nil?
43
45
  end
44
46
 
45
47
  class << self
@@ -78,30 +80,30 @@ module JSONAPI
78
80
  # error if the combination doesn't make sense
79
81
  # @param (see #compliant?)
80
82
  # @raise InvalidHeader the invalid header incombination with the http verb
81
- def check_http_method_against_headers(env)
83
+ def check_http_method_against_headers(env, contains_body)
82
84
  case env['REQUEST_METHOD']
83
85
  when 'GET'
84
- check_get_against_hdrs(env)
86
+ check_get_against_hdrs(env, contains_body)
85
87
  when 'POST' || 'PATCH' || 'PUT'
86
- check_post_against_hdrs(env)
88
+ check_post_against_hdrs(env, contains_body)
87
89
  when 'DELETE'
88
- check_delete_against_hdrs(env)
90
+ check_delete_against_hdrs(env, contains_body)
89
91
  end
90
92
  end
91
93
 
92
94
  # Raise error if a GET request has a body or a content type header
93
95
  # @param (see #compliant?)
94
- def check_get_against_hdrs(env)
95
- raise_error('GET requests cannot have a body.') unless env['rack.input'].nil?
96
+ def check_get_against_hdrs(env, contains_body)
97
+ raise_error('GET requests cannot have a body.') if contains_body
96
98
  raise_error("GET request cannot have a 'CONTENT_TYPE' http header.") unless env['CONTENT_TYPE'].nil?
97
99
  end
98
100
 
99
101
  # POST, PUT, and PATCH request must have a content type header,
100
102
  # a body, and a content-type and accept header that accepts jsonapi
101
103
  # @param (see #compliant?)
102
- def check_post_against_hdrs(env)
104
+ def check_post_against_hdrs(env, contains_body)
103
105
  raise_error("POST, PUT, and PATCH requests must have a 'CONTENT_TYPE' header.") unless env['CONTENT_TYPE']
104
- raise_error('POST, PUT, and PATCH requests must have a body.') unless env['rack.input']
106
+ raise_error('POST, PUT, and PATCH requests must have a body.') unless contains_body
105
107
 
106
108
  return if env['CONTENT_TYPE'] == 'application/vnd.api+json' && accepts_jsonapi?(env)
107
109
 
@@ -109,6 +111,12 @@ module JSONAPI
109
111
  "JSON:API media type, if they include a JSON:API 'CONTENT_TYPE' header")
110
112
  end
111
113
 
114
+ # Raise error if DELETE hdr has a body or a content type header
115
+ def check_delete_against_hdrs(env, contains_body)
116
+ raise_error('DELETE requests cannot have a body.') if contains_body
117
+ raise_error("DELETE request cannot have a 'CONTENT_TYPE' http header.") unless env['CONTENT_TYPE'].nil?
118
+ end
119
+
112
120
  # Check the accept header to see if any of the provided media types indicate that
113
121
  # jsonapi is accepted
114
122
  # @param (see #compliant?)
@@ -121,16 +129,10 @@ module JSONAPI
121
129
  false
122
130
  end
123
131
 
124
- # Raise error if DELETE hdr has a body or a content type header
125
- def check_delete_against_hdrs(env)
126
- raise_error('DELETE requests cannot have a body.') unless env['rack.input'].nil?
127
- raise_error("DELETE request cannot have a 'CONTENT_TYPE' http header.") unless env['CONTENT_TYPE'].nil?
128
- end
129
-
130
132
  # @param accept_hdr [String] The value of the http accept header
131
133
  def contains_at_least_one_jsonapi_media_type_without_params?(accept_hdr)
132
134
  accept_hdr.split(',').each do |mt|
133
- if mt == 'application/vnd.api+json'
135
+ if JSONAPI_MEDIA_TYPES.include? mt
134
136
  return true
135
137
  end
136
138
  end
@@ -33,7 +33,7 @@ module JSONAPI
33
33
  end
34
34
 
35
35
  err_msg = JSONAPI::Exceptions::UserDefinedExceptions.check_user_query_param_requirements(rack_req_params, config_manager, opts)
36
- return err_msg unless err_msg.nil?
36
+ raise err_msg unless err_msg.nil?
37
37
 
38
38
  nil
39
39
  end
@@ -62,8 +62,10 @@ module JSONAPI
62
62
  # with underscores instead of dashes.
63
63
  # @param config (see #check_user_document_requirements)
64
64
  def check_user_header_requirements(headers, config_manager, opts)
65
- return if config_manager.nil? || config_manager.default?
65
+ return if config_manager.nil?
66
+
66
67
  config = get_config(config_manager, opts[:http_method], opts[:path])
68
+ return if config.default? && config_manager.size.positive?
67
69
 
68
70
  err =
69
71
  check_for_required_headers(headers, config.required_headers)
@@ -77,8 +79,10 @@ module JSONAPI
77
79
  # @param rack_req_params [Hash] The hash of the query parameters given by Rack::Request
78
80
  # @param config (see #check_user_document_requirements)
79
81
  def check_user_query_param_requirements(rack_req_params, config_manager, opts)
80
- return if config_manager.nil? || config_manager.default?
82
+ return if config_manager.nil?
83
+
81
84
  config = get_config(config_manager, opts[:http_method], opts[:path])
85
+ return if config.default? && config_manager.size.positive?
82
86
 
83
87
  err =
84
88
  check_for_required_params(rack_req_params, config.required_query_params)
@@ -23,8 +23,8 @@ module JSONAPI
23
23
  # and error if any section is found to be non-compliant.
24
24
  # @param env The rack envirornment hash
25
25
  def call(env)
26
- if in_maintenance_mode?(env)
27
- return maintenance_response(env)
26
+ if in_maintenance_mode?
27
+ return maintenance_response
28
28
  end
29
29
 
30
30
  if jsonapi_request?(env)
@@ -38,17 +38,15 @@ module JSONAPI
38
38
  private
39
39
 
40
40
  # Checks the 'MAINTENANCE' environment variable
41
- # @param (see #call)
42
41
  # @return [TrueClass | FalseClass]
43
- def in_maintenance_mode?(env)
44
- !env['MAINTENANCE'].nil?
42
+ def in_maintenance_mode?
43
+ !ENV['MAINTENANCE'].nil?
45
44
  end
46
45
 
47
46
  # Return 503 with or without msg depending on environment
48
- # @param (see #call)
49
47
  # @return [Array] Http Error Responses
50
- def maintenance_response(env)
51
- if environment_development?(env)
48
+ def maintenance_response
49
+ if environment_development?
52
50
  [503, {}, ['MAINTENANCE envirornment variable set']]
53
51
  else
54
52
  [503, {}, []]
@@ -88,18 +86,21 @@ module JSONAPI
88
86
  # @param config_manager [JSONAPI::ConfigManager::Config] The config object to use modify compliance checking
89
87
  # @return [NilClass | Array] Nil meaning no error or a 400 level http response
90
88
  def check_compliance(env, config_manager)
91
- opts = { http_method: env['REQUEST_METHOD'], path: env['PATH_INFO'] }
89
+ # Store separately so you can rewind for next middleware or app
90
+ body = env['rack.input'].read
91
+ env['rack.input'].rewind
92
+ opts = { http_method: env['REQUEST_METHOD'], path: env['PATH_INFO'], contains_body: body != "" }
92
93
 
93
94
  header_error = check_headers_compliance(env, config_manager, opts)
94
95
  return header_error unless header_error.nil?
95
96
 
96
97
  req = Rack::Request.new(env)
97
- param_error = check_query_param_compliance(env, req.GET, config_manager, opts)
98
+ param_error = check_query_param_compliance(req.GET, config_manager, opts)
98
99
  return param_error unless param_error.nil?
99
100
 
100
101
  return unless env['CONTENT_TYPE']
101
102
 
102
- body_error = check_req_body_compliance(env, config_manager, opts)
103
+ body_error = check_body_compliance(body, config_manager, opts)
103
104
  return body_error unless body_error.nil?
104
105
  end
105
106
 
@@ -108,8 +109,8 @@ module JSONAPI
108
109
  # @return [NilClass | Array] Nil meaning no error or a 400 level http response
109
110
  def check_headers_compliance(env, config_manager, opts)
110
111
  JSONAPI::Exceptions::HeadersExceptions.check_request(env, config_manager, opts)
111
- rescue JSONAPI::Exceptions::HeadersExceptions::InvalidHeader || JSONAPI::Exceptions::UserDefinedExceptions::InvalidHeader => e
112
- raise if environment_development?(env)
112
+ rescue JSONAPI::Exceptions::HeadersExceptions::InvalidHeader, JSONAPI::Exceptions::UserDefinedExceptions::InvalidHeader => e
113
+ raise if environment_development?
113
114
 
114
115
  [e.status_code, {}, []]
115
116
  end
@@ -117,10 +118,10 @@ module JSONAPI
117
118
  # @param query_params [Hash] The rack request query_param hash
118
119
  # @raise If the query parameters are not JSONAPI compliant
119
120
  # @return [NilClass | Array] Nil meaning no error or a 400 level http response
120
- def check_query_param_compliance(env, query_params, config_manager, opts)
121
+ def check_query_param_compliance(query_params, config_manager, opts)
121
122
  JSONAPI::Exceptions::QueryParamsExceptions.check_compliance(query_params, config_manager, opts)
122
- rescue JSONAPI::Exceptions::QueryParamsExceptions::InvalidQueryParameter || JSONAPI::Exceptions::UserDefinedExceptions::InvalidQueryParam => e
123
- raise if environment_development?(env)
123
+ rescue JSONAPI::Exceptions::QueryParamsExceptions::InvalidQueryParameter, JSONAPI::Exceptions::UserDefinedExceptions::InvalidQueryParam => e
124
+ raise if environment_development?
124
125
 
125
126
  [e.status_code, {}, []]
126
127
  end
@@ -128,17 +129,14 @@ module JSONAPI
128
129
  # @param env (see #call)
129
130
  # @param req (see #check_query_param_compliance)
130
131
  # @raise If the document body is not JSONAPI compliant
131
- def check_req_body_compliance(env, config_manager, opts)
132
- # Store separately so you can rewind for next middleware or app
133
- body = env['rack.input'].read
134
- env['rack.input'].rewind
132
+ def check_body_compliance(body, config_manager, opts)
135
133
  JSONAPI::Exceptions::DocumentExceptions.check_compliance(body, config_manager, opts)
136
- rescue JSONAPI::Exceptions::DocumentExceptions::InvalidDocument || JSONAPI::Exceptions::UserDefinedExceptions::InvalidDocument => e
137
- raise if environment_development?(env)
134
+ rescue JSONAPI::Exceptions::DocumentExceptions::InvalidDocument, JSONAPI::Exceptions::UserDefinedExceptions::InvalidDocument => e
135
+ raise if environment_development?
138
136
 
139
137
  [e.status_code, {}, []]
140
138
  rescue JSONAPI::Exceptions::JSONParseError
141
- raise if environment_development?(env)
139
+ raise if environment_development?
142
140
 
143
141
  [400, {}, []]
144
142
  end
@@ -151,8 +149,8 @@ module JSONAPI
151
149
  end
152
150
 
153
151
  # @param (see #call)
154
- def environment_development?(env)
155
- env['RACK_ENV'].to_s.downcase == 'development' || env['RACK_ENV'].nil?
152
+ def environment_development?
153
+ ENV['RACK_ENV'].to_s.downcase == 'development' || ENV['RACK_ENV'].nil?
156
154
  end
157
155
  end
158
156
  end
@@ -21,7 +21,7 @@ module JSONAPI
21
21
  # Convert ruby hash into JSON
22
22
  # @param ruby_hash [Hash] THe hash to convert into JSON
23
23
  def self.dump(ruby_hash)
24
- Oj.dump(ruby_hash)
24
+ Oj.dump(ruby_hash, mode: :compat)
25
25
  end
26
26
 
27
27
  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
- super unless include?(method_name)
47
- get(method_name)
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.2
4
+ version: 1.0.7
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-25 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -140,6 +140,7 @@ files:
140
140
  - ".rubocop.yml"
141
141
  - ".ruby-gemset"
142
142
  - ".ruby-version"
143
+ - ".travis.yml"
143
144
  - CHANGELOG.md
144
145
  - CODE_OF_CONDUCT.md
145
146
  - Gemfile