Class: InfluxRemix::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/influx_remix/writer.rb

Instance Method Summary collapse

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