summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-06-22 18:49:46 +0300
committerSaku Ytti <saku@ytti.fi>2018-06-22 18:49:46 +0300
commit483a9901280ea436db34f61ef220cc2f4d90b0da (patch)
treea859e02f3e6f7df363ec1668b6aec85f0451dc81
parentc0cb572d98708716dc3241e0d73f91143f887b65 (diff)
remove source/http load smells
-rw-r--r--lib/oxidized/source/http.rb46
1 files changed, 24 insertions, 22 deletions
diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb
index bf1e74c..36fa764 100644
--- a/lib/oxidized/source/http.rb
+++ b/lib/oxidized/source/http.rb
@@ -17,28 +17,7 @@ module Oxidized
def load node_want = nil
nodes = []
- uri = URI.parse(@cfg.url)
- http = Net::HTTP.new(uri.host, uri.port)
- http.use_ssl = true if uri.scheme == 'https'
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure
-
- # map headers
- headers = {}
- @cfg.headers.each do |header, value|
- headers[header] = value
- end
-
- req_uri = uri.request_uri
- if node_want
- req_uri = "#{req_uri}/#{node_want}"
- end
- request = Net::HTTP::Get.new(req_uri, headers)
- if (@cfg.user? && @cfg.pass?)
- request.basic_auth(@cfg.user, @cfg.pass)
- end
-
- response = http.request(request)
- data = JSON.parse(response.body)
+ data = JSON.parse(get_http)
data = string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location?
data.each do |node|
next if node.empty?
@@ -72,5 +51,28 @@ module Oxidized
end
object
end
+
+ def get_http
+ uri = URI.parse(@cfg.url)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true if uri.scheme == 'https'
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure
+
+ # map headers
+ headers = {}
+ @cfg.headers.each do |header, value|
+ headers[header] = value
+ end
+
+ req_uri = uri.request_uri
+ if node_want
+ req_uri = "#{req_uri}/#{node_want}"
+ end
+ request = Net::HTTP::Get.new(req_uri, headers)
+ if (@cfg.user? && @cfg.pass?)
+ request.basic_auth(@cfg.user, @cfg.pass)
+ end
+ http.request(request).body
+ end
end
end