kapellmeister 0.9.6 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -9
- data/kapellmeister.gemspec +2 -2
- data/lib/generators/kapellmeister/add_service_generator.rb +0 -5
- data/lib/generators/kapellmeister/templates/lib/third_party/routes.yml.tt +2 -2
- data/lib/kapellmeister/base.rb +2 -0
- data/lib/kapellmeister/dispatcher.rb +9 -3
- data/lib/kapellmeister/requests_extension.rb +1 -1
- data/lib/kapellmeister/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00d0f29f4135cca35f1b74b9eb59e04686a30ce257e7448620fd7131faf73c6f
|
4
|
+
data.tar.gz: feeb5460b5771b5a1974c4a452d0b83f9046dcbc5b1b3e931b3d4c77febf862a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321dd035242112e8ec715b68a7c2df4f10d0a14f8e47839d49b78e4bd81785c104aeac1a0c1a550b24f3badfd95950b79d0386db500c2e50b89d3177b16cda48
|
7
|
+
data.tar.gz: aff7e0ee44980ed3a92d5530ec57d97c7cba429f9d6cf8f876f59a06c7349fccfd4e7dc36f73e725a3dd71c8ffd4258b6ccd20e2f794f027adaa3409fb96032d
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ This template-service allows you to define http requests to a third party throug
|
|
7
7
|
Add kapellmeister to your Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'kapellmeister', '~> 0.
|
10
|
+
gem 'kapellmeister', '~> 0.9.6'
|
11
11
|
```
|
12
12
|
|
13
13
|
### Add new third party configuration:
|
@@ -15,10 +15,15 @@ gem 'kapellmeister', '~> 0.4.1'
|
|
15
15
|
$ bin/rails g kapellmeister:add_service %<ThirdPartyName> %<options> --%<flags>
|
16
16
|
|
17
17
|
`ThirdPartyName` — Pass the lib name, either CamelCased or under_scored
|
18
|
+
|
18
19
|
`options` — Pass the configuration keys, usually host, key and version
|
19
|
-
`flags` — This generator have one flag. This flag is `responder`, default is `false`. If you set to `true` will be generated responder.rb used for parsing response.
|
20
20
|
|
21
|
-
|
21
|
+
`flags` — This generator have one flag.
|
22
|
+
This flag is `responder`, default is `false`.
|
23
|
+
If you set it to `true` will be generated responder.rb used for parsing response.
|
24
|
+
|
25
|
+
All the instructions are lightweight files in your /lib folder.
|
26
|
+
Here's the example of structure:
|
22
27
|
|
23
28
|
``` Capfile
|
24
29
|
└── app
|
@@ -51,16 +56,63 @@ Folder contains `routes scheme`, `client`, `configuration` and optional `respond
|
|
51
56
|
foo: => Wrapper for method
|
52
57
|
bar: => Method name
|
53
58
|
scheme: => Scheme description
|
54
|
-
method: POST => Request type
|
55
|
-
use_wrapper: true => Default true
|
59
|
+
method: POST => Request type (* required)
|
60
|
+
use_wrapper: true => Wrap method for uniqueness. Default true
|
56
61
|
path: buz => Real path
|
57
|
-
|
58
|
-
|
62
|
+
body: => Dry schema for checking parameters. If key doesn't exist nothing happens
|
63
|
+
query_params: => Query params. If key doesn't exist nothing happens
|
64
|
+
mock: => Structure or Path to mock file for tests. If key doesn't exist nothing happens
|
65
|
+
|
66
|
+
# client = ThirdParty::Client.new
|
67
|
+
# client.foo_bar { a: 'b' }
|
68
|
+
# => POST https://third_party.com/foo/buz DATA: { a: 'b' }
|
69
|
+
```
|
70
|
+
#### Parameters explanation:
|
71
|
+
|
72
|
+
`body` — You can use dry-schema for validate request parameters.
|
73
|
+
If this key doesn't exist validation will be skipped.
|
74
|
+
For example:
|
75
|
+
|
76
|
+
```yaml
|
77
|
+
body: CreateSchema
|
78
|
+
```
|
59
79
|
|
60
|
-
|
80
|
+
`query_params` — If request needs a query string.
|
81
|
+
Both arrays and hashes work.
|
82
|
+
If this key doesn't exist validation will be skipped.
|
83
|
+
For example:
|
84
|
+
|
85
|
+
```yaml
|
86
|
+
query_params:
|
87
|
+
dbAct: getCities => For known and unchangeable parameters
|
88
|
+
optional: => For optional parameters
|
89
|
+
- city
|
90
|
+
- state
|
91
|
+
|
92
|
+
# /api?dbAct=getCities&city=Tokio
|
61
93
|
```
|
94
|
+
```yaml
|
95
|
+
query_params:
|
96
|
+
- dbAct: getTarif
|
97
|
+
- org => For required parameters
|
98
|
+
- dest
|
99
|
+
- weight
|
100
|
+
|
101
|
+
# /api?dbAct=getTarif&org=Tokio&dest=Beijing&weight=100
|
102
|
+
```
|
103
|
+
|
104
|
+
`mock` — If you need real requests don't pass during the testing,
|
105
|
+
then you can replace them with mocks.
|
106
|
+
Both yaml structure or path to yaml file can be used.
|
107
|
+
For example:
|
108
|
+
|
109
|
+
```yaml
|
110
|
+
mock: spec/mocks/http_clients/public/cities.yml
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Generated files explanation
|
62
114
|
|
63
|
-
`client.rb` — Nested from main dispatcher and you can add some configuration methods, custom headers
|
115
|
+
`client.rb` — Nested from main dispatcher and you can add some configuration methods, custom headers, requests options, query parameters.
|
64
116
|
|
65
117
|
`configuration.rb` — Add path to third party, config url and logger
|
66
118
|
|
data/kapellmeister.gemspec
CHANGED
@@ -27,8 +27,8 @@ Gem::Specification.new do |gem|
|
|
27
27
|
|
28
28
|
gem.required_ruby_version = '>= 2.4.2'
|
29
29
|
|
30
|
-
gem.add_dependency 'dry-schema', '~> 1.
|
31
|
-
gem.add_dependency 'faraday', '~>
|
30
|
+
gem.add_dependency 'dry-schema', '~> 1.13'
|
31
|
+
gem.add_dependency 'faraday', '~> 2.10'
|
32
32
|
gem.add_dependency 'faraday-cookie_jar', '~> 0.0.7'
|
33
33
|
gem.add_dependency 'faraday_middleware', '~> 1.2'
|
34
34
|
gem.add_dependency 'typhoeus', '~> 1.4.0'
|
@@ -3,8 +3,8 @@
|
|
3
3
|
# bar: => Method name
|
4
4
|
# scheme: => Scheme description
|
5
5
|
# method: POST => Request type (* required)
|
6
|
-
# use_wrapper: true => Default true
|
7
|
-
# path: buz => Real path
|
6
|
+
# use_wrapper: true => Default true
|
7
|
+
# path: buz => Real path
|
8
8
|
# body: => Dry schema for checking parameters. If key doesn't exist nothing happens
|
9
9
|
# query_params: => Query params. If key doesn't exist nothing happens
|
10
10
|
# mock: => Structure or Path to mock file for tests. If key doesn't exist nothing happens
|
data/lib/kapellmeister/base.rb
CHANGED
@@ -41,6 +41,8 @@ def generate_routes(json_scheme)
|
|
41
41
|
|
42
42
|
generate_routes(value).map { |deep_key, deep_value| mapping(deep_key, deep_value, key, scheme) }
|
43
43
|
end
|
44
|
+
rescue TypeError
|
45
|
+
raise "It seems like wrong routes scheme. #{json_scheme}"
|
44
46
|
end
|
45
47
|
|
46
48
|
def mapping(deep_key, deep_value, key, scheme)
|
@@ -44,7 +44,7 @@ class Kapellmeister::Dispatcher
|
|
44
44
|
generated_connection = connection(additional_headers: additional_headers, requests_data: requests_data) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
|
45
45
|
|
46
46
|
process generated_connection.run_request(method_name.downcase.to_sym,
|
47
|
-
url_with_params(path),
|
47
|
+
url_with_params(path, data, method_name),
|
48
48
|
data_json,
|
49
49
|
additional_headers)
|
50
50
|
|
@@ -90,15 +90,21 @@ class Kapellmeister::Dispatcher
|
|
90
90
|
report(data).result
|
91
91
|
end
|
92
92
|
|
93
|
-
def url_with_params(url)
|
93
|
+
def url_with_params(url, data, method_name)
|
94
94
|
url = url.split('/').map do |url_part|
|
95
95
|
url_part.ascii_only? ? url_part : CGI.escape(url_part)
|
96
96
|
end.join('/')
|
97
97
|
|
98
|
+
url = url_repacking(url, data) if method_name == 'GET'
|
99
|
+
|
98
100
|
return url if query_params.blank?
|
99
101
|
|
102
|
+
url_repacking(url, query_params)
|
103
|
+
end
|
104
|
+
|
105
|
+
def url_repacking(url, queries)
|
100
106
|
uri = URI(url)
|
101
|
-
params = URI.decode_www_form(uri.query || '').to_h.merge(
|
107
|
+
params = URI.decode_www_form(uri.query || '').to_h.merge(queries)
|
102
108
|
uri.query = URI.encode_www_form(params)
|
103
109
|
uri.to_s
|
104
110
|
end
|
@@ -63,7 +63,7 @@ end
|
|
63
63
|
def generate_full_path(original_path, data)
|
64
64
|
path = generate_path(original_path, data)
|
65
65
|
query = data.delete(:query_params)&.to_query
|
66
|
-
return "?#{query}"
|
66
|
+
return "?#{query}" if path.blank?
|
67
67
|
|
68
68
|
[path, query].compact_blank!.join('?')
|
69
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kapellmeister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarkWater
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.13'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.10'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday-cookie_jar
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,7 +206,7 @@ licenses:
|
|
206
206
|
metadata:
|
207
207
|
allowed_push_host: https://rubygems.org
|
208
208
|
rubygems_mfa_required: 'true'
|
209
|
-
post_install_message:
|
209
|
+
post_install_message:
|
210
210
|
rdoc_options: []
|
211
211
|
require_paths:
|
212
212
|
- lib
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
requirements: []
|
224
224
|
rubygems_version: 3.3.7
|
225
|
-
signing_key:
|
225
|
+
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: HTTP requests dispatcher
|
228
228
|
test_files: []
|