Class: Sentiero::Reporter::HttpTransport
- Inherits:
-
Object
- Object
- Sentiero::Reporter::HttpTransport
- Defined in:
- lib/sentiero/reporter/http_transport.rb
Overview
Posts a JSON payload to "
Constant Summary collapse
- LOOPBACK_HOSTS =
%w[localhost 127.0.0.1 ::1].freeze
Instance Method Summary collapse
-
#initialize(endpoint:, ingest_key:, open_timeout:, read_timeout:) ⇒ HttpTransport
constructor
A new instance of HttpTransport.
- #post(path, payload) ⇒ Object
Constructor Details
#initialize(endpoint:, ingest_key:, open_timeout:, read_timeout:) ⇒ HttpTransport
Returns a new instance of HttpTransport.
13 14 15 16 17 18 19 |
# File 'lib/sentiero/reporter/http_transport.rb', line 13 def initialize(endpoint:, ingest_key:, open_timeout:, read_timeout:) @endpoint = endpoint.to_s.sub(%r{/+\z}, "") @ingest_key = ingest_key @open_timeout = open_timeout @read_timeout = read_timeout warn_insecure_endpoint end |
Instance Method Details
#post(path, payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sentiero/reporter/http_transport.rb', line 21 def post(path, payload) uri = URI.parse("#{@endpoint}/#{path}") http = build_http(uri) request = Net::HTTP::Post.new(uri) request["content-type"] = "application/json" request["authorization"] = "Bearer #{@ingest_key}" request.body = JSON.generate(payload) http.request(request) end |