Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def initialize(host, port, user, pass)
- @host = host
- @port = port
- @user = user
- @pass = pass
- @httpo = Net::HTTP.new(@host, @port)
- @httpo.use_ssl = true
- end
- def do_request(url)
- @httpo.start {|http|
- req = Net::HTTP::Get.new(url)
- req.basic_auth @user, @pass
- response = http.request(req)
- if response.code == "200" and response.message == "OK" then
- data = XmlSimple.xml_in(response.body)
- return (yield data)
- else
- return false
- end # if reponse code is 200
- }
- end
- def get_host_name
- do_request('/xml-api/gethostname') do |data|
- data['hostname'].to_s
- end
- end
Add Comment
Please, Sign In to add comment