class Object

Constants

CURRENT_SPEC_VERSION
HTTP_ERRORS
JSON_HEADERS

Public Instance Methods

exit_with_msg(err_msg) click to toggle source
# File lib/util.rb, line 130
def exit_with_msg(err_msg)
  STDERR.puts err_msg
  exit 1
end
http_delete(url_list, path, headers) click to toggle source
# File lib/util.rb, line 99
def http_delete(url_list, path, headers)
  lastErr = nil

  url_list.split(';').each do |url|
    uri = URI(url)

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Delete.new(path, headers)
    if uri.user
      request.basic_auth URI.unescape(uri.user), URI.unescape(uri.password)
    end
    begin
      # response = http.delete(path, headers)
      response = http.start {|http| http.request(request) }
    rescue *HTTP_ERRORS => error
      STDERR.puts "Failed http_delete to #{url}: #{error} (#{error.class})"
      lastErr = error
      next
    end

    return response    
  end

  http_fault(lastErr)
end
http_fault(error) click to toggle source
# File lib/util.rb, line 125
def http_fault(error)
  STDERR.puts "Fatal networking error talking to framework: #{error.to_s}"
  exit 1
end
http_get(url_list, path, headers) click to toggle source
# File lib/util.rb, line 73
def http_get(url_list, path, headers)
  lastErr = nil

  url_list.split(';').each do |url|
    uri = URI(url)

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(path, headers)
    if uri.user
      request.basic_auth URI.unescape(uri.user), URI.unescape(uri.password)
    end
    begin
      #response = http.get(path, headers)
      response = http.start {|http| http.request(request) }
    rescue *HTTP_ERRORS => error
      STDERR.puts "Failed http_get to #{url}: #{error} (#{error.class})"
      lastErr = error
      next
    end

    return response    
  end

  http_fault(lastErr)
end
http_post(url_list, path, body, headers) click to toggle source
# File lib/util.rb, line 19
def http_post(url_list, path, body, headers)
  lastErr = nil

  url_list.split(';').each do |url|
    uri = URI(url)

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Post.new(path, headers)
    request.body = body
    if uri.user
      request.basic_auth URI.unescape(uri.user), URI.unescape(uri.password)
    end
    begin
      #response = http.post(path, body, headers)
      response = http.start {|http| http.request(request) }
    rescue *HTTP_ERRORS => error
      STDERR.puts "Failed http_post to #{url}: #{error} (#{error.class})"
      lastErr = error
      next
    end

    return response    
  end

  http_fault(lastErr)
end
http_put(url_list, path, body, headers) click to toggle source
# File lib/util.rb, line 46
def http_put(url_list, path, body, headers)
  lastErr = nil

  url_list.split(';').each do |url|
    uri = URI(url)

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Put.new(path, headers)
    request.body = body
    if uri.user
      request.basic_auth URI.unescape(uri.user), URI.unescape(uri.password)
    end
    begin
      #response = http.put(path, body, headers)
      response = http.start {|http| http.request(request) }
    rescue *HTTP_ERRORS => error
      STDERR.puts "Failed http_put to #{url}: #{error} (#{error.class})"
      lastErr = error
      next
    end

    return response    
  end

  http_fault(lastErr)
end