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



42
43
44
# File 'lib/failbot/haystack.rb', line 42

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

#send_data(data) ⇒ Object

Raises:

  • (StandardError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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' => Yajl.dump(data))

  if user && password
    post.basic_auth(user, password)
  end

  # make request
  http = Net::HTTP.new(@url.host, @url.port)

  # use SSL if applicable
  http.use_ssl = true if @url.scheme == "https"

  # push it through
  response = http.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