request_handler 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -0
- data/lib/request_handler/base.rb +13 -0
- data/lib/request_handler/query_parser.rb +23 -0
- data/lib/request_handler/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20f2c124b0691c7cbff62564b2321b72540198c2
|
4
|
+
data.tar.gz: e74b4037669ef74419b45aeb90ce128be13b6103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ab799a4c910ce2363459e7c13d456f506afd10d9e826a83f49ee34ba9a0f8ec1e8162a0779369a1df0d6b3ae253b9bbc517805a5c533ffcc1d9081578223828
|
7
|
+
data.tar.gz: c2d187403ca7c3f394d685f6ed8999a08d2a17bab13942d8badf9295bca9a2dfd05f7b5d5421943e3a397d5a40a29e60dcd5723c9911ff3b8cf7a79febe4d931
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,9 @@ Please note that pagination only considers options that are configured on the
|
|
42
42
|
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
|
+
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.
|
47
|
+
|
45
48
|
```ruby
|
46
49
|
require "dry-validation"
|
47
50
|
require "request_handler"
|
@@ -78,6 +81,14 @@ class DemoHandler < RequestHandler::Base
|
|
78
81
|
# options({foo: "bar"}) # also works for hash options instead of procs
|
79
82
|
end
|
80
83
|
|
84
|
+
query do
|
85
|
+
schema(
|
86
|
+
Dry::Validation.Form do
|
87
|
+
optional(:name).filled(:str?)
|
88
|
+
end
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
81
92
|
body do
|
82
93
|
schema(
|
83
94
|
Dry::Validation.JSON do
|
data/lib/request_handler/base.rb
CHANGED
@@ -8,6 +8,7 @@ require 'request_handler/header_parser'
|
|
8
8
|
require 'request_handler/body_parser'
|
9
9
|
require 'request_handler/multipart_parser'
|
10
10
|
require 'request_handler/fieldsets_parser'
|
11
|
+
require 'request_handler/query_parser'
|
11
12
|
require 'request_handler/helper'
|
12
13
|
require 'confstruct'
|
13
14
|
module RequestHandler
|
@@ -65,6 +66,10 @@ module RequestHandler
|
|
65
66
|
@fieldsets_params ||= parse_fieldsets_params
|
66
67
|
end
|
67
68
|
|
69
|
+
def query_params
|
70
|
+
@query_params ||= parse_query_params
|
71
|
+
end
|
72
|
+
|
68
73
|
# @abstract Subclass is expected to implement #to_dto
|
69
74
|
# !method to_dto
|
70
75
|
# take the parsed values and return as application specific data transfer object
|
@@ -121,6 +126,14 @@ module RequestHandler
|
|
121
126
|
required: lookup('fieldsets.required') || []).run
|
122
127
|
end
|
123
128
|
|
129
|
+
def parse_query_params
|
130
|
+
QueryParser.new(
|
131
|
+
params: params,
|
132
|
+
schema: lookup!('query.schema'),
|
133
|
+
schema_options: execute_options(lookup('query.options'))
|
134
|
+
).run
|
135
|
+
end
|
136
|
+
|
124
137
|
def fetch_defaults(key, default)
|
125
138
|
value = lookup(key)
|
126
139
|
return default if value.nil?
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'request_handler/schema_parser'
|
4
|
+
require 'request_handler/error'
|
5
|
+
module RequestHandler
|
6
|
+
class QueryParser < SchemaParser
|
7
|
+
RESERVED_KEYS = %w[fields filter include page sort].freeze
|
8
|
+
|
9
|
+
def initialize(params:, schema:, schema_options: {})
|
10
|
+
super(schema: schema, schema_options: schema_options)
|
11
|
+
@query = params.dup
|
12
|
+
RESERVED_KEYS.each { |key| query.delete(key) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
validate_schema(query)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :query
|
22
|
+
end
|
23
|
+
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.
|
4
|
+
version: 0.14.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-
|
12
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-validation
|
@@ -270,6 +270,7 @@ files:
|
|
270
270
|
- lib/request_handler/multipart_parser.rb
|
271
271
|
- lib/request_handler/option_parser.rb
|
272
272
|
- lib/request_handler/page_parser.rb
|
273
|
+
- lib/request_handler/query_parser.rb
|
273
274
|
- lib/request_handler/schema_parser.rb
|
274
275
|
- lib/request_handler/sort_option.rb
|
275
276
|
- lib/request_handler/sort_option_parser.rb
|
@@ -295,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
296
|
version: '0'
|
296
297
|
requirements: []
|
297
298
|
rubyforge_project:
|
298
|
-
rubygems_version: 2.6.
|
299
|
+
rubygems_version: 2.6.13
|
299
300
|
signing_key:
|
300
301
|
specification_version: 4
|
301
302
|
summary: shared base for request_handler using dry-* gems
|