gemfather-stable 2.2.5 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/services/base_create.rb +1 -1
- data/lib/api_generator/services/gemfather.rb +7 -7
- data/lib/api_generator/version.rb +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18a71b66ba4a336f532fa372a6a5b529827de01dd121a2cfa6a96e4b1aab044
|
4
|
+
data.tar.gz: a44cdc356a8dcc8fcbe5a45ad66c3ad048a2c0c7e1955b2b34e09dad3afea930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 680945767d4b70caa22f18c68295407ff70d54893eea0ac3ad8f92dd3bf98be8f3bfe12821e5f06504c9dfc3d3dc05c03c28c1f6035e687dfaf8a52992e509d7
|
7
|
+
data.tar.gz: e42cae60fe2c2f5952d9ceaa89fb75f8d06327a1baa686a6305623185503ef3c1d955e8e46efc588af21df48391be89c031f5185b7d9b3f6702008fe0ed6d998
|
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,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemfather-stable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domclick Ruby Team and Daniil Kachur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -170,11 +170,13 @@ files:
|
|
170
170
|
- lib/api_generator/middleware/error_handler_middleware.rb
|
171
171
|
- lib/api_generator/middleware/handle_unsuccessful_request_middleware.rb
|
172
172
|
- lib/api_generator/middleware/http_errors.rb
|
173
|
+
- lib/api_generator/middleware/instrumentation.rb
|
173
174
|
- lib/api_generator/middleware/raise_error_base.rb
|
174
175
|
- lib/api_generator/middleware/raise_error_dsl.rb
|
175
176
|
- lib/api_generator/models/base.rb
|
176
177
|
- lib/api_generator/models/data.rb
|
177
178
|
- lib/api_generator/pagination.rb
|
179
|
+
- lib/api_generator/pagination/cursor_relation.rb
|
178
180
|
- lib/api_generator/pagination/dsl.rb
|
179
181
|
- lib/api_generator/pagination/limit_offset_relation.rb
|
180
182
|
- lib/api_generator/pagination/page_relation.rb
|
@@ -197,15 +199,15 @@ files:
|
|
197
199
|
- templates/specs/api_spec.erb
|
198
200
|
- templates/specs/request_spec.erb
|
199
201
|
- templates/specs/response_spec.erb
|
200
|
-
homepage: https://github.com/
|
202
|
+
homepage: https://github.com/domclick/gemfather
|
201
203
|
licenses:
|
202
204
|
- MIT
|
203
205
|
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/
|
206
|
+
bug_tracker_uri: https://github.com/domclick/gemfather/issues
|
207
|
+
changelog_uri: https://github.com/domclick/gemfather/blob/main/CHANGELOG.md
|
208
|
+
documentation_uri: https://github.com/domclick/gemfather/blob/main/README.md
|
209
|
+
homepage_uri: https://github.com/domclick/gemfather
|
210
|
+
source_code_uri: https://github.com/domclick/gemfather
|
209
211
|
rubygems_mfa_required: 'true'
|
210
212
|
post_install_message:
|
211
213
|
rdoc_options: []
|