Class: Fsp::Proxies::WebUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/fsp/web_utils.rb

Class Method Summary collapse

Class Method Details

.fetch(url:, headers: { 'Accept' => '*/*' }, method: :get, verifyssl: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fsp/web_utils.rb', line 4

def self.fetch(url:, headers: { 'Accept' => '*/*' }, method: :get, verifyssl: false)
  warn 'In fetch routine now.  '

  begin
    warn "executing call over the Web to #{url}"
    response = RestClient::Request.execute({
                                             method: method,
                                             url: url.to_s,
                                             # user: user,
                                             # password: pass,
                                             headers: headers,
                                             :verify_ssl => verifyssl
                                           })
    warn "starting URL #{url}"
    warn "final URL #{response.request.url}"
    warn "Response code #{response.code}"
    response
  rescue RestClient::ExceptionWithResponse => e
    warn "EXCEPTION WITH RESPONSE! #{e.response.code} with response #{e.response}\nfailed response headers: #{e.response.headers}"
    if e.response.code == 500 or e.response.code == 404
      false
    else
      e.response
    end
    # now we are returning the headers and body that were returned
  rescue RestClient::Exception => e
    warn "EXCEPTION WITH NO RESPONSE! #{e}"
    false
    # now we are returning 'False', and we will check that with an \"if\" statement in our main code
  rescue Exception => e
    warn "EXCEPTION UNKNOWN! #{e}"
    false
    # now we are returning 'False', and we will check that with an \"if\" statement in our main code
  end
end