Class: Hubble::Backend::Haystack

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Haystack

Returns a new instance of Haystack.



3
4
5
# File 'lib/hubble/backend/haystack.rb', line 3

def initialize(url)
  @url = URI.parse(url)
end

Instance Method Details

#passwordObject



19
20
21
# File 'lib/hubble/backend/haystack.rb', line 19

def password
  ENV["HUBBLE_PASSWORD"] || "unknown"
end

#password?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/hubble/backend/haystack.rb', line 23

def password?
  password != "unknown"
end

#report(data) ⇒ Object



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

def report(data)
  send_data(data)
end

#reportsObject



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

def reports
  []
end

#send_data(data) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hubble/backend/haystack.rb', line 27

def send_data(data)
  # make a post

  post = Net::HTTP::Post.new(@url.path)
  post.set_form_data('json' => Yajl.dump(data))

  post.basic_auth(user, password) if password?

  # 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



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

def user
  ENV["HUBBLE_USER"] || "hubble"
end