Sha256: 916d29fb2cb9ef267a116fdf68b50614b62d5bcadc2a4db11388c9e94bd5acb1

Contents?: true

Size: 633 Bytes

Versions: 1

Compression:

Stored size: 633 Bytes

Contents

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

module Measures
  module Transport
    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-3.0.0 lib/measures/transport/http.rb