Class: InfluxRemix::Writer
- Inherits:
-
Object
- Object
- InfluxRemix::Writer
- Defined in:
- lib/influx_remix/writer.rb
Instance Method Summary collapse
-
#initialize(host, org, bucket, token) ⇒ Writer
constructor
A new instance of Writer.
- #write(data) ⇒ Object
Constructor Details
#initialize(host, org, bucket, token) ⇒ Writer
Returns a new instance of Writer.
5 6 7 8 9 10 |
# File 'lib/influx_remix/writer.rb', line 5 def initialize(host, org, bucket, token) @url = host @org = org @bucket = bucket @token = token end |
Instance Method Details
#write(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/influx_remix/writer.rb', line 12 def write(data) stringData = data.reduce("") do |blob, line| blob + line.line_protocol + "\n" end conn = Faraday.new( url: @url, params: {org: @org, bucket: @bucket}, headers: {"Authorization" => "Token #{@token}"} ) res = conn.post('api/v2/write') do |req| req.body = stringData.chomp end end |