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



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

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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
  req = Net::HTTP.new(@url.host, @url.port)

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

  # push it through
  req.start { |http| http.request(post) }
end

#userObject



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

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