Class: Sematext::Metrics::SyncSender

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sematext/metrics/sync_sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(token, base_uri, path) ⇒ SyncSender

Returns a new instance of SyncSender.



22
23
24
25
26
# File 'lib/sematext/metrics/sync_sender.rb', line 22

def initialize(token, base_uri, path)
  @token = token
  self.class.default_options[:base_uri] = base_uri ||  Settings::RECEIVER_URI
  @path = path || Settings::RECEIVER_PATH
end

Instance Method Details

#send(data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sematext/metrics/sync_sender.rb', line 28

def send data
  post_options = {
    :query => {:token => @token},
    :headers => {
      'Content-Type' => 'text/plain',
      'User-Agent' => Settings::USER_AGENT
    },
    :body => data
  }
  response = self.class.post(@path, post_options)
  if response.code == 201
    {:status => :succeed}
  else
    {:status => :failed, :response => response.parsed_response}
  end
end