reach-ruby 1.0.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 +7 -0
- data/.dockerignore +1 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +58 -0
- data/.rubocop_todo.yml +193 -0
- data/AUTHORS.md +52 -0
- data/CHANGES.md +3 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +163 -0
- data/Dockerfile +9 -0
- data/Gemfile +3 -0
- data/ISSUE_TEMPLATE.md +30 -0
- data/LICENSE +21 -0
- data/Makefile +34 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +237 -0
- data/Rakefile +10 -0
- data/UPGRADE.md +5 -0
- data/VERSIONS.md +35 -0
- data/advanced-examples/custom-http-client.md +166 -0
- data/examples/examples.rb +23 -0
- data/githooks/pre-commit +1 -0
- data/lib/rack/reach_webhook_authentication.rb +72 -0
- data/lib/reach-ruby/framework/reach_response.rb +19 -0
- data/lib/reach-ruby/framework/request.rb +41 -0
- data/lib/reach-ruby/framework/response.rb +18 -0
- data/lib/reach-ruby/framework/rest/domain.rb +39 -0
- data/lib/reach-ruby/framework/rest/error.rb +51 -0
- data/lib/reach-ruby/framework/rest/helper.rb +11 -0
- data/lib/reach-ruby/framework/rest/page.rb +144 -0
- data/lib/reach-ruby/framework/rest/resource.rb +23 -0
- data/lib/reach-ruby/framework/rest/version.rb +240 -0
- data/lib/reach-ruby/framework/serialize.rb +81 -0
- data/lib/reach-ruby/framework/values.rb +9 -0
- data/lib/reach-ruby/http/http_client.rb +82 -0
- data/lib/reach-ruby/http.rb +5 -0
- data/lib/reach-ruby/rest/api/authentix/.openapi-generator/FILES +10 -0
- data/lib/reach-ruby/rest/api/authentix/.openapi-generator/VERSION +1 -0
- data/lib/reach-ruby/rest/api/authentix/.openapi-generator-ignore +23 -0
- data/lib/reach-ruby/rest/api/authentix/authentication_trial_item.rb +418 -0
- data/lib/reach-ruby/rest/api/authentix/authentication_trial_stat_item.rb +279 -0
- data/lib/reach-ruby/rest/api/authentix/configuration_item/authentication_control_item.rb +214 -0
- data/lib/reach-ruby/rest/api/authentix/configuration_item/authentication_item.rb +449 -0
- data/lib/reach-ruby/rest/api/authentix/configuration_item.rb +583 -0
- data/lib/reach-ruby/rest/api/authentix.rb +72 -0
- data/lib/reach-ruby/rest/api/messaging/.openapi-generator/FILES +2 -0
- data/lib/reach-ruby/rest/api/messaging/.openapi-generator/VERSION +1 -0
- data/lib/reach-ruby/rest/api/messaging/.openapi-generator-ignore +23 -0
- data/lib/reach-ruby/rest/api/messaging/messaging_item.rb +582 -0
- data/lib/reach-ruby/rest/api/messaging.rb +51 -0
- data/lib/reach-ruby/rest/api.rb +50 -0
- data/lib/reach-ruby/rest/client.rb +130 -0
- data/lib/reach-ruby/rest.rb +13 -0
- data/lib/reach-ruby/security/request_validator.rb +149 -0
- data/lib/reach-ruby/util/configuration.rb +25 -0
- data/lib/reach-ruby/version.rb +3 -0
- data/lib/reach-ruby.rb +44 -0
- data/reach-ruby.gemspec +38 -0
- data/sonar-project.properties +13 -0
- metadata +267 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
module REST
|
5
|
+
class Domain
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
@host = nil
|
11
|
+
@base_url = nil
|
12
|
+
@port = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def absolute_url(uri)
|
16
|
+
"#{@base_url.chomp('/')}/#{uri.chomp('/').gsub(/^\//, '')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
20
|
+
url = uri.match(/^http/) ? uri : absolute_url(uri)
|
21
|
+
|
22
|
+
baseUrl = URI(@base_url)
|
23
|
+
baseHost = "#{baseUrl.scheme}//#{baseUrl.host}"
|
24
|
+
|
25
|
+
@client.request(
|
26
|
+
baseHost,
|
27
|
+
@port,
|
28
|
+
method,
|
29
|
+
url,
|
30
|
+
params,
|
31
|
+
data,
|
32
|
+
headers,
|
33
|
+
auth,
|
34
|
+
timeout
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
module REST
|
5
|
+
class ReachError < StandardError
|
6
|
+
# @deprecated all errors that have a body are now 'Reach::RestError's
|
7
|
+
def body
|
8
|
+
warn "'Reach::REST::ReachError#body' has been deprecated. No 'ReachError' objects are raised with a body."
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RestError < ReachError
|
14
|
+
attr_reader :message, :response, :code, :status_code, :details, :more_info, :error_message
|
15
|
+
|
16
|
+
def initialize(message, response)
|
17
|
+
@status_code = response.status_code
|
18
|
+
@code = response.body.fetch('errorCode', @status_code)
|
19
|
+
@details = response.body.fetch('errorDetails', nil)
|
20
|
+
@error_message = response.body.fetch('errorMessage', nil)
|
21
|
+
@more_info = response.body.fetch('more_info', nil)
|
22
|
+
@message = format_message(message)
|
23
|
+
@response = response
|
24
|
+
end
|
25
|
+
|
26
|
+
# @deprecated use #response instead
|
27
|
+
def body
|
28
|
+
warn 'This error used to be a "Reach::REST::ReachError" but is now a "Reach::REST::RestError". ' \
|
29
|
+
'Please use #response instead of #body.'
|
30
|
+
@response
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
message
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def format_message(initial_message)
|
40
|
+
message = "[HTTP #{status_code}] #{code} : #{initial_message}"
|
41
|
+
message += "\n#{error_message}" if error_message
|
42
|
+
message += "\n#{details}" if details
|
43
|
+
message += "\n#{more_info}" if more_info
|
44
|
+
message + "\n\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ObsoleteError < StandardError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
module REST
|
5
|
+
# Page Base Class
|
6
|
+
class Page
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
META_KEYS = [
|
10
|
+
'page',
|
11
|
+
'pageSize',
|
12
|
+
'totalPages',
|
13
|
+
'outOfPageRange'
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def initialize(url, version, response)
|
17
|
+
payload = process_response(response)
|
18
|
+
|
19
|
+
@url = url
|
20
|
+
@version = version
|
21
|
+
@payload = payload
|
22
|
+
@solution = {}
|
23
|
+
@records = load_page(payload)
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_response(response)
|
27
|
+
if response.status_code != 200
|
28
|
+
raise Reach::REST::RestError.new('Unable to fetch page', response)
|
29
|
+
end
|
30
|
+
|
31
|
+
response.body
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_page(payload)
|
35
|
+
if payload['meta'] && payload['meta']['key']
|
36
|
+
return payload[payload['meta']['key']]
|
37
|
+
else
|
38
|
+
keys = payload.keys
|
39
|
+
key = keys - META_KEYS
|
40
|
+
if key.size == 1
|
41
|
+
return payload[key.first]
|
42
|
+
end
|
43
|
+
if key.size == 2
|
44
|
+
key1 = key[0]
|
45
|
+
key2 = key[1]
|
46
|
+
if key1.length > key2.length
|
47
|
+
aux = key2
|
48
|
+
key2 = key1
|
49
|
+
key1 = aux
|
50
|
+
end
|
51
|
+
val = "total" + key1[0,1].upcase + key1[1..-1]
|
52
|
+
if val == key2
|
53
|
+
return payload[key1]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
raise Reach::REST::ReachError, 'Page Records can not be deserialized'
|
59
|
+
end
|
60
|
+
|
61
|
+
def previous_page_url
|
62
|
+
page = 0
|
63
|
+
if @payload.key?('page')
|
64
|
+
page = @payload['page']
|
65
|
+
end
|
66
|
+
pageSize = 1
|
67
|
+
if @payload.key?('pageSize')
|
68
|
+
pageSize = @payload['pageSize']
|
69
|
+
end
|
70
|
+
if page > 0
|
71
|
+
query = "pageSize=#{pageSize}&page=#{page-1}"
|
72
|
+
uri = URI.parse(@url)
|
73
|
+
if (!(uri.query == nil || uri.query.length == 0))
|
74
|
+
query = uri.query + "&" + query
|
75
|
+
end
|
76
|
+
uri.query = query
|
77
|
+
return uri.to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def next_page_url
|
84
|
+
page = 0
|
85
|
+
if @payload.key?('page')
|
86
|
+
page = @payload['page']
|
87
|
+
end
|
88
|
+
pageSize = 1
|
89
|
+
if @payload.key?('pageSize')
|
90
|
+
pageSize = @payload['pageSize']
|
91
|
+
end
|
92
|
+
outOfPageRange = true
|
93
|
+
if @payload.key?('outOfPageRange')
|
94
|
+
outOfPageRange = @payload['outOfPageRange']
|
95
|
+
end
|
96
|
+
totalPages = 1
|
97
|
+
if @payload.key?('totalPages')
|
98
|
+
totalPages = @payload['totalPages']
|
99
|
+
end
|
100
|
+
if !(outOfPageRange || (page + 1 >= totalPages))
|
101
|
+
query = "pageSize=#{pageSize}&page=#{page+1}"
|
102
|
+
uri = URI.parse(@url)
|
103
|
+
if (!(uri.query == nil || uri.query.length == 0))
|
104
|
+
query = uri.query + "&" + query
|
105
|
+
end
|
106
|
+
uri.query = query
|
107
|
+
return uri.to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_instance(payload)
|
114
|
+
raise Reach::REST::ReachError, 'Page.get_instance() must be implemented in the derived class'
|
115
|
+
end
|
116
|
+
|
117
|
+
def previous_page
|
118
|
+
return nil unless previous_page_url
|
119
|
+
|
120
|
+
response = @version.domain.request('GET', previous_page_url)
|
121
|
+
|
122
|
+
self.class.new(@url, @version, response, @solution)
|
123
|
+
end
|
124
|
+
|
125
|
+
def next_page
|
126
|
+
return nil unless next_page_url
|
127
|
+
|
128
|
+
response = @version.domain.request('GET', next_page_url)
|
129
|
+
|
130
|
+
self.class.new(@url, @version, response, @solution)
|
131
|
+
end
|
132
|
+
|
133
|
+
def each
|
134
|
+
@records.each do |record|
|
135
|
+
yield get_instance(record)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def to_s
|
140
|
+
'#<Page>'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
module REST
|
5
|
+
class ListResource
|
6
|
+
def initialize(version)
|
7
|
+
@version = version
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class InstanceContext
|
12
|
+
def initialize(version)
|
13
|
+
@version = version
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class InstanceResource
|
18
|
+
def initialize(version)
|
19
|
+
@version = version
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
module REST
|
5
|
+
class Version
|
6
|
+
attr_accessor :domain
|
7
|
+
|
8
|
+
class RecordStream
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize(page, limit: nil, page_limit: nil)
|
12
|
+
@page = page
|
13
|
+
@limit = limit
|
14
|
+
@page_limit = page_limit
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
current_record = 0
|
19
|
+
current_page = 1
|
20
|
+
|
21
|
+
while @page
|
22
|
+
@page.each do |record|
|
23
|
+
yield record
|
24
|
+
current_record += 1
|
25
|
+
return nil if @limit && @limit <= current_record
|
26
|
+
end
|
27
|
+
|
28
|
+
return nil if @page_limit && @page_limit <= current_page
|
29
|
+
|
30
|
+
@page = @page.next_page
|
31
|
+
current_page += 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(domain)
|
37
|
+
@domain = domain
|
38
|
+
@version = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def absolute_url(uri)
|
42
|
+
@domain.absolute_url(relative_uri(uri))
|
43
|
+
end
|
44
|
+
|
45
|
+
def url_without_pagination_info(url, params = {})
|
46
|
+
uri = URI.parse(url)
|
47
|
+
clo = params.clone
|
48
|
+
clo = clo.delete_if { |_k, v| v.nil? }
|
49
|
+
query = clo.map{|k, v| "#{k}=#{v}"}.join("&")
|
50
|
+
if (!(uri.query == nil || uri.query.length == 0))
|
51
|
+
sep = ""
|
52
|
+
if (query.length>0)
|
53
|
+
sep = "&"
|
54
|
+
end
|
55
|
+
query = uri.query + sep + query;
|
56
|
+
end
|
57
|
+
if (query.length ==0)
|
58
|
+
return url
|
59
|
+
end
|
60
|
+
queryParams = query.split("&")
|
61
|
+
idx = 0;
|
62
|
+
q = ["page", "pageSize"];
|
63
|
+
while (idx < q.length)
|
64
|
+
par = q[idx]
|
65
|
+
prefix = par + "="
|
66
|
+
i = 0
|
67
|
+
while (i < queryParams.length)
|
68
|
+
if (queryParams[i].start_with?(prefix))
|
69
|
+
queryParams.delete_at(i)
|
70
|
+
else
|
71
|
+
i = i + 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
idx = idx + 1
|
75
|
+
end
|
76
|
+
query = ""
|
77
|
+
if (queryParams.length > 0)
|
78
|
+
query = queryParams.join("&")
|
79
|
+
end
|
80
|
+
uri.query = query
|
81
|
+
return uri.to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
def relative_uri(uri)
|
85
|
+
"#{@version.chomp('/').gsub(/^\//, '')}/#{uri.chomp('/').gsub(/^\//, '')}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
89
|
+
url = relative_uri(uri)
|
90
|
+
params = params.delete_if { |_k, v| v.nil? }
|
91
|
+
data = data
|
92
|
+
@domain.request(method, url, params, data, headers, auth, timeout)
|
93
|
+
end
|
94
|
+
|
95
|
+
def exception(response, header)
|
96
|
+
Reach::REST::RestError.new(header, response)
|
97
|
+
end
|
98
|
+
|
99
|
+
def fetch(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
100
|
+
response = request(
|
101
|
+
method,
|
102
|
+
uri,
|
103
|
+
params,
|
104
|
+
data,
|
105
|
+
headers,
|
106
|
+
auth,
|
107
|
+
timeout
|
108
|
+
)
|
109
|
+
|
110
|
+
# Note that 3XX response codes are allowed for fetches.
|
111
|
+
if response.status_code < 200 || response.status_code >= 400
|
112
|
+
raise exception(response, 'Unable to fetch record')
|
113
|
+
end
|
114
|
+
|
115
|
+
response.body
|
116
|
+
end
|
117
|
+
|
118
|
+
def update(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
119
|
+
response = request(
|
120
|
+
method,
|
121
|
+
uri,
|
122
|
+
params,
|
123
|
+
data,
|
124
|
+
headers,
|
125
|
+
auth,
|
126
|
+
timeout
|
127
|
+
)
|
128
|
+
|
129
|
+
if response.status_code < 200 || response.status_code >= 300
|
130
|
+
raise exception(response, 'Unable to update record')
|
131
|
+
end
|
132
|
+
|
133
|
+
response.body
|
134
|
+
end
|
135
|
+
|
136
|
+
def unschedule(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
137
|
+
response = request(
|
138
|
+
method,
|
139
|
+
uri,
|
140
|
+
params,
|
141
|
+
data,
|
142
|
+
headers,
|
143
|
+
auth,
|
144
|
+
timeout
|
145
|
+
)
|
146
|
+
|
147
|
+
if response.status_code < 200 || response.status_code >= 300
|
148
|
+
raise exception(response, 'Unable to unschedule record')
|
149
|
+
end
|
150
|
+
|
151
|
+
response.body
|
152
|
+
end
|
153
|
+
|
154
|
+
def delete(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
155
|
+
response = request(
|
156
|
+
method,
|
157
|
+
uri,
|
158
|
+
params,
|
159
|
+
data,
|
160
|
+
headers,
|
161
|
+
auth,
|
162
|
+
timeout
|
163
|
+
)
|
164
|
+
|
165
|
+
if response.status_code < 200 || response.status_code >= 300
|
166
|
+
raise exception(response, 'Unable to delete record')
|
167
|
+
end
|
168
|
+
|
169
|
+
response.status_code == 204
|
170
|
+
end
|
171
|
+
|
172
|
+
def read_limits(limit = nil, page_size = nil)
|
173
|
+
unless limit.nil? || page_size
|
174
|
+
page_size = limit
|
175
|
+
end
|
176
|
+
|
177
|
+
{
|
178
|
+
limit: limit || nil,
|
179
|
+
page_size: page_size || nil
|
180
|
+
}
|
181
|
+
end
|
182
|
+
|
183
|
+
def page(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
184
|
+
request(
|
185
|
+
method,
|
186
|
+
uri,
|
187
|
+
params,
|
188
|
+
data,
|
189
|
+
headers,
|
190
|
+
auth,
|
191
|
+
timeout
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
def stream(page, limit: nil, page_limit: nil)
|
196
|
+
RecordStream.new(page, limit: limit, page_limit: page_limit)
|
197
|
+
end
|
198
|
+
|
199
|
+
def create(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
200
|
+
response = request(method, uri, params, data, headers, auth, timeout)
|
201
|
+
|
202
|
+
if response.status_code < 200 || response.status_code >= 300
|
203
|
+
raise exception(response, 'Unable to create record')
|
204
|
+
end
|
205
|
+
|
206
|
+
response.body
|
207
|
+
end
|
208
|
+
|
209
|
+
def dispatch(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
210
|
+
response = request(method, uri, params, data, headers, auth, timeout)
|
211
|
+
|
212
|
+
if response.status_code < 200 || response.status_code >= 300
|
213
|
+
raise exception(response, 'Unable to dispatch record')
|
214
|
+
end
|
215
|
+
|
216
|
+
response.body
|
217
|
+
end
|
218
|
+
|
219
|
+
def start(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
220
|
+
response = request(method, uri, params, data, headers, auth, timeout)
|
221
|
+
|
222
|
+
if response.status_code < 200 || response.status_code >= 300
|
223
|
+
raise exception(response, 'Unable to start record')
|
224
|
+
end
|
225
|
+
|
226
|
+
response.body
|
227
|
+
end
|
228
|
+
|
229
|
+
def check(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: nil)
|
230
|
+
response = request(method, uri, params, data, headers, auth, timeout)
|
231
|
+
|
232
|
+
if response.status_code < 200 || response.status_code >= 300
|
233
|
+
raise exception(response, 'Unable to check record')
|
234
|
+
end
|
235
|
+
|
236
|
+
response.body
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Reach
|
4
|
+
def self.serialize_iso8601_date(date)
|
5
|
+
if date.eql?(:unset)
|
6
|
+
date
|
7
|
+
elsif date.is_a?(Date)
|
8
|
+
date.iso8601
|
9
|
+
elsif date.is_a?(Time)
|
10
|
+
date.strftime('%Y-%m-%d')
|
11
|
+
elsif date.is_a?(String)
|
12
|
+
date
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.serialize_iso8601_datetime(date)
|
17
|
+
if date.eql?(:unset)
|
18
|
+
date
|
19
|
+
elsif date.is_a?(Date)
|
20
|
+
Time.new(date.year, date.month, date.day).utc.iso8601
|
21
|
+
elsif date.is_a?(Time)
|
22
|
+
date.utc.iso8601
|
23
|
+
elsif date.is_a?(String)
|
24
|
+
date
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.deserialize_rfc2822(date)
|
29
|
+
Time.rfc2822(date) unless date.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.deserialize_iso8601_date(date)
|
33
|
+
Date.parse(date) unless date.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.deserialize_iso8601_datetime(date)
|
37
|
+
Time.parse(date) unless date.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.serialize_object(object)
|
41
|
+
if object.is_a?(Hash) || object.is_a?(Array)
|
42
|
+
JSON.generate(object)
|
43
|
+
else
|
44
|
+
object
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.flatten(map, result = {}, previous = [])
|
49
|
+
map.each do |key, value|
|
50
|
+
if value.is_a? Hash
|
51
|
+
self.flatten(value, result, previous + [key])
|
52
|
+
else
|
53
|
+
result[(previous + [key]).join('.')] = value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.prefixed_collapsible_map(map, prefix)
|
61
|
+
result = {}
|
62
|
+
if map.is_a? Hash
|
63
|
+
flattened = self.flatten(map)
|
64
|
+
result = {}
|
65
|
+
flattened.each do |key, value|
|
66
|
+
result[prefix + '.' + key] = value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.serialize_list(input_list)
|
74
|
+
return input_list unless input_list.is_a? Array
|
75
|
+
result = []
|
76
|
+
input_list.each do |e|
|
77
|
+
result.push yield e
|
78
|
+
end
|
79
|
+
result
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module Reach
|
6
|
+
module HTTP
|
7
|
+
class Client
|
8
|
+
attr_accessor :adapter
|
9
|
+
attr_reader :timeout, :last_response, :last_request
|
10
|
+
|
11
|
+
def initialize(proxy_prot = nil, proxy_addr = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil,
|
12
|
+
ssl_ca_file = nil, timeout: nil)
|
13
|
+
@proxy_prot = proxy_prot
|
14
|
+
@proxy_path = "#{proxy_addr}:#{proxy_port}" if proxy_addr && proxy_port
|
15
|
+
@proxy_auth = "#{proxy_user}:#{proxy_pass}@" if proxy_pass && proxy_user
|
16
|
+
@ssl_ca_file = ssl_ca_file
|
17
|
+
@timeout = timeout
|
18
|
+
@adapter = Faraday.default_adapter
|
19
|
+
@configure_connection_blocks = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure_connection(&block)
|
23
|
+
raise ArgumentError, "#{__method__} must be given a block!" unless block_given?
|
24
|
+
|
25
|
+
@configure_connection_blocks << block
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def _request(request) # rubocop:disable Metrics/MethodLength
|
30
|
+
sslVerify = true
|
31
|
+
@connection = Faraday.new(url: request.host + ':' + request.port.to_s, ssl: { verify: sslVerify }) do |f|
|
32
|
+
f.options.params_encoder = Faraday::FlatParamsEncoder
|
33
|
+
f.request :url_encoded
|
34
|
+
f.headers = request.headers
|
35
|
+
#if Faraday::VERSION.start_with?('2.')
|
36
|
+
# f.request(:authorization, :basic, request.auth[0], request.auth[1])
|
37
|
+
#else
|
38
|
+
# f.request(:basic_auth, request.auth[0], request.auth[1])
|
39
|
+
#end
|
40
|
+
f.headers["ApiUser"] = request.auth[0]
|
41
|
+
f.headers["ApiKey"] = request.auth[1]
|
42
|
+
f.proxy = "#{@proxy_prot}://#{@proxy_auth}#{@proxy_path}" if @proxy_prot && @proxy_path
|
43
|
+
f.options.open_timeout = request.timeout || @timeout
|
44
|
+
f.options.timeout = request.timeout || @timeout
|
45
|
+
|
46
|
+
@configure_connection_blocks.each { |block| block.call(f) }
|
47
|
+
f.adapter @adapter
|
48
|
+
end
|
49
|
+
|
50
|
+
@last_request = request
|
51
|
+
@last_response = nil
|
52
|
+
|
53
|
+
response = send(request)
|
54
|
+
if (500..599).include?(response.status)
|
55
|
+
object = { message: "Server error (#{response.status})", code: response.status }.to_json
|
56
|
+
elsif response.body && !response.body.empty?
|
57
|
+
object = response.body
|
58
|
+
elsif response.status == 400
|
59
|
+
object = { message: 'Bad request', code: 400 }.to_json
|
60
|
+
end
|
61
|
+
|
62
|
+
reach_response = Reach::Response.new(response.status, object, headers: response.headers)
|
63
|
+
@last_response = reach_response
|
64
|
+
|
65
|
+
reach_response
|
66
|
+
end
|
67
|
+
|
68
|
+
def send(request)
|
69
|
+
@connection.send(request.method.downcase.to_sym,
|
70
|
+
request.url,
|
71
|
+
request.method == 'GET' ? request.params : request.data)
|
72
|
+
rescue Faraday::Error => e
|
73
|
+
raise Reach::REST::ReachError, e
|
74
|
+
end
|
75
|
+
|
76
|
+
def request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
77
|
+
request = Reach::Request.new(host, port, method, url, params, data, headers, auth, timeout)
|
78
|
+
_request(request)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
../authentix.rb
|
2
|
+
../authentix.rb
|
3
|
+
../authentix.rb
|
4
|
+
../authentix.rb
|
5
|
+
../authentix.rb
|
6
|
+
authentication_trial_item.rb
|
7
|
+
authentication_trial_stat_item.rb
|
8
|
+
configuration_item.rb
|
9
|
+
configuration_item/authentication_control_item.rb
|
10
|
+
configuration_item/authentication_item.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
unset
|