Class: WebServiceMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/Ifd_Automation/methods/web_service_methods.rb

Class Method Summary collapse

Class Method Details

.get_response_code(url, timeout) ⇒ Object



4
5
6
7
# File 'lib/Ifd_Automation/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_get_request(url) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/Ifd_Automation/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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/Ifd_Automation/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) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/Ifd_Automation/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

.send_XML_post_request(url, data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/Ifd_Automation/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

.url_reach?(url, timeout) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/Ifd_Automation/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) ⇒ Object



58
59
60
61
62
# File 'lib/Ifd_Automation/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