Class: Failbot::Haystack

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, connect_timeout = nil) ⇒ Haystack

Returns a new instance of Haystack.



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

def initialize(url, connect_timeout=nil)
  @url = url
  @connect_timeout = connect_timeout
end

Instance Attribute Details

#connect_timeoutObject

Returns the value of attribute connect_timeout.



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

def connect_timeout
  @connect_timeout
end

Class Method Details

.send_data(data) ⇒ Object



32
33
34
# File 'lib/failbot/haystack.rb', line 32

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

Instance Method Details

#passwordObject



17
18
19
# File 'lib/failbot/haystack.rb', line 17

def password
  @url.password
end

#pingObject

Raises:

  • (StandardError)


36
37
38
39
40
# File 'lib/failbot/haystack.rb', line 36

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)


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

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



13
14
15
# File 'lib/failbot/haystack.rb', line 13

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