test_joska 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/test_joska/builder.rb +252 -13
- data/lib/test_joska/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c0ae254c9579695a4fe20db533cfead4b630978185d7456c124d62c428a1c88
|
4
|
+
data.tar.gz: e0fed471d9627747f9335bc3bf8f8d9c7b902ee4bb73a32dcad34ffaa68ec2d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f079fadeb9710551aa447c35b25f8da02a6b63a8f896e294827096a31b72df6aba379d4162276b2d921889d8e581d6e8eab6e46463ee03582375f425dbc897b
|
7
|
+
data.tar.gz: 6bb09ab099d06d25429d721d80f0fddcb59b550a639d5485ac609ea3ed99fbf71bfbb544e42c92d18ecdb5c3b00daba0a26513c83fd069f9df74c6b27e4ebb90
|
data/Gemfile.lock
CHANGED
data/lib/test_joska/builder.rb
CHANGED
@@ -1,37 +1,276 @@
|
|
1
1
|
module TestJoska
|
2
2
|
|
3
|
-
|
3
|
+
@@standard_endpoint = ""
|
4
4
|
|
5
|
-
|
5
|
+
@@standard_environment = ""
|
6
|
+
|
7
|
+
@@HEAD = {}
|
8
|
+
|
9
|
+
@@URL = {}
|
10
|
+
|
11
|
+
@@internal_log = ""
|
12
|
+
|
13
|
+
@@url_log = ""
|
14
|
+
|
15
|
+
@@raise_on_error = false
|
16
|
+
|
17
|
+
@@silent = false
|
18
|
+
|
19
|
+
def jsk_setup(options)
|
20
|
+
|
21
|
+
@@raise_on_error = options["raise_on_error"]
|
22
|
+
|
23
|
+
@@output_url = options["output_url"]
|
24
|
+
|
25
|
+
@@URL = options["url_parts"]
|
26
|
+
|
27
|
+
@@HEAD = options["headers"]
|
28
|
+
|
29
|
+
@@standard_endpoint = options["standard_endpoint"]
|
30
|
+
|
31
|
+
@@standard_environment = options["standard_environment"]
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def jsk_get_log
|
36
|
+
|
37
|
+
return @@internal_log
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def jsk_log(message)
|
42
|
+
|
43
|
+
p @@internal_log = "#{@@internal_log}#{message}\n"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def jsk_clear_log
|
48
|
+
|
49
|
+
@@internal_log = ""
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def jsk_get_url_log
|
54
|
+
|
55
|
+
return @@url_log
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def jsk_clear_url_log
|
60
|
+
|
61
|
+
@@url_log = ""
|
6
62
|
|
7
63
|
end
|
8
64
|
|
9
|
-
|
65
|
+
def request(method, product, type, details=nil, payload=nil, header_type=nil, endpoint=nil, env=nil)
|
66
|
+
|
67
|
+
endpoint = endpoint ? endpoint : @@standard_endpoint
|
10
68
|
|
11
|
-
|
69
|
+
url = urlBuilder(product, type, details, endpoint, env)
|
12
70
|
|
13
|
-
|
71
|
+
header_type ? header = @@HEAD[header_type] : header = @@HEAD[endpoint]
|
14
72
|
|
15
|
-
|
73
|
+
payload = payload.to_json if payload
|
74
|
+
|
75
|
+
res = ""
|
76
|
+
|
77
|
+
p url
|
78
|
+
|
79
|
+
@@url_log = "#{@@url_log}\n#{method} #{type}: #{url}"
|
80
|
+
|
81
|
+
@@url_log = "#{@@url_log}\nPayload: #{payload}" if payload && type != "login"
|
82
|
+
|
83
|
+
RestClient::Request.execute(method: method, url: url, headers: header, payload: payload, timeout: 90) do |response|
|
84
|
+
|
85
|
+
if response.code != 200
|
86
|
+
|
87
|
+
begin
|
88
|
+
|
89
|
+
response = JSON.parse(response)
|
90
|
+
|
91
|
+
rescue
|
92
|
+
|
93
|
+
p "Não possível converter para json"
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
raise "Erro no serviço #{type}, codigo: #{response.code} \nURL: #{url} \nResposta: #{response}"
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
res = response
|
16
102
|
|
17
103
|
end
|
18
|
-
|
19
104
|
|
20
|
-
|
105
|
+
begin
|
106
|
+
|
107
|
+
return JSON.parse(res)
|
108
|
+
|
109
|
+
rescue
|
21
110
|
|
22
|
-
|
111
|
+
raise "Problema em converter a resposta #{response}" if res != ""
|
23
112
|
|
24
113
|
end
|
25
114
|
|
26
|
-
|
27
|
-
|
28
|
-
|
115
|
+
end
|
116
|
+
|
117
|
+
def urlBuilder(product, type, details, endpoint, env=nil)
|
118
|
+
|
119
|
+
env = env ? env : @@standard_environment
|
120
|
+
|
121
|
+
details = "" if !details
|
122
|
+
|
123
|
+
details = [details] if !details.kind_of?(Array)
|
124
|
+
|
125
|
+
url = @@URL[product]["base"]["#{env}_#{endpoint}"]
|
126
|
+
|
127
|
+
if !@@URL[product]["path"][type].kind_of?(Array)
|
128
|
+
|
129
|
+
return "#{url}#{@@URL[product]["path"][type]}#{details[0]}"
|
130
|
+
|
131
|
+
else
|
132
|
+
|
133
|
+
query_pos = 0
|
134
|
+
|
135
|
+
@@URL[product]["path"][type].each do |query|
|
136
|
+
|
137
|
+
if details[query_pos] && details[query_pos] != ""
|
138
|
+
|
139
|
+
query = query[0] if query.kind_of?(Array)
|
140
|
+
|
141
|
+
url = "#{url}#{query}#{details[query_pos]}"
|
142
|
+
|
143
|
+
else
|
29
144
|
|
30
|
-
|
145
|
+
query.kind_of?(Array) ? url = "#{url}#{query[0]}#{query[1]}" : url = "#{url}#{query}"
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
query_pos += 1
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
return url
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
def rateTokenBuilder(rateToken)
|
160
|
+
|
161
|
+
token_decoded = Base64.decode64(rateToken).gsub(" ", "").gsub("/>", "").gsub("<rateToken", "").gsub("=", "").split('"')
|
162
|
+
|
163
|
+
built_token = {}
|
164
|
+
|
165
|
+
cur_part = 0
|
166
|
+
|
167
|
+
while cur_part < token_decoded.count do
|
168
|
+
|
169
|
+
built_token[token_decoded[cur_part]] = token_decoded[cur_part + 1]
|
170
|
+
|
171
|
+
cur_part += 2
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
built_token
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
def comparePrice(price1, price2, type1, type2)
|
180
|
+
|
181
|
+
range = price1.abs * 0.001 > 0.10 ? price1.abs * 0.001 : 0.10
|
182
|
+
|
183
|
+
if !(price1.abs-range...price1.abs+range).include?(price2.abs)
|
184
|
+
|
185
|
+
error_name = "#{type1} - #{type2}"
|
186
|
+
|
187
|
+
error_message = "#{type1}: R$#{price1} / #{type2}: R$#{price2}",
|
188
|
+
|
189
|
+
tempErrorhandler("price", error_name, error_message)
|
190
|
+
|
191
|
+
raise "Diferença de preço encontrada (#{type1} - #{type2})\n#{error_message}" if @@raise_on_error
|
192
|
+
|
193
|
+
jsk_log("Diferença de preço encontrada (#{type1} - #{type2})\n#{error_message}")
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
def compareValues(value1, value2, message, type1, type2)
|
201
|
+
|
202
|
+
if value1 != value2
|
203
|
+
|
204
|
+
value1 = "null" if value1 == nil
|
205
|
+
|
206
|
+
value2 = "null" if value2 == nil
|
207
|
+
|
208
|
+
error_name = "#{message} (#{type1} - #{type2})"
|
209
|
+
|
210
|
+
error_message = "#{type1}: #{value1} / #{type2}: #{value2}"
|
211
|
+
|
212
|
+
tempErrorhandler("value", error_name, error_message)
|
213
|
+
|
214
|
+
raise "Conflito: #{message} (#{type1} - #{type2})\n(#{error_message})") if @@raise_on_error
|
215
|
+
|
216
|
+
jsk_log("Conflito: #{message} (#{type1} - #{type2})\n(#{error_message})")
|
31
217
|
|
32
218
|
end
|
33
219
|
|
220
|
+
end
|
221
|
+
|
222
|
+
def checkFloat value
|
223
|
+
|
224
|
+
true if Float value rescue false
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
def genericComparator object1, object2, context, type1 = "Barramento", type2 = "Micro serviço"
|
34
229
|
|
230
|
+
if object1.is_a?(Hash) && object2.is_a?(Hash)
|
231
|
+
|
232
|
+
compareValues(object1.keys.count, object2.keys.count, "#{context}_keyCount", type1, type2)
|
233
|
+
|
234
|
+
(object1.keys | object2.keys).each do |key|
|
235
|
+
|
236
|
+
genericComparator(object1[key], object2[key], "#{context}_#{key}", type1, type2)
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
elsif object1.is_a?(Array) && object2.is_a?(Array)
|
241
|
+
|
242
|
+
if object1.count != object2.count
|
243
|
+
|
244
|
+
genericComparator(object1[0], object2[0], "#{context}_arrayElement", type1, type2) if object1[0] && object2[0]
|
245
|
+
|
246
|
+
return compareValues(object1.count, object2.count, "#{context}_arrayCount", type1, type2)
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
array_count = 0
|
251
|
+
|
252
|
+
while array_count < object1.count do
|
253
|
+
|
254
|
+
genericComparator(object1[array_count], object2[array_count], "#{context}_arrayElement", type1, type2)
|
255
|
+
|
256
|
+
array_count += 1
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
elsif (checkFloat(object1) && checkFloat(object2)) && (object1.to_s.include?(".") || object2.to_s.include?("."))
|
261
|
+
|
262
|
+
comparePrice(object1.to_f, object2.to_f, "#{type1}_#{context}", "#{type2}_#{context}")
|
263
|
+
|
264
|
+
elsif context.split("_").last.include?("Token")
|
265
|
+
|
266
|
+
genericComparator(rateTokenBuilder(object1), rateTokenBuilder(object2), "#{context}_decoded", type1, type2)
|
267
|
+
|
268
|
+
else
|
269
|
+
|
270
|
+
compareValues(object1, object2, context, type1, type2)
|
271
|
+
|
272
|
+
end
|
273
|
+
|
35
274
|
end
|
36
275
|
|
37
276
|
end
|
data/lib/test_joska/version.rb
CHANGED