Guest User

Untitled

a guest
Mar 11th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def initialize(host, port, user, pass)
  2. @host = host
  3. @port = port
  4. @user = user
  5. @pass = pass
  6. @httpo = Net::HTTP.new(@host, @port)
  7. @httpo.use_ssl = true
  8. end
  9.  
  10. def do_request(url)
  11. @httpo.start {|http|
  12. req = Net::HTTP::Get.new(url)
  13. req.basic_auth @user, @pass
  14. response = http.request(req)
  15. if response.code == "200" and response.message == "OK" then
  16. data = XmlSimple.xml_in(response.body)
  17. return (yield data)
  18. else
  19. return false
  20. end # if reponse code is 200
  21. }
  22. end
  23.  
  24. def get_host_name
  25. do_request('/xml-api/gethostname') do |data|
  26. data['hostname'].to_s
  27. end
  28. end
Add Comment
Please, Sign In to add comment