gemfather 2.2.1 → 2.3.1

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: 2d710977302c99d922728945fcbdd442c7f1335820c9856d07852e3589a3fdd1
4
- data.tar.gz: b489b32109592bfe1c0d20a1942cd3dd2e03ab7aa1d3537a9288089f83d8fb3e
3
+ metadata.gz: b76d8257b078b1c9a56c0c3fb4dff29509b2fb2da8862e682e2c2902c775b858
4
+ data.tar.gz: 0b4d42add75aa92abf940832cae146804053d183fd8d5aa7e4fccd18b615e64b
5
5
  SHA512:
6
- metadata.gz: 65063d4799d4281f20878aed55f60ed2273530138400e4ce4d3bab6e19ae4a79c9ca7451f0993838277b6a46b0e26b1fe534388cce620c135dce5acc829e23cc
7
- data.tar.gz: 1cb8c02edb4dd6b74ad69c12275eeb8a4503c0d62b0096af26b5a08573e920c589e79d033560706b0724b90b14324a68657876352fdee0ee54e8d21cae479ff3
6
+ metadata.gz: fcb5fca115a0d15433419d9eefe531c0e30b16a9253831b469ea43d24fc0a84a795b055536ff5bf18004ea9294915f03d35fa37865633dc15132ab9a048efcf9
7
+ data.tar.gz: 9696bfe5be260edb7b29093aef9db3181d4c1ecdaf0a4cb43e6ba6f9d4e4619d44aa171bacfdd7808845ef7e0c5a9249968cd53c36465a5850bea96e69b9073a
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) вы можете найти известные проблемы, которые можно исправить и идеи для улучшений.
@@ -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 = '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
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
 
@@ -9,14 +9,15 @@ module ApiGenerator
9
9
  MAX_RETRIES = 3
10
10
  RETRY_INTERVAL = 1
11
11
  RETRY_BACKOFF_FACTOR = 1
12
+ CONNECTION_ERROR = ApiGenerator::Middleware::HttpErrors::ConnectionError
12
13
 
13
- # rubocop:disable Metrics/MethodLength
14
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
15
  def self.extended(klass)
15
16
  klass.extend Dry::Configurable
16
17
 
17
18
  klass.class_eval do
18
19
  setting :api_endpoint, reader: true
19
- setting :user_agent, USER_AGENT, reader: true
20
+ setting :user_agent, default: USER_AGENT, reader: true
20
21
 
21
22
  setting :api_header, reader: true
22
23
  setting :api_token, reader: true
@@ -27,21 +28,18 @@ module ApiGenerator
27
28
  setting :ssl_verify, reader: true
28
29
  setting :ca_file, reader: true
29
30
 
30
- setting :open_timeout, OPEN_TIMEOUT, reader: true
31
- setting :read_timeout, READ_TIMEOUT, reader: true
32
- setting :max_retries, MAX_RETRIES, reader: true
33
- setting :retry_interval, RETRY_INTERVAL, reader: true
34
- setting :retry_backoff_factor, RETRY_BACKOFF_FACTOR, reader: true
31
+ setting :open_timeout, default: OPEN_TIMEOUT, reader: true
32
+ setting :read_timeout, default: READ_TIMEOUT, reader: true
33
+ setting :max_retries, default: MAX_RETRIES, reader: true
34
+ setting :retry_interval, default: RETRY_INTERVAL, reader: true
35
+ setting :retry_backoff_factor, default: RETRY_BACKOFF_FACTOR, reader: true
35
36
  setting :logger, reader: true
37
+ setting :enable_instrumentation, reader: true
36
38
 
37
- setting :retriable_errors,
38
- [
39
- ApiGenerator::Middleware::HttpErrors::ConnectionError,
40
- ],
41
- reader: true
39
+ setting :retriable_errors, default: [CONNECTION_ERROR], reader: true
42
40
  end
43
41
  end
44
- # rubocop:enable Metrics/MethodLength
42
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
45
43
 
46
44
  def check_config
47
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,10 @@
1
+ module ApiGenerator
2
+ module Middleware
3
+ class Instrumentation < Faraday::Request::Instrumentation
4
+ def call(env)
5
+ env[:gemfather_api_client] = Thread.current[:gemfather_api_client]
6
+ super(env)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -33,7 +33,7 @@ module ApiGenerator
33
33
  end
34
34
 
35
35
  def source_root
36
- gemfather_lib_path = $LOAD_PATH.grep(/gemfather/).first
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,12 +36,13 @@ module ApiGenerator
32
36
 
33
37
  private
34
38
 
35
- private_class_method :source_root
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}")
43
+ raise(Thor::Error, 'Api name can start only with letter or _') if app_name.chr.match(/[a-zA-Z_]/).nil?
40
44
  end
45
+ # rubocop:enable Layout/LineLength
41
46
 
42
47
  def setup_template_variables(app_name)
43
48
  self.app_name = app_name
@@ -72,10 +77,6 @@ module ApiGenerator
72
77
  chmod(file, EXEC_MODE)
73
78
  end
74
79
  end
75
-
76
- def self.source_root
77
- File.expand_path('./../../../', __dir__)
78
- end
79
80
  end
80
81
  end
81
82
  end
@@ -1,3 +1,3 @@
1
1
  module ApiGenerator
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfather
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domclick Ruby Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-03 00:00:00.000000000 Z
11
+ date: 2023-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -170,6 +170,7 @@ 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
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  - !ruby/object:Gem::Version
223
224
  version: '0'
224
225
  requirements: []
225
- rubygems_version: 3.2.15
226
+ rubygems_version: 3.1.6
226
227
  signing_key:
227
228
  specification_version: 4
228
229
  summary: 'Gemfather: API client generator'