gemfather-stable 2.2.5 → 2.4.2
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 +4 -4
- data/README.md +4 -0
- data/gem_template/%app_name%.gemspec.tt +1 -1
- data/gem_template/README.md.tt +8 -7
- data/lib/api_generator/client/config.rb +3 -2
- data/lib/api_generator/client/connection.rb +23 -2
- data/lib/api_generator/middleware/error_handler_middleware.rb +6 -6
- data/lib/api_generator/middleware/instrumentation.rb +10 -0
- data/lib/api_generator/pagination/cursor_relation.rb +19 -0
- data/lib/api_generator/pagination/dsl.rb +1 -0
- data/lib/api_generator/pagination/relation.rb +2 -0
- data/lib/api_generator/services/base_create.rb +1 -1
- data/lib/api_generator/services/gemfather.rb +7 -7
- data/lib/api_generator/version.rb +1 -1
- metadata +11 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6489f67332e2f46bd6dc8cab1205a9157a9a37fd78aa44bdd1f01429e388fbb8
|
4
|
+
data.tar.gz: b1a2ad1040ddccdfd937492f6f047bd1980cfe3e6aca74315a9ecda300700dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fdc710758e5cf675de5f750951a4673d28e122b529e055917d1022c47fd91098507dda53ef2f924c62712372724ccb936abf3cd016766d5ac49ae0cf01bc717
|
7
|
+
data.tar.gz: 6ca400bf694efaded5e105a87c6e6cfa25f9d8f436de0d6f4b014f46e91918447266fa9abd68350e565842697f07d558bcd11881335fcfc3b35a04322fa9ec73
|
data/README.md
CHANGED
@@ -143,3 +143,7 @@ client.find_offers(company_id: 1).page(2).total
|
|
143
143
|
# Получение общего количество элементов на всех страницах в сумме (сначала загрузит все страницы)
|
144
144
|
client.find_offers(company_id: 1).page(2).total!
|
145
145
|
```
|
146
|
+
|
147
|
+
## Улучшения.
|
148
|
+
|
149
|
+
В файле [TODO.md](/TODO.md) вы можете найти известные проблемы, которые можно исправить и идеи для улучшений.
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_dependency 'addressable', '~> 2.3'
|
26
26
|
spec.add_dependency 'dry-configurable', '~> 0.11'
|
27
|
-
spec.add_dependency 'gemfather
|
27
|
+
spec.add_dependency 'gemfather', '~> <%= version %>'
|
28
28
|
spec.add_dependency 'faraday', '>= 0.17', '< 2'
|
29
29
|
spec.add_dependency 'faraday_middleware', '>= 0.13', '< 2'
|
30
30
|
spec.add_dependency 'hashie', '>= 3.0', '< 5'
|
data/gem_template/README.md.tt
CHANGED
@@ -26,13 +26,14 @@ gem '<%= app_name %>'
|
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
<%= app_name_class %>::Client.configure do |config|
|
29
|
-
config.api_endpoint
|
30
|
-
config.api_user
|
31
|
-
config.api_password
|
32
|
-
config.open_timeout
|
33
|
-
config.read_timeout
|
34
|
-
config.user_agent
|
35
|
-
config.logger
|
29
|
+
config.api_endpoint = 'https://<%= app_name %>.dev/'
|
30
|
+
config.api_user = 'user'
|
31
|
+
config.api_password = 'password'
|
32
|
+
config.open_timeout = 5
|
33
|
+
config.read_timeout = 5
|
34
|
+
config.user_agent = 'info for debugging' # default is `Ruby <%= app_name_class %> API Client`
|
35
|
+
config.logger = Logger.new(STDERR) # по дефолту `Rails.logger` в development окружении, в других - nil
|
36
|
+
config.enable_instrumentation = true # под дефолту выключен, включает отправку метрик гему domclick_bigbrother через ActiveSupport::Notifications
|
36
37
|
end
|
37
38
|
```
|
38
39
|
|
@@ -11,7 +11,7 @@ module ApiGenerator
|
|
11
11
|
RETRY_BACKOFF_FACTOR = 1
|
12
12
|
CONNECTION_ERROR = ApiGenerator::Middleware::HttpErrors::ConnectionError
|
13
13
|
|
14
|
-
# rubocop:disable Metrics/MethodLength
|
14
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
15
15
|
def self.extended(klass)
|
16
16
|
klass.extend Dry::Configurable
|
17
17
|
|
@@ -34,11 +34,12 @@ module ApiGenerator
|
|
34
34
|
setting :retry_interval, default: RETRY_INTERVAL, reader: true
|
35
35
|
setting :retry_backoff_factor, default: RETRY_BACKOFF_FACTOR, reader: true
|
36
36
|
setting :logger, reader: true
|
37
|
+
setting :enable_instrumentation, reader: true
|
37
38
|
|
38
39
|
setting :retriable_errors, default: [CONNECTION_ERROR], reader: true
|
39
40
|
end
|
40
41
|
end
|
41
|
-
# rubocop:enable Metrics/MethodLength
|
42
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
42
43
|
|
43
44
|
def check_config
|
44
45
|
raise ConfigurationError, 'API endpoint is not configured.' if config.api_endpoint.nil?
|
@@ -52,8 +52,10 @@ module ApiGenerator
|
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
|
-
# rubocop:disable Metrics/MethodLength
|
55
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
56
56
|
def connection
|
57
|
+
set_instrumentation_context
|
58
|
+
|
57
59
|
@connection ||= Faraday.new(url: self.class.api_endpoint) do |connection|
|
58
60
|
setup_auth!(connection)
|
59
61
|
|
@@ -65,6 +67,7 @@ module ApiGenerator
|
|
65
67
|
setup_error_handling!(connection)
|
66
68
|
setup_error_code_middleware!(connection)
|
67
69
|
setup_ssl(connection)
|
70
|
+
setup_instrumentation!(connection)
|
68
71
|
|
69
72
|
customize_connection!(connection)
|
70
73
|
|
@@ -74,7 +77,7 @@ module ApiGenerator
|
|
74
77
|
connection.adapter(Faraday.default_adapter)
|
75
78
|
end
|
76
79
|
end
|
77
|
-
# rubocop:enable Metrics/MethodLength
|
80
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
78
81
|
|
79
82
|
# rubocop:disable Metrics/AbcSize
|
80
83
|
def setup_auth!(connection)
|
@@ -109,6 +112,24 @@ module ApiGenerator
|
|
109
112
|
connection.response(:logger, self.class.logger) if self.class.logger
|
110
113
|
end
|
111
114
|
|
115
|
+
def setup_instrumentation!(connection)
|
116
|
+
return unless self.class.enable_instrumentation
|
117
|
+
|
118
|
+
connection.use ApiGenerator::Middleware::Instrumentation,
|
119
|
+
name: 'gemfather_api_client.requests'
|
120
|
+
end
|
121
|
+
|
122
|
+
def set_instrumentation_context
|
123
|
+
return unless self.class.enable_instrumentation
|
124
|
+
|
125
|
+
action = caller_locations(4, 1)&.first&.label || 'unparsed_method'
|
126
|
+
|
127
|
+
Thread.current[:gemfather_api_client] = {
|
128
|
+
name: self.class.to_s,
|
129
|
+
action: action,
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
112
133
|
def setup_ssl(connection)
|
113
134
|
connection.ssl.verify = self.class.ssl_verify
|
114
135
|
connection.ssl.ca_file = self.class.ca_file
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module ApiGenerator
|
2
2
|
module Middleware
|
3
3
|
class ErrorHandlerMiddleware < Faraday::Middleware
|
4
|
+
FARADAY_CONNECTION_ERRORS = [
|
5
|
+
Faraday::TimeoutError,
|
6
|
+
Faraday::ConnectionFailed,
|
7
|
+
Faraday::SSLError,
|
8
|
+
].freeze
|
9
|
+
|
4
10
|
def self.inherited(subclass)
|
5
11
|
class << subclass
|
6
12
|
attr_accessor :error_namespace
|
@@ -10,12 +16,6 @@ module ApiGenerator
|
|
10
16
|
super
|
11
17
|
end
|
12
18
|
|
13
|
-
FARADAY_CONNECTION_ERRORS = [
|
14
|
-
Faraday::TimeoutError,
|
15
|
-
Faraday::ConnectionFailed,
|
16
|
-
Faraday::SSLError,
|
17
|
-
].freeze
|
18
|
-
|
19
19
|
def call(env)
|
20
20
|
@app.call(env)
|
21
21
|
rescue *FARADAY_CONNECTION_ERRORS => e
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ApiGenerator::Pagination::CursorRelation < ApiGenerator::Pagination::Relation
|
2
|
+
def size(size)
|
3
|
+
expand(size: size)
|
4
|
+
end
|
5
|
+
|
6
|
+
def next_cursor(cursor)
|
7
|
+
expand(next_cursor: cursor)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def next_relation
|
13
|
+
expand(next_cursor: response['cursor'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def last_page?
|
17
|
+
response['cursor'].nil?
|
18
|
+
end
|
19
|
+
end
|
@@ -33,7 +33,7 @@ module ApiGenerator
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def source_root
|
36
|
-
gemfather_lib_path = $LOAD_PATH.grep(/
|
36
|
+
gemfather_lib_path = $LOAD_PATH.grep(%r{gems/gemfather}).first
|
37
37
|
|
38
38
|
return File.expand_path('../', gemfather_lib_path) if gemfather_lib_path
|
39
39
|
|
@@ -10,6 +10,10 @@ module ApiGenerator
|
|
10
10
|
attr_accessor :app_name, :app_name_class, :app_short_name,
|
11
11
|
:app_short_name_class, :author, :email, :version
|
12
12
|
|
13
|
+
def self.source_root
|
14
|
+
File.expand_path('./../../../', __dir__)
|
15
|
+
end
|
16
|
+
|
13
17
|
# rubocop:disable Metrics/MethodLength
|
14
18
|
desc 'generates API gem', 'generates basic API gem with the provided name'
|
15
19
|
def generate_client(app_name)
|
@@ -32,13 +36,13 @@ module ApiGenerator
|
|
32
36
|
|
33
37
|
private
|
34
38
|
|
35
|
-
|
36
|
-
|
39
|
+
# rubocop:disable Layout/LineLength
|
37
40
|
def check_app_name(app_name)
|
38
41
|
raise(Thor::Error, 'APP_NAME is not provided') unless app_name
|
39
42
|
raise(Thor::Error, "Folder #{app_name} name already exists") if Dir.exist?("./#{app_name}")
|
40
|
-
raise(Thor::Error,
|
43
|
+
raise(Thor::Error, 'Api name can start only with letter or _') if app_name.chr.match(/[a-zA-Z_]/).nil?
|
41
44
|
end
|
45
|
+
# rubocop:enable Layout/LineLength
|
42
46
|
|
43
47
|
def setup_template_variables(app_name)
|
44
48
|
self.app_name = app_name
|
@@ -73,10 +77,6 @@ module ApiGenerator
|
|
73
77
|
chmod(file, EXEC_MODE)
|
74
78
|
end
|
75
79
|
end
|
76
|
-
|
77
|
-
def self.source_root
|
78
|
-
File.expand_path('./../../../', __dir__)
|
79
|
-
end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemfather-stable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domclick Ruby Team and Daniil Kachur
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -133,7 +132,6 @@ dependencies:
|
|
133
132
|
- !ruby/object:Gem::Version
|
134
133
|
version: '2.2'
|
135
134
|
description: Library that helps to generate high-quality API clients
|
136
|
-
email:
|
137
135
|
executables:
|
138
136
|
- gemfather
|
139
137
|
extensions: []
|
@@ -170,11 +168,13 @@ files:
|
|
170
168
|
- lib/api_generator/middleware/error_handler_middleware.rb
|
171
169
|
- lib/api_generator/middleware/handle_unsuccessful_request_middleware.rb
|
172
170
|
- lib/api_generator/middleware/http_errors.rb
|
171
|
+
- lib/api_generator/middleware/instrumentation.rb
|
173
172
|
- lib/api_generator/middleware/raise_error_base.rb
|
174
173
|
- lib/api_generator/middleware/raise_error_dsl.rb
|
175
174
|
- lib/api_generator/models/base.rb
|
176
175
|
- lib/api_generator/models/data.rb
|
177
176
|
- lib/api_generator/pagination.rb
|
177
|
+
- lib/api_generator/pagination/cursor_relation.rb
|
178
178
|
- lib/api_generator/pagination/dsl.rb
|
179
179
|
- lib/api_generator/pagination/limit_offset_relation.rb
|
180
180
|
- lib/api_generator/pagination/page_relation.rb
|
@@ -197,17 +197,16 @@ files:
|
|
197
197
|
- templates/specs/api_spec.erb
|
198
198
|
- templates/specs/request_spec.erb
|
199
199
|
- templates/specs/response_spec.erb
|
200
|
-
homepage: https://github.com/
|
200
|
+
homepage: https://github.com/domclick/gemfather
|
201
201
|
licenses:
|
202
202
|
- MIT
|
203
203
|
metadata:
|
204
|
-
bug_tracker_uri: https://github.com/
|
205
|
-
changelog_uri: https://github.com/
|
206
|
-
documentation_uri: https://github.com/
|
207
|
-
homepage_uri: https://github.com/
|
208
|
-
source_code_uri: https://github.com/
|
204
|
+
bug_tracker_uri: https://github.com/domclick/gemfather/issues
|
205
|
+
changelog_uri: https://github.com/domclick/gemfather/blob/main/CHANGELOG.md
|
206
|
+
documentation_uri: https://github.com/domclick/gemfather/blob/main/README.md
|
207
|
+
homepage_uri: https://github.com/domclick/gemfather
|
208
|
+
source_code_uri: https://github.com/domclick/gemfather
|
209
209
|
rubygems_mfa_required: 'true'
|
210
|
-
post_install_message:
|
211
210
|
rdoc_options: []
|
212
211
|
require_paths:
|
213
212
|
- lib
|
@@ -222,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
221
|
- !ruby/object:Gem::Version
|
223
222
|
version: '0'
|
224
223
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
226
|
-
signing_key:
|
224
|
+
rubygems_version: 3.6.2
|
227
225
|
specification_version: 4
|
228
226
|
summary: 'Gemfather: API client generator'
|
229
227
|
test_files: []
|