Class: Failbot::Haystack

Inherits:
Object
  • Object
show all
Defined in:
lib/failbot/haystack.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Haystack

Returns a new instance of Haystack.



7
8
9
# File 'lib/failbot/haystack.rb', line 7

def initialize(url)
  @url = url
end

Class Method Details

.send_data(data) ⇒ Object



30
31
32
# File 'lib/failbot/haystack.rb', line 30

def self.send_data(data)
  new(Failbot.haystack).send_data(data)
end

Instance Method Details

#passwordObject



15
16
17
# File 'lib/failbot/haystack.rb', line 15

def password
  @url.password
end

#pingObject

Raises:

  • (StandardError)


34
35
36
37
38
# File 'lib/failbot/haystack.rb', line 34

def ping
  request = Net::HTTP::Head.new('/')
  response = send_request(request)
  raise StandardError, "haystack returned #{response.code}" unless response.code == "200"
end

#send_data(data) ⇒ Object

Raises:

  • (StandardError)


19
20
21
22
23
24
25
26
27
28
# File 'lib/failbot/haystack.rb', line 19

def send_data(data)
  # make a post
  post = Net::HTTP::Post.new(@url.path)
  post.set_form_data('json' => data.to_json)
  response = send_request(post)

  # Raise if the exception doesn't make it to Haystack, ensures the failure
  # is logged
  raise StandardError, "couldn't send exception to Haystack" unless response.code == "201"
end

#userObject



11
12
13
# File 'lib/failbot/haystack.rb', line 11

def user
  @url.user || "failbot"
end