Class: DebugBundle::Transport::HttpTransport
- Inherits:
-
Object
- Object
- DebugBundle::Transport::HttpTransport
- Defined in:
- lib/debugbundle/transport.rb
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(endpoint) ⇒ HttpTransport
constructor
A new instance of HttpTransport.
Constructor Details
#initialize(endpoint) ⇒ HttpTransport
Returns a new instance of HttpTransport.
44 45 46 |
# File 'lib/debugbundle/transport.rb', line 44 def initialize(endpoint) @uri = URI.parse(endpoint) end |
Instance Method Details
#call(request) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/debugbundle/transport.rb', line 48 def call(request) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = @uri.scheme == 'https' http.open_timeout = 5 http.read_timeout = 5 response = http.post( @uri.request_uri, JSON.generate(events: request.fetch(:events)), { 'Authorization' => "Bearer #{request.fetch(:project_token)}", 'Content-Type' => 'application/json' } ) Result.new( status_code: response.code.to_i, retry_after_seconds: parse_retry_after(response['Retry-After']) ) rescue StandardError Result.new(status_code: 500) end |