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) ⇒ SyncSender

Returns a new instance of SyncSender.



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

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

Instance Method Details

#send(data) ⇒ Object



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

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