class WebServiceMethods

Public Class Methods

get_response_code(url, timeout) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 4
def self.get_response_code(url, timeout)
  response = HTTParty.get url, {timeout => timeout}
  return response.code
end
send_XML_post_request(url, data) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 38
def self.send_XML_post_request(url, data)
  begin
    # puts "*** #{'WebServiceMethods.send_post_request.url'.ljust(47,' ')}: #{url}"
    # puts "WebServiceMethods.send_post_request.data: #{data}"
    response = RestClient.post url, data, :content_type => "text/xml", :timeout => 180000
    return response
  rescue => e
    raise "*** ERROR: when sending put request to '#{url}'. Info: \n\n #{e.message}"
  end
end
send_get_request(url) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 49
def self.send_get_request(url)
  begin
    response = HTTParty.get url, timeout: 180000
    return response
  rescue => e
    raise "*** ERROR: when sending get request to '#{url}'. Info: \n\n #{e.message}"
  end
end
send_post_request(url, data) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 27
def self.send_post_request(url, data)
  begin
    puts "*** #{'WebServiceMethods.send_post_request.url'.ljust(47,' ')}: #{url}"
    puts "WebServiceMethods.send_post_request.data: #{data}"
    response = HTTParty.post url, {:body => data, :timeout => 180000}
    return response
  rescue => e
    raise "*** ERROR: when sending put request to '#{url}'. Info: \n\n #{e.message}"
  end
end
send_put_request(url, data) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 18
def self.send_put_request(url, data)
  begin
    response = HTTParty.put url, {:body => data, :timeout => 180000}
    return response
  rescue => e
    raise "*** ERROR: when sending put request to '#{url}'. Info: \n\n #{e.message}"
  end
end
url_reach?(url, timeout) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 9
def self.url_reach? (url, timeout)
  response_code = get_response_code(url, timeout)
  if response_code/10 ==2
    return true
  else
    return false
  end
end
verify_response(reponse) click to toggle source
# File lib/anhpham/methods/web_service_methods.rb, line 58
def self.verify_response(reponse)
  if response.code/100 != 2
    raise "*** ERROR: when processing the request. More info: \n\n #{response.body.to_s}"
  end
end