Sha256: b63c3f8a5cc444931984ce275aa8d980990c1d73fc30c32ca4eece58a4cc0213

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

require "faraday"
require "faraday_middleware"
require "uri"

module Measures
  module Transports
    class HTTP
      def initialize(host, port = 80, url = "/")
        @host = host
        @port = port
        @url = url
      end

      def send(data)
        client = Faraday.new(url: URI::HTTP.build(host: @host, port: @port)) do |c|
          c.request :json

          c.response :raise_error
          c.adapter Faraday.default_adapter
        end

        client.post do |req|
          req.url @url
          req.headers["Content-Type"] = "application/json"
          req.body = data
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
measures-4.0.0 lib/measures/transports/http.rb