Class: Livestatus::PatronHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Livestatus::PatronHandler
- Defined in:
- lib/livestatus/handler/patron.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(config) ⇒ PatronHandler
constructor
A new instance of PatronHandler.
- #query(method, query, headers = {}) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(config) ⇒ PatronHandler
Returns a new instance of PatronHandler.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/livestatus/handler/patron.rb', line 10 def initialize(config) @session = Patron::Session.new @session.timeout = 10 @session.headers["User-Agent"] = "livestatus/#{VERSION} ruby/#{RUBY_VERSION}" @session.insecure = config[:insecure] @session.auth_type = config.fetch(:auth_type, :basic).to_sym @session.username = config[:username] @session.password = config[:password] @uri = config[:uri] end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
8 9 10 |
# File 'lib/livestatus/handler/patron.rb', line 8 def session @session end |
Instance Method Details
#query(method, query, headers = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/livestatus/handler/patron.rb', line 21 def query(method, query, headers = {}) headers = Hash[headers.merge({ :query => "#{method.to_s.upcase} #{query}" }).map do |k, v| ["X-Livestatus-#{k.to_s.dasherize}", v] end] result = session.get(@uri, headers) unless result.status == 200 raise HandlerException, "livestatus query failed with status #{result.status}" end Yajl::Parser.parse(result.body) end |