ecoportal-api 0.9.7 → 0.9.8
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/.rubocop.yml +55 -15
- data/CHANGELOG.md +11 -2
- data/Rakefile +18 -7
- data/lib/ecoportal/api/common/client.rb +26 -4
- data/lib/ecoportal/api/common/response.rb +6 -6
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d89b2ca34f7a85f9cbeaf61331b155fb83b4f80ee8ff9d57133837d4f87bf03f
|
4
|
+
data.tar.gz: 93e71b77a46c283f01708f94099580774cf5d72b49df2041e15688f9622dfe08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f5a46fb757bebae8ac0727ce9ea89d801e5fb3b91aac3146b2117c43f852682ed7bbd3ca7020b43ddde5b1ccdd4c4297bf52afa0fa5a859def1701844caedc
|
7
|
+
data.tar.gz: 4b1fc568bae19759bac6d62badf06a9a949988b7667e87e8b2ec0ab90b5604d67e33ea695117d43bfa329d1706c81bf8fa7244323264052205b49b01bd38c233
|
data/.rubocop.yml
CHANGED
@@ -1,39 +1,71 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7.8
|
3
3
|
Exclude:
|
4
4
|
- 'config/routes.rb'
|
5
|
+
NewCops: enable
|
5
6
|
|
6
|
-
Metrics/
|
7
|
-
|
8
|
-
Metrics/
|
9
|
-
|
10
|
-
Max: 50
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Max: 500
|
9
|
+
Metrics/ModuleLength:
|
10
|
+
Max: 300
|
11
11
|
Metrics/MethodLength:
|
12
12
|
Max: 50
|
13
|
-
Metrics/ClassLength:
|
14
|
-
Max: 200
|
15
13
|
Metrics/AbcSize:
|
16
14
|
Max: 30
|
17
|
-
|
18
|
-
ParameterLists:
|
15
|
+
Metrics/ParameterLists:
|
19
16
|
Max: 5
|
20
17
|
CountKeywordArgs: false
|
18
|
+
Metrics/BlockLength:
|
19
|
+
CountAsOne: ['array', 'heredoc', 'method_call']
|
20
|
+
Max: 50
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Max: 30
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 30
|
21
25
|
|
22
|
-
Style/
|
26
|
+
Style/AccessorGrouping:
|
27
|
+
Enabled: false
|
28
|
+
Style/ConditionalAssignment:
|
29
|
+
Enabled: false
|
30
|
+
Style/BlockDelimiters:
|
31
|
+
BracesRequiredMethods: ['log']
|
32
|
+
AllowedPatterns: ['proc', 'new']
|
33
|
+
Style/ClassAndModuleChildren:
|
23
34
|
Enabled: false
|
24
35
|
Style/FrozenStringLiteralComment:
|
25
36
|
Enabled: false
|
26
|
-
Style/
|
37
|
+
Style/StringLiterals:
|
27
38
|
Enabled: false
|
28
|
-
Style/
|
39
|
+
Style/StringLiteralsInInterpolation:
|
29
40
|
Enabled: false
|
30
41
|
Style/Documentation:
|
31
42
|
Enabled: false
|
32
|
-
Style/
|
43
|
+
Style/CommentedKeyword:
|
44
|
+
Enabled: false
|
45
|
+
Style/MultilineBlockChain:
|
33
46
|
Enabled: false
|
34
47
|
Style/AndOr:
|
35
48
|
Enabled: false
|
49
|
+
Style/Alias:
|
50
|
+
EnforcedStyle: prefer_alias_method
|
51
|
+
Style/FetchEnvVar:
|
52
|
+
Enabled: false
|
53
|
+
Style/RegexpLiteral:
|
54
|
+
EnforcedStyle: mixed
|
55
|
+
AllowInnerSlashes: true
|
36
56
|
|
57
|
+
Layout/HashAlignment:
|
58
|
+
EnforcedColonStyle: table
|
59
|
+
EnforcedHashRocketStyle: table
|
60
|
+
Layout/LeadingCommentSpace:
|
61
|
+
Enabled: false
|
62
|
+
AllowGemfileRubyComment: true
|
63
|
+
Layout/ParameterAlignment:
|
64
|
+
Enabled: false
|
65
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
66
|
+
EnforcedStyle: symmetrical
|
67
|
+
Layout/LineLength:
|
68
|
+
Enabled: true
|
37
69
|
Layout/SpaceInsideHashLiteralBraces:
|
38
70
|
Enabled: false
|
39
71
|
Layout/SpaceInsideBlockBraces:
|
@@ -42,14 +74,22 @@ Layout/SpaceAroundOperators:
|
|
42
74
|
Enabled: false
|
43
75
|
Layout/ExtraSpacing:
|
44
76
|
AllowForAlignment: true
|
77
|
+
AllowBeforeTrailingComments: true
|
45
78
|
Layout/AccessModifierIndentation:
|
46
79
|
EnforcedStyle: indent
|
47
80
|
Layout/DotPosition:
|
48
81
|
EnforcedStyle: trailing
|
49
82
|
Layout/MultilineMethodCallIndentation:
|
50
83
|
EnforcedStyle: indented
|
51
|
-
Layout/
|
84
|
+
Layout/FirstHashElementIndentation:
|
85
|
+
Enabled: false
|
86
|
+
Layout/EmptyLineAfterGuardClause:
|
52
87
|
Enabled: false
|
53
88
|
|
54
89
|
Naming/VariableNumber:
|
55
90
|
EnforcedStyle: snake_case
|
91
|
+
CheckSymbols: false
|
92
|
+
Naming/MethodParameterName:
|
93
|
+
AllowedNames: ['x', 'y', 'i', 'j', 'id', 'io', 'to']
|
94
|
+
Naming/RescuedExceptionsVariableName:
|
95
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.9.8] - 2024-05-15
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `rubocop`
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
- `Ecoportal::API::Common::Client#with_retry`
|
11
|
+
- Make resilient (**re-try**) to recent silent server errors where the body doesn't parse as JSON.
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
4
15
|
## [0.9.7] - 2024-02-03
|
5
16
|
|
6
17
|
### Added
|
@@ -8,8 +19,6 @@ All notable changes to this project will be documented in this file.
|
|
8
19
|
- `Ecoportal::API::V1::Person`
|
9
20
|
- **removed** property `subordinates`
|
10
21
|
|
11
|
-
### Fixed
|
12
|
-
|
13
22
|
## [0.9.6] - 2024-02-03
|
14
23
|
|
15
24
|
### Changed
|
data/Rakefile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
require 'yard'
|
5
|
+
require 'redcarpet'
|
5
6
|
|
6
7
|
desc "run the specs"
|
7
8
|
RSpec::Core::RakeTask.new(:spec)
|
@@ -10,11 +11,18 @@ desc "run rspec showing backtrace"
|
|
10
11
|
RSpec::Core::RakeTask.new(:spec_trace) do |task|
|
11
12
|
task.rspec_opts = ['--backtrace']
|
12
13
|
end
|
14
|
+
task(rspec_trace: :spec_trace)
|
13
15
|
|
14
16
|
desc "run rspec stopping on first fail, and show backtrace"
|
15
17
|
RSpec::Core::RakeTask.new(:spec_fast) do |task|
|
16
18
|
task.rspec_opts = ['--fail-fast', '--backtrace']
|
17
19
|
end
|
20
|
+
task(rspec_fast: :spec_fast)
|
21
|
+
|
22
|
+
desc "run rubocop diaplying cop names"
|
23
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
24
|
+
t.options = ['--display-cop-names']
|
25
|
+
end
|
18
26
|
|
19
27
|
# default task name is yard
|
20
28
|
desc "Yard: generate all the documentation"
|
@@ -22,6 +30,9 @@ YARD::Rake::YardocTask.new(:doc) do |t|
|
|
22
30
|
#t.files = ['lib/**/*.rb']
|
23
31
|
end
|
24
32
|
|
25
|
-
|
26
|
-
task :
|
27
|
-
|
33
|
+
desc "default task: runs rubocop and rspec"
|
34
|
+
task :default do
|
35
|
+
Rake::Task[:rubocop].invoke
|
36
|
+
ensure
|
37
|
+
Rake::Task[:spec].invoke
|
38
|
+
end
|
@@ -13,6 +13,7 @@ module Ecoportal
|
|
13
13
|
class Client
|
14
14
|
include Common::ElasticApmIntegration
|
15
15
|
DELAY_REQUEST_RETRY = 5
|
16
|
+
RETRY_ATTEMPTS = 5
|
16
17
|
|
17
18
|
attr_accessor :logger
|
18
19
|
attr_reader :host
|
@@ -167,22 +168,27 @@ module Ecoportal
|
|
167
168
|
end
|
168
169
|
|
169
170
|
# Helper to ensure unexpected server errors do not bring client scripts immediately down
|
170
|
-
def with_retry(attempts =
|
171
|
+
def with_retry(attempts = RETRY_ATTEMPTS, delay = DELAY_REQUEST_RETRY, error_safe: true, &block)
|
171
172
|
response = nil
|
172
173
|
attempts.times do |i|
|
173
174
|
remaining = attempts - i - 1
|
175
|
+
|
174
176
|
begin
|
175
177
|
response = block.call
|
176
178
|
rescue HTTP::ConnectionError => e
|
177
|
-
raise unless error_safe && remaining
|
179
|
+
raise unless error_safe && remaining.positive?
|
178
180
|
log(:error) { "Got connection error: #{e.message}" }
|
179
181
|
response = with_retry(remaining, error_safe: error_safe, &block)
|
180
182
|
rescue IOError => e
|
181
|
-
raise unless error_safe && remaining
|
183
|
+
raise unless error_safe && remaining.positive?
|
182
184
|
log(:error) { "Got IO error: #{e.message}" }
|
183
185
|
response = with_retry(remaining, error_safe: error_safe, &block)
|
184
186
|
end
|
185
|
-
|
187
|
+
|
188
|
+
return response unless some_unexpected_error?(response)
|
189
|
+
|
190
|
+
puts "re-attempting (remaining: #{remaining} attempts out of #{attempts})"
|
191
|
+
|
186
192
|
log_unexpected_server_error(response)
|
187
193
|
msg = "Got server error (#{response.status}): #{response.body}\n"
|
188
194
|
msg += "Going to retry (#{i} out of #{attempts})"
|
@@ -192,6 +198,22 @@ module Ecoportal
|
|
192
198
|
response
|
193
199
|
end
|
194
200
|
|
201
|
+
# Sometimes response body is wrong but status code
|
202
|
+
# doesn't reflect. Let it retry
|
203
|
+
def some_unexpected_error?(response)
|
204
|
+
unexpected_server_error?(response.status) ||
|
205
|
+
unexpected_body?(response)
|
206
|
+
end
|
207
|
+
|
208
|
+
def unexpected_body?(response)
|
209
|
+
response.body.nil?.tap do |wrong|
|
210
|
+
next unless wrong
|
211
|
+
|
212
|
+
msg = "Received non json body in response "
|
213
|
+
msg << "(#{response.src_body.class}):\n #{response.src_body}"
|
214
|
+
puts
|
215
|
+
end
|
216
|
+
end
|
195
217
|
end
|
196
218
|
end
|
197
219
|
end
|
@@ -2,18 +2,18 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
class Response
|
5
|
-
|
6
5
|
attr_reader :status, :body
|
6
|
+
attr_reader :src_body
|
7
7
|
|
8
8
|
def initialize(response)
|
9
|
-
@status
|
10
|
-
@
|
9
|
+
@status = response.status
|
10
|
+
@src_body = [].tap do |body_data|
|
11
11
|
response.body.each do |chunk|
|
12
12
|
body_data << chunk
|
13
13
|
end
|
14
|
-
end.join
|
15
|
-
|
16
|
-
|
14
|
+
end.join.to_s
|
15
|
+
|
16
|
+
@body = JSON.parse(@src_body) rescue nil
|
17
17
|
end
|
18
18
|
|
19
19
|
def success?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|