kapellmeister 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe79b6fb67ba56c68ef8f1ae0c8f617856027bd63092193f32c11ced913db7f8
4
- data.tar.gz: 80f2ff06ffcb6b91da5610162d52a5c8648d60a0d22991ffe90a175998424bf3
3
+ metadata.gz: 62a0e8ed962461f5c86bd781a7b8d6c3003ddc30e0001edd8efcf0da42081d64
4
+ data.tar.gz: fd56000ef1fdd4c06feeed14650ca9c902b444f26fe2a453f613f8d2b055bc14
5
5
  SHA512:
6
- metadata.gz: acfe492025285fe11843ba4bdd3a911f793ae3c980afb46281b9490df7096005f246f585722587d2103d1d56f9b4568aa3082392f29640fff61f35c5fd1926bb
7
- data.tar.gz: 916c8280053a15b9fbccfc7ddab4941219d1309331b019e40879523fe0b05300ba802d5ad306e4492245a47871e919aca8c184f0cab17ad581d56fa24dfd18be
6
+ metadata.gz: f73144f388ef871cd0d4233ad9ae925513a79bc297f520c51ed91f3e81eb0b0a48a0bbdd28b2627f6fef976c6f314e64368c1076a91364109ec7555a07698aa1
7
+ data.tar.gz: 7d001a857e5fa55206a6932eb5c73c151718586731bd1fd11c60796d7a74df57a618692b45c411e51f1b1a848b64da83a7de0370e5336754d028fbcb4e3606dc
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.4.1'
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
- All the instructions are lightweight files in your /lib folder. Here's the example of structure:
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
- mock: => Mock for development
58
- token: blablabla
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
- # ThirdParty::Client.foo_bar { a: 'b' } => POST https://third_party.com/foo/buz DATA: { a: 'b' }
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 and requests options.
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
 
@@ -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 (* required)
7
- # path: buz => Real path (* required)
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
@@ -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(query_params)
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}" unless path
66
+ return "?#{query}" if path.blank?
67
67
 
68
68
  [path, query].compact_blank!.join('?')
69
69
  end
@@ -1,3 +1,3 @@
1
1
  module Kapellmeister
2
- VERSION = '0.9.6'.freeze
2
+ VERSION = '0.9.7'.freeze
3
3
  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.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarkWater
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-schema
@@ -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: []