Class: LetMeSendEmail::HttpTransport
- Inherits:
-
Object
- Object
- LetMeSendEmail::HttpTransport
- Defined in:
- lib/letmesendemail/http_transport.rb
Overview
Internal net/http transport.
Constant Summary collapse
- MAX_RETRY_AFTER_SECONDS =
300
Instance Method Summary collapse
- #call(method, path, body: nil, extra_headers: {}) ⇒ Object
-
#initialize(config) ⇒ HttpTransport
constructor
A new instance of HttpTransport.
Constructor Details
#initialize(config) ⇒ HttpTransport
Returns a new instance of HttpTransport.
14 15 16 |
# File 'lib/letmesendemail/http_transport.rb', line 14 def initialize(config) @config = config end |
Instance Method Details
#call(method, path, body: nil, extra_headers: {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/letmesendemail/http_transport.rb', line 18 def call(method, path, body: nil, extra_headers: {}) uri = URI.parse("#{@config.base_url}/#{path.sub(%r{^/}, '')}") response = perform(uri, method, body, extra_headers) headers = response.each_header.to_h { |key, value| [key.downcase, value] } status = response.code.to_i raw_body = response.body.to_s parsed = parse_response_body(raw_body, status, headers) return Models.wrap(parsed) if status.between?(200, 299) raise error_from_status(status, parsed, headers, raw_body) rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout => e raise TimeoutError, e. rescue SocketError, SystemCallError, IOError, OpenSSL::SSL::SSLError, Net::HTTPBadResponse => e raise NetworkError, e. end |