ecoportal-api 0.9.8 → 0.10.2
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/.markdownlint.json +4 -0
- data/.rubocop.yml +8 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +234 -174
- data/ecoportal-api.gemspec +26 -17
- data/lib/ecoportal/api/common/base_model.rb +36 -25
- data/lib/ecoportal/api/common/batch_operation.rb +22 -15
- data/lib/ecoportal/api/common/batch_response.rb +2 -5
- data/lib/ecoportal/api/common/client.rb +31 -18
- data/lib/ecoportal/api/common/doc_helpers.rb +1 -1
- data/lib/ecoportal/api/common/response.rb +1 -1
- data/lib/ecoportal/api/common/time_out.rb +26 -0
- data/lib/ecoportal/api/common/wrapped_response.rb +14 -19
- data/lib/ecoportal/api/common.rb +1 -0
- data/lib/ecoportal/api/internal/account.rb +11 -10
- data/lib/ecoportal/api/internal.rb +5 -5
- data/lib/ecoportal/api/logger.rb +11 -9
- data/lib/ecoportal/api/v1/job_status.rb +33 -0
- data/lib/ecoportal/api/v1/people.rb +80 -34
- data/lib/ecoportal/api/v1/person.rb +16 -13
- data/lib/ecoportal/api/v1/person_details.rb +10 -9
- data/lib/ecoportal/api/v1/person_schema.rb +1 -1
- data/lib/ecoportal/api/v1/person_schemas.rb +0 -2
- data/lib/ecoportal/api/v1/schema_field.rb +4 -5
- data/lib/ecoportal/api/v1/schema_field_value.rb +23 -24
- data/lib/ecoportal/api/v1.rb +5 -3
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +63 -64
data/ecoportal-api.gemspec
CHANGED
@@ -1,35 +1,44 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path(
|
1
|
+
# rubocop:disable Gemspec/DevelopmentDependencies
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
4
|
+
|
5
|
+
require 'ecoportal/api/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = "ecoportal-api"
|
8
9
|
spec.version = Ecoportal::API::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Tapio Saarinen']
|
11
|
+
spec.email = [
|
12
|
+
'tapio@ecoportal.co.nz',
|
13
|
+
'oscar@ecoportal.co.nz'
|
14
|
+
]
|
11
15
|
|
12
16
|
spec.summary = %q{A collection of helpers for interacting with the ecoPortal MS's various APIs}
|
13
17
|
spec.homepage = "https://www.ecoportal.com"
|
14
18
|
spec.licenses = %w[MIT]
|
15
19
|
|
16
|
-
spec.
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 3.2.2'
|
17
23
|
|
18
|
-
spec.files
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
25
|
f.match(%r{^(test|spec|features)/})
|
20
26
|
end
|
21
|
-
spec.bindir =
|
27
|
+
spec.bindir = 'exe'
|
22
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
-
spec.require_paths = [
|
29
|
+
spec.require_paths = ['lib']
|
24
30
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency 'pry' , '~> 0.14'
|
32
|
+
spec.add_development_dependency 'rake', '>= 13.0.3', '< 14'
|
33
|
+
spec.add_development_dependency 'redcarpet', '>= 3.6.0', '< 4'
|
34
|
+
spec.add_development_dependency 'rspec', '>= 3.12.0', '< 4'
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1'
|
36
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0'
|
37
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
31
38
|
|
32
|
-
spec.add_dependency '
|
33
|
-
spec.add_dependency 'dotenv', '>= 2.8', "< 3"
|
39
|
+
spec.add_dependency 'dotenv', '~> 3'
|
34
40
|
spec.add_dependency 'elastic-apm', '>= 4.7', "< 5"
|
41
|
+
spec.add_dependency 'http', '~> 5.1', "< 6"
|
35
42
|
end
|
43
|
+
|
44
|
+
# rubocop:enable Gemspec/DevelopmentDependencies
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# rubocop:disable Naming/PredicateName
|
1
2
|
module Ecoportal
|
2
3
|
module API
|
3
4
|
module Common
|
4
5
|
class BaseModel
|
5
|
-
class UnlinkedModel <
|
6
|
-
def initialize
|
7
|
-
msg
|
8
|
-
msg
|
6
|
+
class UnlinkedModel < StandardError
|
7
|
+
def initialize(msg = "Something went wrong when linking the document.", from: nil, key: nil)
|
8
|
+
msg << " From: #{from}." if from
|
9
|
+
msg << " key: #{key}." if key
|
9
10
|
super(msg)
|
10
11
|
end
|
11
12
|
end
|
@@ -25,10 +26,11 @@ module Ecoportal
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
def embeds_one(method, key: method, nullable: false
|
29
|
+
def embeds_one(method, klass:, key: method, nullable: false)
|
29
30
|
method = method.to_s.freeze
|
30
31
|
var = "@#{method}".freeze
|
31
32
|
key = key.to_s.freeze
|
33
|
+
|
32
34
|
define_method(method) do
|
33
35
|
if instance_variable_defined?(var)
|
34
36
|
value = instance_variable_get(var)
|
@@ -36,7 +38,9 @@ module Ecoportal
|
|
36
38
|
return value if (value && doc[key]) || (!value && !doc[key])
|
37
39
|
remove_instance_variable(var)
|
38
40
|
end
|
41
|
+
|
39
42
|
doc[key] ||= {} unless nullable
|
43
|
+
|
40
44
|
return instance_variable_set(var, nil) unless doc[key]
|
41
45
|
|
42
46
|
self.class.resolve_class(klass).new(
|
@@ -44,7 +48,6 @@ module Ecoportal
|
|
44
48
|
).tap {|obj| instance_variable_set(var, obj)}
|
45
49
|
end
|
46
50
|
end
|
47
|
-
|
48
51
|
end
|
49
52
|
|
50
53
|
attr_reader :_parent, :_key
|
@@ -52,28 +55,32 @@ module Ecoportal
|
|
52
55
|
def initialize(doc = {}, parent: self, key: nil)
|
53
56
|
@_parent = parent
|
54
57
|
@_key = key
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
return unless !_parent || !_key
|
60
|
+
|
61
|
+
@doc = JSON.parse(doc.to_json)
|
62
|
+
@original_doc = JSON.parse(@doc.to_json)
|
63
|
+
@initial_doc = JSON.parse(@doc.to_json)
|
60
64
|
end
|
61
65
|
|
62
66
|
def doc
|
63
|
-
raise UnlinkedModel.new(from: "#{self.class}#doc", key: _key)
|
67
|
+
raise UnlinkedModel.new(from: "#{self.class}#doc", key: _key) unless linked?
|
64
68
|
return @doc if is_root?
|
69
|
+
|
65
70
|
_parent.doc.dig(*[_key].flatten)
|
66
71
|
end
|
67
72
|
|
68
73
|
def original_doc
|
69
|
-
raise UnlinkedModel.new(from: "#{self.class}#original_doc", key: _key)
|
74
|
+
raise UnlinkedModel.new(from: "#{self.class}#original_doc", key: _key) unless linked?
|
70
75
|
return @original_doc if is_root?
|
76
|
+
|
71
77
|
_parent.original_doc&.dig(*[_key].flatten)
|
72
78
|
end
|
73
79
|
|
74
80
|
def initial_doc
|
75
|
-
raise UnlinkedModel.new(from: "#{self.class}#initial_doc", key: _key)
|
81
|
+
raise UnlinkedModel.new(from: "#{self.class}#initial_doc", key: _key) unless linked?
|
76
82
|
return @initial_doc if is_root?
|
83
|
+
|
77
84
|
_parent.initial_doc&.dig(*[_key].flatten)
|
78
85
|
end
|
79
86
|
|
@@ -81,6 +88,7 @@ module Ecoportal
|
|
81
88
|
# @return [Hash] `doc` before change
|
82
89
|
def replace_doc!(new_doc)
|
83
90
|
raise UnlinkedModel.new(from: "#{self.class}#replace_doc", key: _key) unless linked?
|
91
|
+
|
84
92
|
@doc.tap do
|
85
93
|
@doc = new_doc
|
86
94
|
end
|
@@ -90,6 +98,7 @@ module Ecoportal
|
|
90
98
|
# @return [Hash] `original_doc` before change
|
91
99
|
def replace_original_doc!(new_doc)
|
92
100
|
raise UnlinkedModel.new(from: "#{self.class}#replace_original_doc", key: _key) unless linked?
|
101
|
+
|
93
102
|
@original_doc.tap do
|
94
103
|
@original_doc = new_doc
|
95
104
|
end
|
@@ -115,7 +124,8 @@ module Ecoportal
|
|
115
124
|
|
116
125
|
# It consolidates all the changes carried by `doc` by setting it as `original_doc`.
|
117
126
|
def consolidate!
|
118
|
-
raise UnlinkedModel.new(from: "#{self.class}#consolidate!", key: _key)
|
127
|
+
raise UnlinkedModel.new(from: "#{self.class}#consolidate!", key: _key) unless linked?
|
128
|
+
|
119
129
|
new_doc = JSON.parse(doc.to_json)
|
120
130
|
if is_root?
|
121
131
|
@original_doc = new_doc
|
@@ -130,18 +140,19 @@ module Ecoportal
|
|
130
140
|
# i.e. `parent.reset!("child")` # when parent.child is `nil`
|
131
141
|
# 2. In such a case, only immediate childs are allowed to be reset
|
132
142
|
# @param key [String, Array<String>, nil] if given, it only resets the specified property
|
133
|
-
def reset!(key = nil)
|
134
|
-
|
135
|
-
raise
|
143
|
+
def reset!(key = nil) # rubocop:disable Metrics/AbcSize>
|
144
|
+
msg = "'key' should be a String. Given #{key}"
|
145
|
+
raise ArgumentError, msg unless !key || key.is_a?(String)
|
146
|
+
raise UnlinkedModel.new(from: "#{self.class}#reset!", key: _key) unless linked?
|
136
147
|
|
137
148
|
if key
|
138
|
-
if
|
149
|
+
if respond_to?(key) && (child = send(key)) && child.is_a?(Ecoportal::API::Common::BaseModel)
|
139
150
|
child.reset!
|
140
151
|
else
|
141
152
|
new_doc = original_doc && original_doc[key]
|
142
153
|
dig_set(doc, [key], new_doc && JSON.parse(new_doc.to_json))
|
143
154
|
# regenerate object if new_doc is null
|
144
|
-
|
155
|
+
send(key) if !new_doc && respond_to?(key)
|
145
156
|
end
|
146
157
|
else
|
147
158
|
new_doc = JSON.parse(original_doc.to_json)
|
@@ -179,17 +190,17 @@ module Ecoportal
|
|
179
190
|
end
|
180
191
|
|
181
192
|
def set_uniq_array_keep_order(key, value)
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
ini_vals = (original_doc && original_doc[key]) || []
|
193
|
+
msg = "#{key}= needs to be passed an Array, got #{value.class}"
|
194
|
+
raise ArgumentError, msg unless value.is_a?(Array)
|
186
195
|
|
196
|
+
ini_vals = (original_doc && original_doc[key]) || []
|
187
197
|
value = value.uniq
|
188
198
|
# preserve original order to avoid false updates
|
189
199
|
doc[key] = ((ini_vals & value) + (value - ini_vals)).compact
|
190
200
|
end
|
191
|
-
|
192
201
|
end
|
193
202
|
end
|
194
203
|
end
|
195
204
|
end
|
205
|
+
|
206
|
+
# rubocop:enable Naming/PredicateName
|
@@ -11,6 +11,10 @@ module Ecoportal
|
|
11
11
|
@logger = logger
|
12
12
|
end
|
13
13
|
|
14
|
+
def count
|
15
|
+
@operations.count
|
16
|
+
end
|
17
|
+
|
14
18
|
def as_json
|
15
19
|
{
|
16
20
|
actions: @operations.map do |operation|
|
@@ -28,19 +32,21 @@ module Ecoportal
|
|
28
32
|
log(:info) { "Processing batch responses" }
|
29
33
|
|
30
34
|
body_data(response.body).each.with_index do |subresponse, idx|
|
31
|
-
callback = @operations[idx][:callback]
|
32
35
|
status = subresponse["status"]
|
33
|
-
body = subresponse["response"]
|
34
36
|
method = @operations[idx][:method]
|
37
|
+
body = subresponse["response"]
|
38
|
+
callback = @operations[idx][:callback]
|
35
39
|
|
36
40
|
if status == 200 && method == "GET"
|
37
41
|
batch_response = BatchResponse.new(status, body, @wrapper.new(body))
|
38
42
|
log_batch_response(@operations[idx], batch_response)
|
39
|
-
|
43
|
+
|
44
|
+
callback&.call(batch_response, batch_response.result)
|
40
45
|
else
|
41
46
|
batch_response = BatchResponse.new(status, body)
|
42
47
|
log_batch_response(@operations[idx], batch_response)
|
43
|
-
|
48
|
+
|
49
|
+
callback&.call(batch_response)
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
@@ -48,9 +54,9 @@ module Ecoportal
|
|
48
54
|
def get(doc, &block)
|
49
55
|
id = get_id(doc)
|
50
56
|
@operations << {
|
51
|
-
path: @base_path
|
57
|
+
path: "#{@base_path}/#{CGI.escape(id)}",
|
52
58
|
method: "GET",
|
53
|
-
callback:
|
59
|
+
callback: block
|
54
60
|
}
|
55
61
|
end
|
56
62
|
|
@@ -58,10 +64,10 @@ module Ecoportal
|
|
58
64
|
id = get_id(doc)
|
59
65
|
body = get_body(doc)
|
60
66
|
@operations << {
|
61
|
-
path: @base_path
|
67
|
+
path: "#{@base_path}/#{CGI.escape(id)}",
|
62
68
|
method: "PATCH",
|
63
69
|
body: body,
|
64
|
-
callback:
|
70
|
+
callback: block
|
65
71
|
}
|
66
72
|
end
|
67
73
|
|
@@ -69,19 +75,19 @@ module Ecoportal
|
|
69
75
|
id = get_id(doc)
|
70
76
|
body = get_body(doc)
|
71
77
|
@operations << {
|
72
|
-
path: @base_path
|
78
|
+
path: "#{@base_path}/#{CGI.escape(id)}",
|
73
79
|
method: "POST",
|
74
80
|
body: body,
|
75
|
-
callback:
|
81
|
+
callback: block
|
76
82
|
}
|
77
83
|
end
|
78
84
|
|
79
85
|
def delete(doc, &block)
|
80
86
|
id = get_id(doc)
|
81
87
|
@operations << {
|
82
|
-
path: @base_path
|
88
|
+
path: "#{@base_path}/#{CGI.escape(id)}",
|
83
89
|
method: "DELETE",
|
84
|
-
callback:
|
90
|
+
callback: block
|
85
91
|
}
|
86
92
|
end
|
87
93
|
|
@@ -91,7 +97,7 @@ module Ecoportal
|
|
91
97
|
path: @base_path,
|
92
98
|
method: "POST",
|
93
99
|
body: body,
|
94
|
-
callback:
|
100
|
+
callback: block
|
95
101
|
}
|
96
102
|
end
|
97
103
|
|
@@ -104,14 +110,15 @@ module Ecoportal
|
|
104
110
|
end
|
105
111
|
|
106
112
|
def log_batch_response(operation, response)
|
107
|
-
level = response.success?? :debug : :warn
|
108
113
|
log(:info) { "BATCH #{operation[:method]} #{operation[:path]}" }
|
109
114
|
log(:info) { "Status #{response.status}" }
|
115
|
+
|
116
|
+
level = response.success?? :debug : :warn
|
110
117
|
log(level) { "Response: #{JSON.pretty_generate(response.body)}" }
|
111
118
|
end
|
112
119
|
|
113
120
|
def log(level, &block)
|
114
|
-
@logger
|
121
|
+
@logger&.send(level, &block)
|
115
122
|
end
|
116
123
|
end
|
117
124
|
end
|
@@ -2,7 +2,6 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
class BatchResponse
|
5
|
-
|
6
5
|
attr_reader :status, :body, :result
|
7
6
|
|
8
7
|
def initialize(status, body, result = nil)
|
@@ -15,10 +14,8 @@ module Ecoportal
|
|
15
14
|
status.success?
|
16
15
|
end
|
17
16
|
|
18
|
-
def each
|
19
|
-
[*@result].each
|
20
|
-
yield doc
|
21
|
-
end
|
17
|
+
def each(&block)
|
18
|
+
[*@result].each(&block)
|
22
19
|
end
|
23
20
|
|
24
21
|
def print_pretty
|
@@ -3,11 +3,16 @@ module Ecoportal
|
|
3
3
|
module API
|
4
4
|
module Common
|
5
5
|
# @note
|
6
|
-
# - You can see the documentation of the `HTTP` module in
|
7
|
-
#
|
8
|
-
# -
|
9
|
-
#
|
10
|
-
# -
|
6
|
+
# - You can see the documentation of the `HTTP` module in
|
7
|
+
# [the repository](https://github.com/httprb/http)
|
8
|
+
# - it does `extend` the module `Chainable`
|
9
|
+
# ([chainable.rb](https://github.com/httprb/http/blob/master/lib/http/chainable.rb)),
|
10
|
+
# - where all the http requests are dev by using `HTTP::Client#request`
|
11
|
+
# ([client.rb](https://github.com/httprb/http/blob/master/lib/http/client.rb))
|
12
|
+
# - which calls `build_request` (new `HTTP::Request`) and `perform`
|
13
|
+
# (new `HTTP::Connection`)
|
14
|
+
# - to return `HTTP::Response`
|
15
|
+
# ([response.rb](https://github.com/httprb/http/blob/master/lib/http/response.rb))
|
11
16
|
# @attr_reader logger [Logger] the logger.
|
12
17
|
# @attr_reader host [String] the remote target server.
|
13
18
|
class Client
|
@@ -31,15 +36,17 @@ module Ecoportal
|
|
31
36
|
@logger = logger
|
32
37
|
@host = host
|
33
38
|
@response_logging_enabled = response_logging
|
39
|
+
|
34
40
|
if host.match(/^localhost|^127\.0\.0\.1/)
|
35
41
|
@base_uri = "http://#{host}/api/"
|
36
42
|
else
|
37
43
|
@base_uri = "https://#{host}/api/"
|
38
44
|
end
|
39
45
|
log(:info) { "#{version} client initialized pointing at #{host}" }
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
|
47
|
+
return unless @api_key.nil? || @api_key.match(/\A\W*\z/)
|
48
|
+
|
49
|
+
log(:error) { "Api-key missing!" }
|
43
50
|
end
|
44
51
|
|
45
52
|
# Logger interface.
|
@@ -52,7 +59,7 @@ module Ecoportal
|
|
52
59
|
# @yield [] generates the message.
|
53
60
|
# @yieldreturn [String] the generated message.
|
54
61
|
def log(level, &block)
|
55
|
-
logger
|
62
|
+
logger&.send(level, &block)
|
56
63
|
end
|
57
64
|
|
58
65
|
# Sends an http `GET` request against the api version using `path` to complete the base url,
|
@@ -127,18 +134,18 @@ module Ecoportal
|
|
127
134
|
Ecoportal::API::Common::Response.new(response)
|
128
135
|
end
|
129
136
|
|
130
|
-
# Creates a HTTP object adding the `X-ApiKey` or `X-ECOPORTAL-API-KEY` param
|
137
|
+
# Creates a HTTP object adding the `X-ApiKey` or `X-ECOPORTAL-API-KEY` param
|
138
|
+
# to the header, depending on the API version.
|
131
139
|
# @note It configures HTTP so it only allows body data in json format.
|
132
140
|
# @return [HTTP] HTTP object.
|
133
141
|
def base_request
|
134
|
-
@base_request ||=
|
142
|
+
@base_request ||=
|
135
143
|
case @version
|
136
144
|
when "v2"
|
137
145
|
HTTP.headers("X-ECOPORTAL-API-KEY" => @api_key).accept(:json)
|
138
146
|
else
|
139
147
|
HTTP.headers("X-ApiKey" => @api_key).accept(:json)
|
140
148
|
end
|
141
|
-
end
|
142
149
|
end
|
143
150
|
|
144
151
|
# Full URl builder of the request
|
@@ -151,19 +158,23 @@ module Ecoportal
|
|
151
158
|
private
|
152
159
|
|
153
160
|
def instrument(method, path, data = nil, &block)
|
154
|
-
raise "Expected block" unless
|
161
|
+
raise "Expected block" unless block_given?
|
162
|
+
|
155
163
|
start_time = Time.now.to_f
|
156
164
|
log(:info) { "#{method} #{url_for(path)}" }
|
157
165
|
log(:debug) { "Data: #{JSON.pretty_generate(data)}" }
|
158
166
|
|
159
167
|
with_retry(&block).tap do |result|
|
160
168
|
end_time = Time.now.to_f
|
161
|
-
log(result.success?? :info : :warn)
|
162
|
-
"Took %.2fs, Status #{result.status}" % (end_time - start_time)
|
163
|
-
|
164
|
-
|
169
|
+
log(result.success?? :info : :warn) {
|
170
|
+
"Took %.2fs, Status #{result.status}" % (end_time - start_time) # rubocop:disable Style/FormatString
|
171
|
+
}
|
172
|
+
|
173
|
+
next unless @response_logging_enabled
|
174
|
+
|
175
|
+
log(result.success?? :debug : :warn) {
|
165
176
|
"Response: #{JSON.pretty_generate(result.body)}"
|
166
|
-
|
177
|
+
}
|
167
178
|
end
|
168
179
|
end
|
169
180
|
|
@@ -190,9 +201,11 @@ module Ecoportal
|
|
190
201
|
puts "re-attempting (remaining: #{remaining} attempts out of #{attempts})"
|
191
202
|
|
192
203
|
log_unexpected_server_error(response)
|
204
|
+
|
193
205
|
msg = "Got server error (#{response.status}): #{response.body}\n"
|
194
206
|
msg += "Going to retry (#{i} out of #{attempts})"
|
195
207
|
log(:error) { msg }
|
208
|
+
|
196
209
|
sleep(delay) if i < attempts
|
197
210
|
end
|
198
211
|
response
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module TimeOut
|
5
|
+
MIN_THROUGHPUT = 0.2 # people per second
|
6
|
+
MIN_SIZE = 10
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def min_throughput
|
11
|
+
self.class::MIN_THROUGHPUT
|
12
|
+
end
|
13
|
+
|
14
|
+
def min_size
|
15
|
+
self.class::MIN_SIZE
|
16
|
+
end
|
17
|
+
|
18
|
+
def timeout_for(count)
|
19
|
+
count = 1 unless count&.positive?
|
20
|
+
count = min_size if count < min_size
|
21
|
+
(count.ceil / min_throughput).ceil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -10,26 +10,24 @@ module Ecoportal
|
|
10
10
|
@response = response
|
11
11
|
@klass = klass
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
@klass.new(@response.body)
|
13
|
+
return unless @response.success?
|
14
|
+
|
15
|
+
@result =
|
16
|
+
if @response.body.is_a?(Array)
|
17
|
+
@response.body.map do |doc|
|
18
|
+
@klass.new(doc)
|
21
19
|
end
|
22
|
-
|
20
|
+
else
|
21
|
+
@klass.new(@response.body)
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def body
|
26
26
|
response.body.to_s
|
27
27
|
end
|
28
28
|
|
29
|
-
def each
|
30
|
-
[*result].each
|
31
|
-
yield doc
|
32
|
-
end
|
29
|
+
def each(&block)
|
30
|
+
[*result].each(&block)
|
33
31
|
end
|
34
32
|
|
35
33
|
def status
|
@@ -41,13 +39,10 @@ module Ecoportal
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def print_pretty
|
44
|
-
if success?
|
45
|
-
each(&:print_pretty)
|
46
|
-
else
|
47
|
-
puts "Request failed."
|
48
|
-
end
|
49
|
-
end
|
42
|
+
return each(&:print_pretty) if success?
|
50
43
|
|
44
|
+
"Request failed."
|
45
|
+
end
|
51
46
|
end
|
52
47
|
end
|
53
48
|
end
|
data/lib/ecoportal/api/common.rb
CHANGED
@@ -11,6 +11,7 @@ require 'ecoportal/api/common/base_model'
|
|
11
11
|
require 'ecoportal/api/common/doc_helpers'
|
12
12
|
require 'ecoportal/api/common/logging'
|
13
13
|
require 'ecoportal/api/common/elastic_apm_integration'
|
14
|
+
require 'ecoportal/api/common/time_out'
|
14
15
|
require 'ecoportal/api/common/client'
|
15
16
|
require 'ecoportal/api/common/response'
|
16
17
|
require 'ecoportal/api/common/wrapped_response'
|
@@ -2,13 +2,14 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class Internal
|
4
4
|
class Account < Common::BaseModel
|
5
|
-
PROPERTIES = [
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
]
|
11
|
-
|
5
|
+
PROPERTIES = %w[
|
6
|
+
user_id policy_group_ids default_tag prefilter
|
7
|
+
permissions_custom permissions_merged preferences
|
8
|
+
login_provider_ids starred_ids landing_page_id
|
9
|
+
accept_eula send_invites force_send_invites
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
passthrough(*PROPERTIES.map(&:to_sym))
|
12
13
|
|
13
14
|
class_resolver :preferences_class, "Ecoportal::API::Internal::Preferences"
|
14
15
|
class_resolver :permissions_class, "Ecoportal::API::Internal::Permissions"
|
@@ -23,11 +24,11 @@ module Ecoportal
|
|
23
24
|
# @return [String, nil] the value set in `default_tag`
|
24
25
|
def default_tag=(value)
|
25
26
|
unless !value || value.is_a?(String)
|
26
|
-
raise ArgumentError
|
27
|
+
raise ArgumentError, "default_tag= needs to be passed a String or nil, got #{value.class}"
|
27
28
|
end
|
28
29
|
if value
|
29
30
|
unless value.match(Ecoportal::API::V1::Person::VALID_TAG_REGEX)
|
30
|
-
raise ArgumentError
|
31
|
+
raise ArgumentError, "Invalid default tag #{value.inspect}"
|
31
32
|
end
|
32
33
|
value = value.upcase
|
33
34
|
end
|
@@ -89,7 +90,7 @@ module Ecoportal
|
|
89
90
|
end
|
90
91
|
|
91
92
|
def as_update(ref = :last, ignore: [])
|
92
|
-
super(ref, ignore: ignore | [
|
93
|
+
super(ref, ignore: ignore | %w[user_id permissions_merged prefilter])
|
93
94
|
end
|
94
95
|
end
|
95
96
|
end
|
@@ -3,12 +3,12 @@ module Ecoportal
|
|
3
3
|
class Internal < V1
|
4
4
|
include Common::Logging
|
5
5
|
|
6
|
-
VERSION = "v0"
|
7
|
-
class_resolver :people_class,
|
8
|
-
class_resolver :person_schemas_class,
|
6
|
+
VERSION = "v0".freeze
|
7
|
+
class_resolver :people_class, "Ecoportal::API::Internal::People"
|
8
|
+
class_resolver :person_schemas_class, "Ecoportal::API::Internal::PersonSchemas"
|
9
9
|
|
10
|
-
class_resolver :policy_groups_class,
|
11
|
-
class_resolver :login_providers_class,
|
10
|
+
class_resolver :policy_groups_class, "Ecoportal::API::Internal::PolicyGroups"
|
11
|
+
class_resolver :login_providers_class, "Ecoportal::API::Internal::LoginProviders"
|
12
12
|
|
13
13
|
# Obtain specific object for policy groups api requests.
|
14
14
|
# @return [PolicyGroups] an instance object ready to make policy groups api requests.
|