ecoportal-api 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a66f25a41e7da2e5d0d38efe75ef485e8c4e830a7af80d458170e1f9e44352a9
4
- data.tar.gz: a3b1060723814238dc9b4bbfaa4098b0ae8d8f17320ba4dc9b9c3e33a0a9095c
3
+ metadata.gz: dc651f2474f74b8f767c9df5b4611bd8adefdff75f8e25365135c89561229738
4
+ data.tar.gz: cb7a8ff5c0c03ba7e371f987d6b277c001b33e57716ab6cf03628d28bac53b61
5
5
  SHA512:
6
- metadata.gz: e0fe445e561bbefac97f7fb2eaa7e7b926f60310a0f98d9304f214321c039b04cf610cedeb46b0e5b2ba763139feaba5385df7f4dc2f855327a2f45b03f16888
7
- data.tar.gz: e121969d12d78aded1030e8ff07ef92ab5d71f73b69bc05e4332ff8cc42f7f6e6d43bb6c9143ddfd5a523558e6b928f96d36af2973c0550b1ae9dc200ab149c3
6
+ metadata.gz: f89285565edeaa9cbe4a98970bae8602a943c7c865121a89782f512353a8be74529578eecb4f48e893f546f172425dd38af0759412f53b8fc3a91989d6dbe52a
7
+ data.tar.gz: 4f51e3e6d080745261c033acf511fdd341ebf9f97003f4dda5067c49c9ef51adf966c51cf268e4991e741b45c803fc6c1e821051832c090ba2c685f03c4eaa7d
data/CHANGELOG.md CHANGED
@@ -1,8 +1,34 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.8.4] - 2021-10-xx
4
5
 
5
- ## [0.8.3] - 2021-05-xx
6
+ ### Added
7
+ - `Ecoportal::API::Internal::Permissions` added abilities
8
+ - `visitor_management`, `cross_register_reporting` and `broadcast_notifications`
9
+ - Some yardocs too
10
+ - Some callbacks are done in a non-obvious way and the returned object type was not documented
11
+ - For this reason, some yardocs have been added to some of the parts that have been worked on.
12
+
13
+ ### Fixed
14
+ - `Ecoportal::API::V1::People#create_job`
15
+ - **Removed** call to `BatchOperation#process_response`
16
+ - The method was is already called by `job_result`
17
+ - As a consequence there was a double up of `callbacks`
18
+ - **Fixed** line in wrong position
19
+ - `Ecoportal::API::V1::People#batch`
20
+ - `Ecoportal::API::Common::ElasticApmIntegration#unexpected_server_error?`
21
+ - No code or code lesser than 100 is a server error as well
22
+
23
+ ### Changed
24
+ - `Ecoportal::API::Common::Client`: changed
25
+ - Logging the **response** of batches or batch jobs can be handy when debugging the back-end
26
+ - **removed** method `#without_response_logging`
27
+ - This change entailed to remove dependencies in `Ecoportal::API::V1::People`
28
+ - Specifically in methods `#batch`, `#job_result` and `#create_job`
29
+ - `@response_logging_enabled` to be set in initialization stage (added parameter for `.new`)
30
+
31
+ ## [0.8.3] - 2021-05-24
6
32
 
7
33
  ### Added
8
34
  - `Ecoportal::API::Errors` namespace
@@ -20,12 +20,14 @@ module Ecoportal
20
20
  # @param version [String] it is part of the base url and will determine the api version we query against.
21
21
  # @param host [String] api server domain.
22
22
  # @param logger [Logger] an object with `Logger` interface to generate logs.
23
+ # @param response_logging [Boolean] whether or not batch responses should be logged
23
24
  # @return [Client] an object that holds the configuration of the api connection.
24
- def initialize(api_key:, version: "v1", host: "live.ecoportal.com", logger: nil)
25
+ def initialize(api_key:, version: "v1", host: "live.ecoportal.com", logger: nil, response_logging: false)
25
26
  @version = version
26
27
  @api_key = api_key
27
28
  @logger = logger
28
29
  @host = host
30
+ @response_logging_enabled = response_logging
29
31
  if host.match(/^localhost|^127\.0\.0\.1/)
30
32
  @base_uri = "http://#{host}/api/"
31
33
  else
@@ -35,7 +37,6 @@ module Ecoportal
35
37
  if @api_key.nil? || @api_key.match(/\A\W*\z/)
36
38
  log(:error) { "Api-key missing!" }
37
39
  end
38
- @response_logging_enabled = true
39
40
  end
40
41
 
41
42
  # Logger interface.
@@ -144,15 +145,6 @@ module Ecoportal
144
145
  @base_uri+@version+path
145
146
  end
146
147
 
147
- def without_response_logging(&block)
148
- begin
149
- @response_logging_enabled = false
150
- yield self
151
- ensure
152
- @response_logging_enabled = true
153
- end
154
- end
155
-
156
148
  private
157
149
 
158
150
  def instrument(method, path, data = nil, &block)
@@ -173,12 +165,26 @@ module Ecoportal
173
165
  end
174
166
 
175
167
  # Helper to ensure unexpected server errors do not bring client scripts immediately down
176
- def with_retry(attempts = 3, delay = DELAY_REQUEST_RETRY)
168
+ def with_retry(attempts = 3, delay = DELAY_REQUEST_RETRY, error_safe: true, &block)
177
169
  response = nil
178
170
  attempts.times do |i|
179
- response = yield
171
+ remaining = attempts - i - 1
172
+ begin
173
+ response = block.call
174
+ rescue HTTP::ConnectionError => e
175
+ raise unless error_safe && remaining > 0
176
+ log(:error) { "Got connection error: #{e.message}" }
177
+ response = with_retry(remaining, error_safe: error_safe, &block)
178
+ rescue IOError => e
179
+ raise unless error_safe && remaining > 0
180
+ log(:error) { "Got IO error: #{e.message}" }
181
+ response = with_retry(remaining, error_safe: error_safe, &block)
182
+ end
180
183
  return response unless unexpected_server_error?(response.status)
181
184
  log_unexpected_server_error(response)
185
+ msg = "Got server error (#{response.status}): #{response.body}\n"
186
+ msg += "Going to retry (#{i} out of #{attempts})"
187
+ log(:error) { msg }
182
188
  sleep(delay) if i < attempts
183
189
  end
184
190
  response
@@ -25,7 +25,7 @@ module Ecoportal
25
25
  private
26
26
 
27
27
  def unexpected_server_error?(code)
28
- code && (code >= 500) && (code <= 599)
28
+ !code || ((code >= 500) && (code <= 599)) || (code <= 99)
29
29
  end
30
30
 
31
31
  # finalizer to stop the agent
@@ -6,6 +6,7 @@ module Ecoportal
6
6
  passthrough :organization, :pages, :page_editor, :registers, :tasks
7
7
  passthrough :person_core, :person_core_create, :person_core_edit
8
8
  passthrough :person_details, :person_account, :person_abilities
9
+ passthrough :visitor_management, :broadcast_notifications, :cross_register_reporting
9
10
  end
10
11
  end
11
12
  end
@@ -36,9 +36,16 @@ module Ecoportal
36
36
  puts "\n" unless silent
37
37
  loop do
38
38
  params.update(cursor_id: cursor_id) if cursor_id
39
+ body = nil; response = nil
40
+ loop do
41
+ response = client.get("/people", params: params)
42
+ body = response && body_data(response.body)
43
+ break if response.success?
44
+ puts "Request failed - Status #{response.status}: #{body}"
45
+ end
39
46
  response = client.get("/people", params: params)
40
- body = response && body_data(response.body)
41
- raise "Request failed - Status #{response.status}: #{body}" unless response.success?
47
+ #body = response && body_data(response.body)
48
+ #raise "Request failed - Status #{response.status}: #{body}" unless response.success?
42
49
 
43
50
  unless silent || (total = body["total_results"]) == 0
44
51
  results += body["results"].length
@@ -117,27 +124,27 @@ module Ecoportal
117
124
  # Creates a `BatchOperation` and yields it to the given bock.
118
125
  # @yield [batch_op] adds multiple api requests for the current batch.
119
126
  # @yieldparam batch_op [BatchOperation]
127
+ # @param job_mode [Boolean] whether or not it should use batch jobs
128
+ # @return [Ecoportal::API::Common::Response] the results of the batch
120
129
  def batch(job_mode: true, &block)
121
130
  return job(&block) if job_mode
122
131
  operation = Common::BatchOperation.new("/people", person_class, logger: client.logger)
123
132
  yield operation
124
133
  # The batch operation is responsible for logging the output
125
- client.without_response_logging do
126
- client.post("/people/batch", data: operation.as_json).tap do |response|
127
- operation.process_response(response)
128
- end
134
+ client.post("/people/batch", data: operation.as_json).tap do |response|
135
+ operation.process_response(response)
129
136
  end
130
137
  end
131
138
 
139
+ # @return [Ecoportal::API::Common::Response] the results of the batch job
132
140
  def job
133
141
  operation = Common::BatchOperation.new("/people", person_class, logger: client.logger)
134
142
  yield operation
135
- # The batch operation is responsible for logging the output
136
143
  job_id = create_job(operation)
137
144
  status = wait_for_job_completion(job_id)
138
145
 
139
146
  if status&.complete?
140
- operation.process_response job_result(job_id, operation)
147
+ job_result(job_id, operation)
141
148
  else
142
149
  msg = "Job `#{job_id}` not complete. Probably timeout after #{JOB_TIMEOUT} seconds. Current status: #{status}"
143
150
  raise API::Errors::TimeOut.new msg
@@ -165,12 +172,10 @@ module Ecoportal
165
172
  )
166
173
  end
167
174
 
175
+ # @return [Ecoportal::API::Common::Response] the results of the batch job
168
176
  def job_result(job_id, operation)
169
- # The batch operation is responsible for logging the output
170
- client.without_response_logging do
171
- client.get("/people/job/#{CGI.escape(job_id)}").tap do |response|
172
- operation.process_response(response)
173
- end
177
+ client.get("/people/job/#{CGI.escape(job_id)}").tap do |response|
178
+ operation.process_response(response)
174
179
  end
175
180
  end
176
181
 
@@ -187,12 +192,11 @@ module Ecoportal
187
192
  end
188
193
  end
189
194
 
195
+ # @return [String] the `id` of the created batch job
190
196
  def create_job(operation)
191
197
  job_id = nil
192
- client.without_response_logging do
193
- client.post("/people/job", data: operation.as_json).tap do |response|
194
- job_id = body_data(response.body)["id"] if response.success?
195
- end
198
+ client.post("/people/job", data: operation.as_json).tap do |response|
199
+ job_id = body_data(response.body)["id"] if response.success?
196
200
  raise "Could not create job - Error (#{response.status}): #{body_data(response.body)}" unless job_id
197
201
  end
198
202
  job_id
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.8.3"
3
+ VERSION = "0.8.4"
4
4
  end
5
5
  end
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.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler