wolf_core 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wolf_core/infrastructure/http_operations.rb +45 -26
- data/lib/wolf_core/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: 34de3ce44a6c43a34f730c9a1e1eebf091f63ce6a94c0acbccfc6f1e15e151ab
|
4
|
+
data.tar.gz: 3e16fb618f71f3c36f17dc312933dfad77ce0f32a0d3eb87bf775d2d16591c57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f3529936b64862714e4163e793a81e260193efd35dcc845569e80ea606904da74040bc17b0c69c75ff08f16d3c7361b9c6f05bc13d63cf71492ec8c8186f34
|
7
|
+
data.tar.gz: 635cd4831a4582f5bb134a917125fb95170b2b21f569e73c3d268ab37116839ce68917a4b2321cb3845cf0f8bd1fd180495f6ec03ad7395eb3a381f4f7aaa9be
|
@@ -4,12 +4,17 @@ module WolfCore
|
|
4
4
|
include WolfCore::AsyncUtils
|
5
5
|
include WolfCore::LoggingUtils
|
6
6
|
|
7
|
+
def parsed_http_get(url:, headers: {}, query: nil)
|
8
|
+
response = http_get(url: url, headers: headers, query: query)
|
9
|
+
parse_http_response(response)
|
10
|
+
end
|
11
|
+
|
7
12
|
def async_http_get(**args)
|
8
|
-
log_object
|
9
|
-
log_object args, title:
|
13
|
+
log_object "starting async_http_get"
|
14
|
+
log_object args, title: "async_http_get args are"
|
10
15
|
run_async do
|
11
16
|
response = http_get(**args)
|
12
|
-
log_object parse_http_response(response), title:
|
17
|
+
log_object parse_http_response(response), title: "async_http_get response is"
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
@@ -19,7 +24,7 @@ module WolfCore
|
|
19
24
|
|
20
25
|
log_object response, title: title if title.present?
|
21
26
|
|
22
|
-
error_message ||=
|
27
|
+
error_message ||= "Error on safe_http_get"
|
23
28
|
validate_http_response(response: response, message: error_message)
|
24
29
|
|
25
30
|
response
|
@@ -29,12 +34,17 @@ module WolfCore
|
|
29
34
|
WolfCore::HttpDataSource.http_get(url: url, headers: headers, query: query)
|
30
35
|
end
|
31
36
|
|
37
|
+
def parsed_http_post(url:, headers: {}, query: nil)
|
38
|
+
response = http_post(url: url, headers: headers, query: query)
|
39
|
+
parse_http_response(response)
|
40
|
+
end
|
41
|
+
|
32
42
|
def async_http_post(**args)
|
33
43
|
log_object "starting async_http_post"
|
34
|
-
log_object args, title:
|
44
|
+
log_object args, title: "async_http_post args are"
|
35
45
|
run_async do
|
36
46
|
response = http_post(**args)
|
37
|
-
log_object parse_http_response(response), title:
|
47
|
+
log_object parse_http_response(response), title: "async_http_post response is"
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
@@ -42,10 +52,10 @@ module WolfCore
|
|
42
52
|
response = http_post(url: url, headers: headers, body: body, query: query)
|
43
53
|
response = parse_http_response(response)
|
44
54
|
|
45
|
-
title ||=
|
55
|
+
title ||= "safe_http_post response is"
|
46
56
|
log_object response, title: title
|
47
57
|
|
48
|
-
error_message ||=
|
58
|
+
error_message ||= "Error on safe_http_post"
|
49
59
|
validate_http_response(response: response, message: error_message)
|
50
60
|
|
51
61
|
response
|
@@ -55,12 +65,17 @@ module WolfCore
|
|
55
65
|
WolfCore::HttpDataSource.http_post(url: url, headers: headers, query: query, body: body)
|
56
66
|
end
|
57
67
|
|
68
|
+
def parsed_http_put(url:, headers: {}, query: nil)
|
69
|
+
response = http_put(url: url, headers: headers, query: query)
|
70
|
+
parse_http_response(response)
|
71
|
+
end
|
72
|
+
|
58
73
|
def async_http_put(**args)
|
59
|
-
log_object
|
60
|
-
log_object args, title:
|
74
|
+
log_object "starting async_http_put"
|
75
|
+
log_object args, title: "async_http_put args are"
|
61
76
|
run_async do
|
62
77
|
response = http_put(**args)
|
63
|
-
log_object parse_http_response(response), title:
|
78
|
+
log_object parse_http_response(response), title: "async_http_put response is"
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
@@ -68,10 +83,10 @@ module WolfCore
|
|
68
83
|
response = http_put(url: url, headers: headers, body: body, query: query)
|
69
84
|
response = parse_http_response(response)
|
70
85
|
|
71
|
-
title ||=
|
86
|
+
title ||= "safe_http_put response is"
|
72
87
|
log_object response, title: title
|
73
88
|
|
74
|
-
error_message ||=
|
89
|
+
error_message ||= "Error on safe_http_put"
|
75
90
|
validate_http_response(response: response, message: error_message)
|
76
91
|
|
77
92
|
response
|
@@ -82,22 +97,26 @@ module WolfCore
|
|
82
97
|
end
|
83
98
|
|
84
99
|
def validate_http_response(response:, message:, error_data: nil)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
100
|
+
return if response.code == 200
|
101
|
+
|
102
|
+
error_data = {
|
103
|
+
message: message,
|
104
|
+
response: parse_http_response(response)
|
105
|
+
}.merge(error_data || {})
|
106
|
+
raise_service_error(error_data)
|
92
107
|
end
|
93
108
|
|
94
109
|
def parse_http_response(response)
|
95
|
-
body =
|
110
|
+
body = begin
|
111
|
+
JSON.parse(response.body)
|
112
|
+
rescue StandardError
|
113
|
+
response.body
|
114
|
+
end
|
96
115
|
OpenStruct.new({
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
116
|
+
code: response.code,
|
117
|
+
body: body,
|
118
|
+
message: response.message
|
119
|
+
})
|
101
120
|
end
|
102
121
|
end
|
103
|
-
end
|
122
|
+
end
|
data/lib/wolf_core/version.rb
CHANGED