lib/lenddo/authentication.rb in lenddo-2.0.0 vs lib/lenddo/authentication.rb in lenddo-2.1.0

- old
+ new

@@ -1,9 +1,10 @@ require 'base64' require 'curb' require 'json' require 'openssl' +require 'lenddo/errors/exceptions' module Lenddo module Authentication def signed_request(args) host = args[:host] @@ -16,20 +17,30 @@ else body = {} end uri = URI.parse(host + path) - Curl.send(method.to_s, uri.to_s, params) do |http| - headers = sign(method.upcase, path, body) - headers.each do |key, value| - http.headers[key] = value.chomp - end + begin + response = Curl.send(method.to_s, uri.to_s, params) do |http| + headers = sign(method.upcase, path, body) + headers.each do |key, value| + http.headers[key] = value.chomp + end - http.use_ssl = 3 - http.ssl_verify_host = OpenSSL::SSL::VERIFY_PEER - http.cacert = File.absolute_path("./cacert.pem") if RbConfig::CONFIG['host_os'] == 'mingw32' + http.use_ssl = 3 + http.ssl_verify_host = OpenSSL::SSL::VERIFY_PEER + http.cacert = File.absolute_path("./cacert.pem") if RbConfig::CONFIG['host_os'] == 'mingw32' + end + rescue Curl::Err::TimeoutError => e + raise Lenddo::Errors::TimeoutException.new(e.message) + rescue Curl::Err::HostResolutionError => e + raise Lenddo::Errors::HostResolutionError.new(e.message) + rescue => e + raise Lenddo::Errors::UnknownException.new(e.message) end + + response end private def sign(verb, path, body, ts = nil) date_format = "%a %b %d %H:%M:%S %Z %Y" @@ -51,6 +62,6 @@ def sha1_hmac(key, value) OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), key, value) end end -end \ No newline at end of file +end