http-client-generator 0.1.25 → 0.1.26
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd4199c88095416464c53ed94e3090b45d05fe9be355c1bd1b2bcc88028b80e4
|
4
|
+
data.tar.gz: 6a338d9883dc24fd62e89ba20123449ed34be1ebfa50a8dd5a80464760d500d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 843142bf98fa45cc08e907087a8e734f741ff9c2211dcaa722c4199fd3210960481e1d28e2010dfbb9b266509fac51c76b6bcf54c9c0eb23461d944c0fef801f
|
7
|
+
data.tar.gz: e8fdc7462c2c700ba6492948d89070829f3c518ba9612d06d72f59baa4628d48a2c7e198e1226cdcecc7f2c6e9c96d43815ebf157f56a549c9101fb99e2ed421
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HttpClientGenerator
|
4
|
+
module SchemaBuilder
|
5
|
+
def self.included(base)
|
6
|
+
super
|
7
|
+
|
8
|
+
require 'datacaster'
|
9
|
+
base.extend(self)
|
10
|
+
end
|
11
|
+
|
12
|
+
def schema_for(name, kind: :choosy, &block)
|
13
|
+
@schemas ||= {}
|
14
|
+
@schemas[name] =
|
15
|
+
case kind
|
16
|
+
in :choosy
|
17
|
+
Datacaster.choosy_schema(&block)
|
18
|
+
in :partial
|
19
|
+
Datacaster.partial_schema(&block)
|
20
|
+
in :strict
|
21
|
+
Datacaster.schema(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_singleton_method(name) do |params|
|
25
|
+
@schemas[name].(params)
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method(name) do |params|
|
29
|
+
@schemas[name].(params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HttpClientGenerator
|
4
|
+
class Plugs
|
5
|
+
class ValidateRequest
|
6
|
+
Plugs.register :validate_request, self
|
7
|
+
|
8
|
+
def initialize(schema_helper:)
|
9
|
+
@schema_helper = schema_helper
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(req)
|
13
|
+
schema_name = :"#{req.name}_#{req.verb}"
|
14
|
+
|
15
|
+
return req unless @schema_helper.respond_to?(schema_name)
|
16
|
+
|
17
|
+
req.response_body = @schema_helper.public_send(schema_name, req.body)
|
18
|
+
.value_or { |e| req.raise_message("Unexpected #{e.inspect} in #{req.body}") }
|
19
|
+
|
20
|
+
req
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -5,31 +5,8 @@ module HttpClientGenerator
|
|
5
5
|
class ValidateResponse
|
6
6
|
Plugs.register :validate_response, self
|
7
7
|
|
8
|
-
|
9
|
-
def self.included(base)
|
10
|
-
super
|
11
|
-
|
12
|
-
require 'datacaster'
|
13
|
-
base.extend(self)
|
14
|
-
end
|
15
|
-
|
16
|
-
def schema_for(name, &block)
|
17
|
-
@schemas ||= {}
|
18
|
-
@schemas[name] = Datacaster.choosy_schema(&block)
|
19
|
-
|
20
|
-
define_singleton_method(name) do |params|
|
21
|
-
@schemas[name].(params)
|
22
|
-
end
|
23
|
-
|
24
|
-
define_method(name) do |params|
|
25
|
-
@schemas[name].(params)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(schema_helper:, strict: false)
|
8
|
+
def initialize(schema_helper:)
|
31
9
|
@schema_helper = schema_helper
|
32
|
-
@strict = strict
|
33
10
|
end
|
34
11
|
|
35
12
|
def call(req)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-client-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Egorov
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- lib/http_client_generator.rb
|
50
|
+
- lib/http_client_generator/base_schema_builder.rb
|
50
51
|
- lib/http_client_generator/plugs.rb
|
51
52
|
- lib/http_client_generator/plugs/camelize_body.rb
|
52
53
|
- lib/http_client_generator/plugs/encode_json_response.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- lib/http_client_generator/plugs/set_header.rb
|
56
57
|
- lib/http_client_generator/plugs/set_request_id.rb
|
57
58
|
- lib/http_client_generator/plugs/underscore_response.rb
|
59
|
+
- lib/http_client_generator/plugs/validate_request.rb
|
58
60
|
- lib/http_client_generator/plugs/validate_response.rb
|
59
61
|
- lib/http_client_generator/request.rb
|
60
62
|
- lib/http_client_generator/resource.rb
|