Assignment 3/assignment3.rb
### DEFINING METHODS ###
# 1. contact the web and handle possible errors
DEFINING METHODS
1. contact the web and handle possible errors
DEFINING METHODS 1 . contact the web and handle possible errors
def fetch(url, headers = {accept: "*/*"}, user = "", pass="") 
  response = RestClient::Request.execute({
    method: :get,
    url: url.to_s,
    user: user,
    password: pass,
    headers: headers})
  return response
  rescue RestClient::ExceptionWithResponse => e 
    $stderr.puts e.inspect
    response = false
    return response  
  rescue RestClient::Exception => e
    $stderr.puts e.inspect
    response = false
    return response  
  rescue Exception => e
    $stderr.puts e.inspect
    response = false
    return response  
end
def fetch ( url , headers = { accept : "*/*" } , user = "" , pass = "" ) response = RestClient :: Request . execute ( { method : :get , url : url . to_s , user : user , password : pass , headers : headers } ) return response rescue RestClient :: ExceptionWithResponse => e $stderr . puts e . inspect response = false return response rescue RestClient :: Exception => e $stderr . puts e . inspect response = false return response rescue Exception => e $stderr . puts e . inspect response = false return response end
DEFINING METHODS
1. contact the web and handle possible errors
DEFINING METHODS 1 . contact the web and handle possible errors
# handling-errors # si pasa este error rescatalo de este codigo # now we are returning 'False', and we will check that with an \"if\" statement in our main code # now we are returning 'False', and we will check that with an \"if\" statement in our main code # now we are returning 'False', and we will check that with an \"if\" statement in our main code
url
<not_specific>
headers
<not_specific>
user
<not_specific>
pass
<not_specific>