request_handler 0.14.0 → 0.15.0

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
- SHA1:
3
- metadata.gz: 20f2c124b0691c7cbff62564b2321b72540198c2
4
- data.tar.gz: e74b4037669ef74419b45aeb90ce128be13b6103
2
+ SHA256:
3
+ metadata.gz: 3ec28a9872f4f531acc1942ec45f37aecb057f2857cf50aa26dede690625c13f
4
+ data.tar.gz: b2c4c2c0131ab55a364265ded644e0151d338e2a2f505d8dd68e9ea35f16a753
5
5
  SHA512:
6
- metadata.gz: 4ab799a4c910ce2363459e7c13d456f506afd10d9e826a83f49ee34ba9a0f8ec1e8162a0779369a1df0d6b3ae253b9bbc517805a5c533ffcc1d9081578223828
7
- data.tar.gz: c2d187403ca7c3f394d685f6ed8999a08d2a17bab13942d8badf9295bca9a2dfd05f7b5d5421943e3a397d5a40a29e60dcd5723c9911ff3b8cf7a79febe4d931
6
+ metadata.gz: 7fe42bb5f624fa531353554ce192e6577299eabec6d66ef465adb6efc995869568173b075c40498fca292d9e248776dd8a3b4bfdc8939e741f9e2a3d1af96160
7
+ data.tar.gz: 0a87c3d8751372650e5ef31f9fd5bdd1421f0472e623f28f1316e8255c88d4e6b06aef2732b54deb7f3f3ce7ca254fffca979a445f265becaf03913710e151c1
data/.travis.yml CHANGED
@@ -1,10 +1,12 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2.7
5
- - 2.3.4
6
- - 2.4.1
7
- - jruby-9.1.12.0
4
+ - 2.2.10
5
+ - 2.3.7
6
+ - 2.4.4
7
+ - 2.5.1
8
+ - jruby-9.1.17.0
9
+ - jruby-9.2.0.0
8
10
  jdk:
9
11
  - oraclejdk8
10
12
  env:
@@ -12,21 +14,27 @@ env:
12
14
  - "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
13
15
  matrix:
14
16
  exclude:
15
- - rvm: 2.2.7
17
+ - rvm: 2.2.10
16
18
  jdk: oraclejdk8
17
19
  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
18
- - rvm: 2.3.4
20
+ - rvm: 2.3.7
19
21
  jdk: oraclejdk8
20
22
  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
21
- - rvm: 2.4.1
23
+ - rvm: 2.4.4
24
+ jdk: oraclejdk8
25
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
26
+ - rvm: 2.5.1
22
27
  jdk: oraclejdk8
23
28
  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
24
29
  allow_failures:
25
- - rvm: jruby-9.1.12.0
30
+ - rvm: jruby-9.1.17.0
31
+ jdk: oraclejdk8
32
+ env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
33
+ - rvm: jruby-9.2.0.0
26
34
  jdk: oraclejdk8
27
35
  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
28
36
  before_install:
29
37
  - gem update --system
30
- - gem install bundler -v 1.15.1
38
+ - gem install bundler -v 1.16.2
31
39
  before_script:
32
40
  - bundle exec danger
data/CHANGELOG.md CHANGED
@@ -1,18 +1,28 @@
1
- Changelog
2
- ===
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
3
 
4
- ## master
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
6
 
6
- ## 0.14.0
7
+ ## [Unreleased]
8
+
9
+ ## [0.15.0] - 2018-06-20
10
+ ### Added
11
+ - JsonParser for non-jsonapi documents in body an multipart files
12
+
13
+ ### Changed
14
+ - changelog format (previous logs kept mostly the same)
15
+
16
+ ## [0.14.0] - 2017-09-11
7
17
 
8
18
  - support generic query params
9
19
 
10
- ## 0.13.0
20
+ ## [0.13.0] - 2017-07-28
11
21
 
12
22
  - sidecar resources for multipart requests can be labeled with required
13
23
  - **remove** support for sidepushing via `included` array in request body.
14
24
 
15
- ## 0.12.0
25
+ ## [0.12.0] - 2017-05-19
16
26
 
17
27
  - support for multipart-requests
18
28
  - update rubocop and fix danger check
@@ -21,65 +31,67 @@ Changelog
21
31
  - no need for 'required' field in fieldsets_parser anymore
22
32
  - throw different errors for each parser, all new errors inherit from ExternalArgumentError
23
33
 
24
- ## 0.11.0
34
+ ## [0.11.0] - 2017-03-17
25
35
 
26
- - Parse `included` array from request body
27
- - Body no longer accepts a default
36
+ - parse `included` array from request body
37
+ - body no longer accepts a default
28
38
 
29
- ## 0.10.0
39
+ ## [0.10.0] - 2017-02-16
30
40
 
31
41
  - raise an error if mandatory options are missing in the handler configuration
32
- - Transform param keys to string before substitution
42
+ - transform param keys to string before substitution
33
43
  - make gem compatible with ruby 2.1
34
44
  - add danger
35
45
  - raise an ExternalArgumentError if the body does not contain data
36
46
 
37
- ## 0.9.1
47
+ ## [0.9.1] - 2017-01-31
38
48
 
39
49
  - fix configure method
40
50
 
41
- ## 0.9.0
51
+ ## [0.9.0] - 2017-01-31
42
52
 
43
53
  - change nesting separator from `_` to `__` and use it consistently (also in sorting fields)
44
54
  - make separator configurable
45
55
 
46
56
 
47
- ## 0.8.0
57
+ ## [0.8.0] - 2017-01-10
58
+
48
59
  - rename gem (dry-request_handler --> request_handler)
49
60
  - remove env based config for logger
50
61
 
51
- ## 0.7.1
62
+ ## [0.7.1] - 2017-01-04
52
63
 
53
64
  - fix usage of struct to be unambiguous if dry-struct is used
54
65
 
55
- ## 0.7
66
+ ## [0.7.0] - 2017-01-03
56
67
 
57
68
  - fix error message building
58
69
  - sort_params returns an array of SortOption structs now
59
70
  - general `headers` method for all headers (removes `authorization_headers` method)
60
71
  - sort and include options will use only the values from the request if they exist and the defaults if there are no values set in the request
61
72
 
62
- ## 0.6
73
+ ## [0.6.0] - 2016-12-14
63
74
 
64
75
  - support for fieldsets
65
76
 
66
- ## 0.5
77
+ ## [0.5.0] - 2016-11-29
67
78
 
68
79
  - `default_size` is now mandatory
69
80
  - `default_size` and `max_size` now must be Integers
70
81
 
71
- ## 0.4
82
+ ## [0.4.0] - 2016-11-16
72
83
 
73
84
  fix error messages to also work with nested error messages
74
85
 
75
- ## 0.3
86
+ ## [0.3.0] - 2016-11-08
76
87
 
77
88
  sort_params returns an array of dtos now `DataTransferObject.new(field: "test", directions: :asc)`
78
89
 
79
- ## 0.2
90
+ ## [0.2.1] - 2016-11-02
80
91
 
81
92
  version bump for publishing
82
93
 
83
- ## 0.1
84
-
85
- Initial Gem
94
+ [Unreleased]: https://github.com/runtastic/request_handler/compare/v0.15.0...HEAD
95
+ [0.15.0]: https://github.com/runtastic/request_handler/compare/v0.14.0...v0.15.0
96
+ [0.14.0]: https://github.com/runtastic/request_handler/compare/v0.13.0...v0.14.0
97
+ [0.13.0]: https://github.com/runtastic/request_handler/compare/v0.12.0...v0.13.0
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Runtastic
3
+ Copyright (c) 2018 runtastic GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -43,7 +43,15 @@ server (at least an empty configuration block int the page block), other options
43
43
  sent by the client are ignored and will cause a warning.
44
44
 
45
45
  Generic query params can be added by using the `query` block. This may be useful
46
- if parameters should be validated which cannot be assigned to other predefined option blocks.
46
+ if parameters should be validated which cannot be assigned to other predefined
47
+ option blocks.
48
+
49
+ A `type` param can be passed in the `body` block, or the `resource` block in
50
+ [multipart requests](#multipart-requests) (like `question` in the example below).
51
+ You can pass either a symbol or a string.
52
+ At the moment there are only "jsonapi" and "json" available for `type`. This
53
+ defines if the JsonApiDocumentParser or JsonParser is used.
54
+ If nothing is defined, JsonApiDocumentParser will be used by default.
47
55
 
48
56
  ```ruby
49
57
  require "dry-validation"
@@ -90,6 +98,7 @@ class DemoHandler < RequestHandler::Base
90
98
  end
91
99
 
92
100
  body do
101
+ type :jsonapi
93
102
  schema(
94
103
  Dry::Validation.JSON do
95
104
  configure do
@@ -161,7 +170,7 @@ sort_options = SortOption.new(:posts__published_on, :asc)
161
170
  It is also possible to process and validate multipart requests, consisting of an arbitrary number of parts.
162
171
  You can require specific resources, all the other listed resources are optional
163
172
 
164
- The following request handler requires a question (which will be uploaded as a json-file) and accepts an additional
173
+ The following request handler requires a question (which will be uploaded as a json-file) and accepts an additional
165
174
  file related to the question
166
175
 
167
176
  ```ruby
@@ -170,15 +179,16 @@ class CreateQuestionHandler < RequestHandler::Base
170
179
  multipart do
171
180
  question do
172
181
  required true
182
+ type "json"
173
183
  schema(
174
184
  Dry::Validation.JSON do
175
185
  required(:id).filled(:str?)
176
186
  required(:type).filled(:str?)
177
- required(:content).filled(:str?)
187
+ required(:content).filled(:str?)
178
188
  end
179
189
  )
180
190
  end
181
-
191
+
182
192
  file do
183
193
  # no validation necessary
184
194
  end
@@ -195,27 +205,23 @@ end
195
205
  Assuming that the request consists of a json file `question.json` containing
196
206
  ``` json
197
207
  {
198
- "data": {
199
- "id": "1",
200
- "type": "questions",
201
- "attributes": {
202
- "content": "How much is the fish?"
203
- }
204
- }
208
+ "id": "1",
209
+ "type": "questions",
210
+ "content": "How much is the fish?"
205
211
  }
206
- ```
212
+ ```
207
213
 
208
214
  and an additional file `image.png`, the resulting `multipart_params` will be the following:
209
215
 
210
216
  ``` ruby
211
217
  {
212
- question:
218
+ question:
213
219
  {
214
220
  id: '1',
215
221
  type: 'questions',
216
222
  content: 'How much is the fish?'
217
223
  },
218
- file:
224
+ file:
219
225
  {
220
226
  filename: 'image.png',
221
227
  type: 'application/octet-stream'
@@ -226,7 +232,7 @@ and an additional file `image.png`, the resulting `multipart_params` will be the
226
232
  }
227
233
  ```
228
234
 
229
- Please note that each part's content has to be uploaded as a separate file currently.
235
+ Please note that each part's content has to be uploaded as a separate file currently.
230
236
 
231
237
  ### Configuration
232
238
 
@@ -109,7 +109,8 @@ module RequestHandler
109
109
  BodyParser.new(
110
110
  request: request,
111
111
  schema: lookup!('body.schema'),
112
- schema_options: execute_options(lookup('body.options'))
112
+ schema_options: execute_options(lookup('body.options')),
113
+ type: lookup('body.type')
113
114
  ).run
114
115
  end
115
116
 
@@ -2,20 +2,23 @@
2
2
 
3
3
  require 'request_handler/schema_parser'
4
4
  require 'request_handler/error'
5
- require 'request_handler/json_api_document_parser'
5
+ require 'request_handler/document_parser'
6
+
6
7
  module RequestHandler
7
8
  class BodyParser
8
- def initialize(request:, schema:, schema_options: {})
9
+ def initialize(request:, schema:, type: nil, schema_options: {})
9
10
  raise MissingArgumentError, "request.body": 'is missing' if request.body.nil?
10
11
  @request = request
11
12
  @schema = schema
12
13
  @schema_options = schema_options
14
+ @type = type
13
15
  end
14
16
 
15
17
  def run
16
- JsonApiDocumentParser.new(
17
- document: request_body,
18
- schema: schema,
18
+ DocumentParser.new(
19
+ type: type,
20
+ document: request_body,
21
+ schema: schema,
19
22
  schema_options: schema_options
20
23
  ).run
21
24
  end
@@ -29,6 +32,6 @@ module RequestHandler
29
32
  b.empty? ? {} : MultiJson.load(b)
30
33
  end
31
34
 
32
- attr_reader :request, :schema, :schema_options
35
+ attr_reader :request, :schema, :schema_options, :type
33
36
  end
34
37
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'request_handler/json_api_document_parser'
4
+ require 'request_handler/json_parser'
5
+
6
+ module RequestHandler
7
+ module DocumentParser
8
+ module_function
9
+
10
+ def new(**args)
11
+ type = args.delete(:type)
12
+ type = type.to_sym unless type.nil?
13
+ PARSER_MAPPING
14
+ .fetch(type) { raise InternalArgumentError.new(detail: "parser for type '#{type}' not found") }
15
+ .new(args)
16
+ end
17
+
18
+ PARSER_MAPPING = {
19
+ nil => JsonApiDocumentParser, # no config defaults to jsonapi
20
+ :jsonapi => JsonApiDocumentParser,
21
+ :json => JsonParser
22
+ }.freeze
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'request_handler/schema_parser'
4
+ require 'request_handler/error'
5
+ module RequestHandler
6
+ class JsonParser < SchemaParser
7
+ def initialize(document:, schema:, schema_options: {})
8
+ raise MissingArgumentError, "json": 'no content sent in document' if document.nil?
9
+ super(schema: schema, schema_options: schema_options)
10
+ @document = document
11
+ end
12
+
13
+ def run
14
+ validate_schema(document)
15
+ end
16
+
17
+ attr_reader :document
18
+ end
19
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'request_handler/error'
4
4
  require 'request_handler/schema_parser'
5
- require 'request_handler/error'
6
- require 'request_handler/json_api_document_parser'
5
+ require 'request_handler/document_parser'
6
+
7
7
  module RequestHandler
8
8
  class MultipartsParser
9
9
  def initialize(request:, multipart_config:)
@@ -35,8 +35,11 @@ module RequestHandler
35
35
  end
36
36
 
37
37
  def parse_data(name)
38
- JsonApiDocumentParser.new(
39
- document: load_json(name),
38
+ data = load_json(name)
39
+ type = lookup("#{name}.type")
40
+ DocumentParser.new(
41
+ type: type,
42
+ document: data,
40
43
  schema: lookup("#{name}.schema"),
41
44
  schema_options: execute_options(lookup("#{name}.options"))
42
45
  ).run
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RequestHandler
4
- VERSION = '0.14.0'.freeze
4
+ VERSION = '0.15.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Eger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-09-11 00:00:00.000000000 Z
12
+ date: 2018-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-validation
@@ -260,6 +260,7 @@ files:
260
260
  - lib/request_handler.rb
261
261
  - lib/request_handler/base.rb
262
262
  - lib/request_handler/body_parser.rb
263
+ - lib/request_handler/document_parser.rb
263
264
  - lib/request_handler/error.rb
264
265
  - lib/request_handler/fieldsets_parser.rb
265
266
  - lib/request_handler/filter_parser.rb
@@ -267,6 +268,7 @@ files:
267
268
  - lib/request_handler/helper.rb
268
269
  - lib/request_handler/include_option_parser.rb
269
270
  - lib/request_handler/json_api_document_parser.rb
271
+ - lib/request_handler/json_parser.rb
270
272
  - lib/request_handler/multipart_parser.rb
271
273
  - lib/request_handler/option_parser.rb
272
274
  - lib/request_handler/page_parser.rb
@@ -296,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
298
  version: '0'
297
299
  requirements: []
298
300
  rubyforge_project:
299
- rubygems_version: 2.6.13
301
+ rubygems_version: 2.7.6
300
302
  signing_key:
301
303
  specification_version: 4
302
304
  summary: shared base for request_handler using dry-* gems