Class: Measures::Transports::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/measures/transports/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80, url = "/") ⇒ HTTP

Returns a new instance of HTTP.



8
9
10
11
12
# File 'lib/measures/transports/http.rb', line 8

def initialize(host, port = 80, url = "/")
  @host = host
  @port = port
  @url = url
end

Instance Method Details

#send(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/measures/transports/http.rb', line 14

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