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: 0e631d6496a32223a78647bd0e8e20351460609198fcb39120cbc6ee8dcb5e89
4
- data.tar.gz: 8eceda8b7ce7eb04814e7646bcec2c2aba7e156688e585d228ba075da87b8105
3
+ metadata.gz: cd4199c88095416464c53ed94e3090b45d05fe9be355c1bd1b2bcc88028b80e4
4
+ data.tar.gz: 6a338d9883dc24fd62e89ba20123449ed34be1ebfa50a8dd5a80464760d500d4
5
5
  SHA512:
6
- metadata.gz: 525fd231428f4978cf354812a02101a43b006e29b40e0b00c66ea0d4f529a684dda5ea7ee91ddc2f10ef06b20426e725d4f01ad366c51cf4f7fa4c0f629a0f18
7
- data.tar.gz: b6da1d6c14f39bfbcfb402fd741e693315765c75791570efdd27e290cee0feda98c323abaad0fa43dd68ec3a135ff1c36f08f549225198dd636d12d271cd1652
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
- module SchemaBuilder
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HttpClientGenerator
4
- VERSION = '0.1.25'
4
+ VERSION = '0.1.26'
5
5
  end
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.25
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