ecoportal-api 0.8.5 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +20 -20
- data/.rspec +3 -3
- data/.rubocop.yml +55 -55
- data/.travis.yml +5 -5
- data/.yardopts +10 -10
- data/CHANGELOG.md +257 -236
- data/Gemfile +6 -6
- data/LICENSE +21 -21
- data/README.md +34 -34
- data/Rakefile +27 -27
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/ecoportal-api.gemspec +36 -36
- data/lib/ecoportal/api/common/base_class.rb +33 -29
- data/lib/ecoportal/api/common/base_model.rb +195 -177
- data/lib/ecoportal/api/common/batch_operation.rb +119 -119
- data/lib/ecoportal/api/common/batch_response.rb +34 -34
- data/lib/ecoportal/api/common/client.rb +198 -196
- data/lib/ecoportal/api/common/doc_helpers.rb +29 -29
- data/lib/ecoportal/api/common/elastic_apm_integration.rb +112 -112
- data/lib/ecoportal/api/common/hash_diff.rb +41 -41
- data/lib/ecoportal/api/common/logging.rb +12 -12
- data/lib/ecoportal/api/common/response.rb +31 -31
- data/lib/ecoportal/api/common/wrapped_response.rb +54 -54
- data/lib/ecoportal/api/common.rb +18 -18
- data/lib/ecoportal/api/errors/base.rb +8 -8
- data/lib/ecoportal/api/errors/time_out.rb +8 -8
- data/lib/ecoportal/api/errors.rb +9 -9
- data/lib/ecoportal/api/internal/account.rb +99 -100
- data/lib/ecoportal/api/internal/login_provider.rb +9 -9
- data/lib/ecoportal/api/internal/login_providers.rb +33 -33
- data/lib/ecoportal/api/internal/people.rb +14 -14
- data/lib/ecoportal/api/internal/permissions.rb +14 -13
- data/lib/ecoportal/api/internal/person.rb +101 -53
- data/lib/ecoportal/api/internal/person_details.rb +9 -9
- data/lib/ecoportal/api/internal/person_schema.rb +10 -10
- data/lib/ecoportal/api/internal/person_schemas.rb +11 -11
- data/lib/ecoportal/api/internal/policy_group.rb +9 -9
- data/lib/ecoportal/api/internal/policy_groups.rb +32 -32
- data/lib/ecoportal/api/internal/preferences.rb +31 -31
- data/lib/ecoportal/api/internal/schema_field.rb +8 -8
- data/lib/ecoportal/api/internal/schema_field_value.rb +8 -8
- data/lib/ecoportal/api/internal.rb +31 -31
- data/lib/ecoportal/api/logger.rb +62 -62
- data/lib/ecoportal/api/v1/people.rb +218 -218
- data/lib/ecoportal/api/v1/person.rb +138 -135
- data/lib/ecoportal/api/v1/person_details.rb +94 -82
- data/lib/ecoportal/api/v1/person_schema.rb +53 -53
- data/lib/ecoportal/api/v1/person_schemas.rb +48 -48
- data/lib/ecoportal/api/v1/schema_field.rb +34 -34
- data/lib/ecoportal/api/v1/schema_field_value.rb +65 -65
- data/lib/ecoportal/api/v1.rb +49 -49
- data/lib/ecoportal/api/version.rb +5 -5
- data/lib/ecoportal/api.rb +16 -16
- metadata +3 -3
@@ -1,119 +1,119 @@
|
|
1
|
-
module Ecoportal
|
2
|
-
module API
|
3
|
-
module Common
|
4
|
-
class BatchOperation
|
5
|
-
include Common::DocHelpers
|
6
|
-
|
7
|
-
def initialize(base_path, wrapper, logger: nil)
|
8
|
-
@base_path = base_path
|
9
|
-
@wrapper = wrapper
|
10
|
-
@operations = []
|
11
|
-
@logger = logger
|
12
|
-
end
|
13
|
-
|
14
|
-
def as_json
|
15
|
-
{
|
16
|
-
actions: @operations.map do |operation|
|
17
|
-
operation.slice(:path, :method, :body)
|
18
|
-
end
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def process_response(response)
|
23
|
-
unless response.success?
|
24
|
-
log(:error) { "Total failure in batch operation." }
|
25
|
-
raise "Total failure in batch operation"
|
26
|
-
end
|
27
|
-
|
28
|
-
log(:info) { "Processing batch responses" }
|
29
|
-
|
30
|
-
body_data(response.body).each.with_index do |subresponse, idx|
|
31
|
-
callback = @operations[idx][:callback]
|
32
|
-
status = subresponse["status"]
|
33
|
-
body = subresponse["response"]
|
34
|
-
method = @operations[idx][:method]
|
35
|
-
|
36
|
-
if status == 200 && method == "GET"
|
37
|
-
batch_response = BatchResponse.new(status, body, @wrapper.new(body))
|
38
|
-
log_batch_response(@operations[idx], batch_response)
|
39
|
-
callback && callback.call(batch_response, batch_response.result)
|
40
|
-
else
|
41
|
-
batch_response = BatchResponse.new(status, body)
|
42
|
-
log_batch_response(@operations[idx], batch_response)
|
43
|
-
callback && callback.call(batch_response)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def get(doc)
|
49
|
-
id = get_id(doc)
|
50
|
-
@operations << {
|
51
|
-
path: @base_path + "/" + CGI::escape(id),
|
52
|
-
method: "GET",
|
53
|
-
callback: block_given? && Proc.new
|
54
|
-
}
|
55
|
-
end
|
56
|
-
|
57
|
-
def update(doc)
|
58
|
-
id = get_id(doc)
|
59
|
-
body = get_body(doc)
|
60
|
-
@operations << {
|
61
|
-
path: @base_path + "/" + CGI::escape(id),
|
62
|
-
method: "PATCH",
|
63
|
-
body: body,
|
64
|
-
callback: block_given? && Proc.new
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
def upsert(doc)
|
69
|
-
id = get_id(doc)
|
70
|
-
body = get_body(doc)
|
71
|
-
@operations << {
|
72
|
-
path: @base_path + "/" + CGI::escape(id),
|
73
|
-
method: "POST",
|
74
|
-
body: body,
|
75
|
-
callback: block_given? && Proc.new
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
def delete(doc)
|
80
|
-
id = get_id(doc)
|
81
|
-
@operations << {
|
82
|
-
path: @base_path + "/" + CGI::escape(id),
|
83
|
-
method: "DELETE",
|
84
|
-
callback: block_given? && Proc.new
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
def create(doc)
|
89
|
-
body = get_body(doc)
|
90
|
-
@operations << {
|
91
|
-
path: @base_path,
|
92
|
-
method: "POST",
|
93
|
-
body: body,
|
94
|
-
callback: block_given? && Proc.new
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
# Hook for other api versions to obtain the raw data of a response
|
101
|
-
# @note this was introduced to allow `v2` to reuse this class
|
102
|
-
def body_data(body)
|
103
|
-
body
|
104
|
-
end
|
105
|
-
|
106
|
-
def log_batch_response(operation, response)
|
107
|
-
level = response.success?? :debug : :warn
|
108
|
-
log(:info) { "BATCH #{operation[:method]} #{operation[:path]}" }
|
109
|
-
log(:info) { "Status #{response.status}" }
|
110
|
-
log(level) { "Response: #{JSON.pretty_generate(response.body)}" }
|
111
|
-
end
|
112
|
-
|
113
|
-
def log(level, &block)
|
114
|
-
@logger.send(level, &block) if @logger
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
class BatchOperation
|
5
|
+
include Common::DocHelpers
|
6
|
+
|
7
|
+
def initialize(base_path, wrapper, logger: nil)
|
8
|
+
@base_path = base_path
|
9
|
+
@wrapper = wrapper
|
10
|
+
@operations = []
|
11
|
+
@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def as_json
|
15
|
+
{
|
16
|
+
actions: @operations.map do |operation|
|
17
|
+
operation.slice(:path, :method, :body)
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_response(response)
|
23
|
+
unless response.success?
|
24
|
+
log(:error) { "Total failure in batch operation." }
|
25
|
+
raise "Total failure in batch operation"
|
26
|
+
end
|
27
|
+
|
28
|
+
log(:info) { "Processing batch responses" }
|
29
|
+
|
30
|
+
body_data(response.body).each.with_index do |subresponse, idx|
|
31
|
+
callback = @operations[idx][:callback]
|
32
|
+
status = subresponse["status"]
|
33
|
+
body = subresponse["response"]
|
34
|
+
method = @operations[idx][:method]
|
35
|
+
|
36
|
+
if status == 200 && method == "GET"
|
37
|
+
batch_response = BatchResponse.new(status, body, @wrapper.new(body))
|
38
|
+
log_batch_response(@operations[idx], batch_response)
|
39
|
+
callback && callback.call(batch_response, batch_response.result)
|
40
|
+
else
|
41
|
+
batch_response = BatchResponse.new(status, body)
|
42
|
+
log_batch_response(@operations[idx], batch_response)
|
43
|
+
callback && callback.call(batch_response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get(doc)
|
49
|
+
id = get_id(doc)
|
50
|
+
@operations << {
|
51
|
+
path: @base_path + "/" + CGI::escape(id),
|
52
|
+
method: "GET",
|
53
|
+
callback: block_given? && Proc.new
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def update(doc)
|
58
|
+
id = get_id(doc)
|
59
|
+
body = get_body(doc)
|
60
|
+
@operations << {
|
61
|
+
path: @base_path + "/" + CGI::escape(id),
|
62
|
+
method: "PATCH",
|
63
|
+
body: body,
|
64
|
+
callback: block_given? && Proc.new
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def upsert(doc)
|
69
|
+
id = get_id(doc)
|
70
|
+
body = get_body(doc)
|
71
|
+
@operations << {
|
72
|
+
path: @base_path + "/" + CGI::escape(id),
|
73
|
+
method: "POST",
|
74
|
+
body: body,
|
75
|
+
callback: block_given? && Proc.new
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete(doc)
|
80
|
+
id = get_id(doc)
|
81
|
+
@operations << {
|
82
|
+
path: @base_path + "/" + CGI::escape(id),
|
83
|
+
method: "DELETE",
|
84
|
+
callback: block_given? && Proc.new
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def create(doc)
|
89
|
+
body = get_body(doc)
|
90
|
+
@operations << {
|
91
|
+
path: @base_path,
|
92
|
+
method: "POST",
|
93
|
+
body: body,
|
94
|
+
callback: block_given? && Proc.new
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# Hook for other api versions to obtain the raw data of a response
|
101
|
+
# @note this was introduced to allow `v2` to reuse this class
|
102
|
+
def body_data(body)
|
103
|
+
body
|
104
|
+
end
|
105
|
+
|
106
|
+
def log_batch_response(operation, response)
|
107
|
+
level = response.success?? :debug : :warn
|
108
|
+
log(:info) { "BATCH #{operation[:method]} #{operation[:path]}" }
|
109
|
+
log(:info) { "Status #{response.status}" }
|
110
|
+
log(level) { "Response: #{JSON.pretty_generate(response.body)}" }
|
111
|
+
end
|
112
|
+
|
113
|
+
def log(level, &block)
|
114
|
+
@logger.send(level, &block) if @logger
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module Ecoportal
|
2
|
-
module API
|
3
|
-
module Common
|
4
|
-
class BatchResponse
|
5
|
-
|
6
|
-
attr_reader :status, :body, :result
|
7
|
-
|
8
|
-
def initialize(status, body, result = nil)
|
9
|
-
@status = HTTP::Response::Status.new(status)
|
10
|
-
@body = body
|
11
|
-
@result = result
|
12
|
-
end
|
13
|
-
|
14
|
-
def success?
|
15
|
-
status.success?
|
16
|
-
end
|
17
|
-
|
18
|
-
def each
|
19
|
-
[*@result].each do |doc|
|
20
|
-
yield doc
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def print_pretty
|
25
|
-
if success?
|
26
|
-
each(&:print_pretty)
|
27
|
-
else
|
28
|
-
puts "Request failed."
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
class BatchResponse
|
5
|
+
|
6
|
+
attr_reader :status, :body, :result
|
7
|
+
|
8
|
+
def initialize(status, body, result = nil)
|
9
|
+
@status = HTTP::Response::Status.new(status)
|
10
|
+
@body = body
|
11
|
+
@result = result
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
status.success?
|
16
|
+
end
|
17
|
+
|
18
|
+
def each
|
19
|
+
[*@result].each do |doc|
|
20
|
+
yield doc
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_pretty
|
25
|
+
if success?
|
26
|
+
each(&:print_pretty)
|
27
|
+
else
|
28
|
+
puts "Request failed."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|