gemfather 2.2.1 → 2.3.0

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: c09582c0dd342839f92c7bbabe5647e5b121d0793f25f954c79167d89bbe8180
4
+ data.tar.gz: 5545749705cfbd231eb70bdbdb36d5ef83e54e1ddcdb6b10beb7d6ec143752c6
5
5
  SHA512:
6
- metadata.gz: 65063d4799d4281f20878aed55f60ed2273530138400e4ce4d3bab6e19ae4a79c9ca7451f0993838277b6a46b0e26b1fe534388cce620c135dce5acc829e23cc
7
- data.tar.gz: 1cb8c02edb4dd6b74ad69c12275eeb8a4503c0d62b0096af26b5a08573e920c589e79d033560706b0724b90b14324a68657876352fdee0ee54e8d21cae479ff3
6
+ metadata.gz: 5e4a46929223ebb62e86d18357da79f1fbee5007749e993ef94036dab66e7659246f7adb07f33dfa9a3989cb150f8743ae096baf72d09e9febddf4061266095a
7
+ data.tar.gz: a8e3766200d26234b91a35834fc4eadbeb5d0c239ced4753e57df9f36e8375088bfaced32a75af780aeb30baa39bac2bb52ca41c7f377030f4ab1bd159384328
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
 
@@ -10,7 +10,7 @@ module ApiGenerator
10
10
  RETRY_INTERVAL = 1
11
11
  RETRY_BACKOFF_FACTOR = 1
12
12
 
13
- # rubocop:disable Metrics/MethodLength
13
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
14
  def self.extended(klass)
15
15
  klass.extend Dry::Configurable
16
16
 
@@ -33,6 +33,7 @@ module ApiGenerator
33
33
  setting :retry_interval, RETRY_INTERVAL, reader: true
34
34
  setting :retry_backoff_factor, RETRY_BACKOFF_FACTOR, reader: true
35
35
  setting :logger, reader: true
36
+ setting :enable_instrumentation, reader: true
36
37
 
37
38
  setting :retriable_errors,
38
39
  [
@@ -41,7 +42,7 @@ module ApiGenerator
41
42
  reader: true
42
43
  end
43
44
  end
44
- # rubocop:enable Metrics/MethodLength
45
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
45
46
 
46
47
  def check_config
47
48
  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
@@ -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,8 +36,6 @@ module ApiGenerator
32
36
 
33
37
  private
34
38
 
35
- private_class_method :source_root
36
-
37
39
  def check_app_name(app_name)
38
40
  raise(Thor::Error, 'APP_NAME is not provided') unless app_name
39
41
  raise(Thor::Error, "Folder #{app_name} name already exists") if Dir.exist?("./#{app_name}")
@@ -72,10 +74,6 @@ module ApiGenerator
72
74
  chmod(file, EXEC_MODE)
73
75
  end
74
76
  end
75
-
76
- def self.source_root
77
- File.expand_path('./../../../', __dir__)
78
- end
79
77
  end
80
78
  end
81
79
  end
@@ -1,3 +1,3 @@
1
1
  module ApiGenerator
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.3.0'.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.0
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
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.11'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '0.14'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: '0.11'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.14'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: faraday
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +176,7 @@ files:
170
176
  - lib/api_generator/middleware/error_handler_middleware.rb
171
177
  - lib/api_generator/middleware/handle_unsuccessful_request_middleware.rb
172
178
  - lib/api_generator/middleware/http_errors.rb
179
+ - lib/api_generator/middleware/instrumentation.rb
173
180
  - lib/api_generator/middleware/raise_error_base.rb
174
181
  - lib/api_generator/middleware/raise_error_dsl.rb
175
182
  - lib/api_generator/models/base.rb
@@ -222,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
229
  - !ruby/object:Gem::Version
223
230
  version: '0'
224
231
  requirements: []
225
- rubygems_version: 3.2.15
232
+ rubygems_version: 3.1.2
226
233
  signing_key:
227
234
  specification_version: 4
228
235
  summary: 'Gemfather: API client generator'