Class: Measures::Transports::HTTP
- Inherits:
-
Object
- Object
- Measures::Transports::HTTP
- Defined in:
- lib/measures/transports/http.rb
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(host, port = 80, url = "/", open_timeout = 30, timeout = 30) ⇒ HTTP
constructor
A new instance of HTTP.
- #send(data) ⇒ Object
Constructor Details
#initialize(host, port = 80, url = "/", open_timeout = 30, timeout = 30) ⇒ HTTP
Returns a new instance of HTTP.
7 8 9 10 11 12 13 |
# File 'lib/measures/transports/http.rb', line 7 def initialize(host, port = 80, url = "/", open_timeout = 30, timeout = 30) @host = host @port = port @url = url @open_timeout = open_timeout @timeout = timeout end |
Instance Method Details
#client ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/measures/transports/http.rb', line 23 def client Faraday.new(url: URI::HTTP.build(host: @host, port: @port)) do |c| c.request :json c.[:open_timeout] = @open_timeout c.[:timeout] = @timeout c.response :raise_error c.adapter Faraday.default_adapter end end |
#send(data) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/measures/transports/http.rb', line 15 def send(data) client.post do |req| req.url @url req.headers["Content-Type"] = "application/json" req.body = data end end |