socialHub_httpUtility 1.0.1 → 1.0.3
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/lib/socialHub_httpUtility/version.rb +1 -1
- data/lib/socialHub_httpUtility.rb +106 -15
- data/socialHub_httpUtility.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a503d113f7f69e5e4c667166d99eaa4fd8799e1
|
4
|
+
data.tar.gz: 35c8c82584776acb7a751fccc0b44f0722cc2f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43aa254f138cdc55bfac5ae0585f07b7bb88ba5cee5e850be53230c82eb378a2c523c514053885d07c2c9ca7bb954edb2e626b8b424531fe2a74faa43f467107
|
7
|
+
data.tar.gz: c76e59171c4bd0686cfe2148ec65fbbb18a9b274f417a8b36e382fe6397674bfc410f2abd9f9e28066b26000a3466989611d099fa89ca42ef6a22f29a0d21f15
|
@@ -11,18 +11,61 @@ module SocialHubHttpUtility
|
|
11
11
|
headers.each do |key,value|
|
12
12
|
request.add_field(key, value)
|
13
13
|
end
|
14
|
-
|
14
|
+
if(!headers.key?("request-id"))
|
15
|
+
request.add_field("request-id",SecureRandom.uuid)
|
16
|
+
end
|
15
17
|
log_params = {
|
16
18
|
"service_name" => params["service_name"],
|
17
19
|
"http_url" => url,
|
18
20
|
"http_request_params" => params,
|
19
21
|
"http_request_type" => "GET"
|
20
22
|
}
|
23
|
+
|
24
|
+
response = {}
|
25
|
+
metadata = {}
|
21
26
|
begin
|
22
|
-
|
23
|
-
|
27
|
+
res = http.request(request)
|
28
|
+
|
29
|
+
case res
|
30
|
+
when Net::HTTPSuccess then
|
31
|
+
metadata["statusCode"] = 1
|
32
|
+
metadata["reason"] = "SUCCESS"
|
33
|
+
response["metadata"] = metadata
|
34
|
+
response["http_response"] = res
|
35
|
+
|
36
|
+
when Net::HTTPMethodNotAllowed then
|
37
|
+
metadata["statusCode"] = 0
|
38
|
+
metadata["reason"] = "Method NOT ALLOWED FOR THIS URL >> Check The Method Type "
|
39
|
+
response["metadata"] = metadata
|
40
|
+
response["http_response"] = {}
|
41
|
+
|
42
|
+
when Net::HTTPNotFound then
|
43
|
+
metadata["statusCode"] = 0
|
44
|
+
metadata["reason"] = "THERE IS NO SUCH A METHOD >> Check That The Server Has This Method"
|
45
|
+
response["metadata"] = metadata
|
46
|
+
response["http_response"] = {}
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
log(log_params, distination_service, metadata)
|
51
|
+
rescue
|
52
|
+
end
|
53
|
+
|
54
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
55
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,Errno::ECONNREFUSED => e
|
56
|
+
metadata["statusCode"] = -1
|
57
|
+
metadata["reason"] = e.message
|
58
|
+
response["metadata"] = metadata
|
59
|
+
response["http_response"] = {}
|
60
|
+
begin
|
61
|
+
log(log_params, distination_service, metadata)
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
|
24
65
|
end
|
25
|
-
|
66
|
+
|
67
|
+
|
68
|
+
return response
|
26
69
|
end
|
27
70
|
|
28
71
|
def self.post_http_request(domain, path, params, headers, distination_service)
|
@@ -30,28 +73,76 @@ module SocialHubHttpUtility
|
|
30
73
|
uri = URI.parse(url)
|
31
74
|
http = Net::HTTP.new(uri.host, uri.port)
|
32
75
|
post_data = URI.encode_www_form(params)
|
33
|
-
|
76
|
+
if(!headers.key?("request-id"))
|
77
|
+
headers["request-id"] = SecureRandom.uuid
|
78
|
+
end
|
34
79
|
log_params = {
|
35
80
|
"service_name" => params["service_name"],
|
36
81
|
"http_url" => url,
|
37
82
|
"http_request_params" => params,
|
38
|
-
"http_request_type" => "
|
83
|
+
"http_request_type" => "POST"
|
39
84
|
}
|
85
|
+
response = {}
|
86
|
+
metadata = {}
|
40
87
|
begin
|
41
|
-
|
42
|
-
rescue
|
43
|
-
end
|
44
|
-
return JSON.parse res.body
|
45
|
-
end
|
88
|
+
res = http.post(uri.path, post_data, headers)
|
46
89
|
|
47
|
-
|
90
|
+
case res
|
91
|
+
when Net::HTTPSuccess then
|
92
|
+
metadata["statusCode"] = 1
|
93
|
+
metadata["reason"] = "SUCCESS"
|
94
|
+
response["metadata"] = metadata
|
95
|
+
response["http_response"] = res
|
48
96
|
|
97
|
+
when Net::HTTPMethodNotAllowed then
|
98
|
+
metadata["statusCode"] = 0
|
99
|
+
metadata["reason"] = "Method NOT ALLOWED FOR THIS URL >> Check The Method Type "
|
100
|
+
response["metadata"] = metadata
|
101
|
+
response["http_response"] = {}
|
102
|
+
|
103
|
+
when Net::HTTPNotFound then
|
104
|
+
metadata["statusCode"] = 0
|
105
|
+
metadata["reason"] = "THERE IS NO SUCH A METHOD >> Check That The Server Has This Method"
|
106
|
+
response["metadata"] = metadata
|
107
|
+
response["http_response"] = {}
|
108
|
+
end
|
109
|
+
|
110
|
+
begin
|
111
|
+
log(log_params, distination_service, metadata)
|
112
|
+
rescue
|
113
|
+
end
|
114
|
+
|
115
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
116
|
+
Net::HTTPBadResponse , Net::HTTPHeaderSyntaxError ,Net::ProtocolError,Errno::ECONNREFUSED => e
|
117
|
+
|
118
|
+
metadata["statusCode"] = -1
|
119
|
+
metadata["reason"] = e.message
|
120
|
+
response["metadata"] = metadata
|
121
|
+
response["http_response"] = {}
|
122
|
+
begin
|
123
|
+
log(log_params, distination_service, metadata)
|
124
|
+
rescue
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
return response
|
129
|
+
end
|
130
|
+
|
131
|
+
def log (log_params, distination_service, response_meta_data)
|
49
132
|
uri = URI.parse("http://localhost:8186/MonitoringService/storeLog")
|
50
133
|
time = Time.now
|
51
134
|
log_params["log_time"] = time.to_s
|
52
|
-
log_params["log_time_unix"] = time.to_i
|
53
|
-
|
54
|
-
|
135
|
+
log_params["log_time_unix"] = time.to_i
|
136
|
+
|
137
|
+
if response_meta_data["statusCode"] == 1
|
138
|
+
log_params["log_message"] = "Successed to get Http Response from " + distination_service
|
139
|
+
log_params["http_response"] = "SUCCESS"
|
140
|
+
elsif (response_meta_data["statusCode"] == -1 || response_meta_data["statusCode"] == 0 )
|
141
|
+
log_params["log_message"] = "Failed to get Http Response from " + distination_service
|
142
|
+
log_params["http_response"] = "FAILED"
|
143
|
+
log_params["http_response_reason"] = response_meta_data["reason"]
|
144
|
+
end
|
145
|
+
|
55
146
|
http = Net::HTTP.new(uri.host, uri.port)
|
56
147
|
post_data = URI.encode_www_form(log_params)
|
57
148
|
res = http.post(uri.path, post_data)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialHub_httpUtility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AbdAllah Elabasery
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: SecureRandom
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: httpUtility that provides us to make getHttp request and post http Requests
|
98
112
|
with headers
|
99
113
|
email:
|