class Qmetrics::API

Public Class Methods

new(server: , port: , user: , pass: ) click to toggle source
# File lib/qmetrics/api.rb, line 7
def initialize(server: , port: , user: , pass: )
  @base_route = "http://#{server}:#{port}/queuemetrics"
  @auth = { basic_auth: { username: user, password: pass } }
end

Public Instance Methods

call(api_method,options={}) click to toggle source
# File lib/qmetrics/api.rb, line 12
def call(api_method,options={})
  check_status(HTTParty.get("#{@base_route}/#{api_method}",
                            options.merge(@auth)))
end
realtime(**args) click to toggle source
# File lib/qmetrics/api.rb, line 25
def realtime(**args)
  if args.empty?
    @realtime
  else
    @realtime = Qmetrics::Realtime.new(args.merge({api: self}))
  end
end
stats(**args) click to toggle source
# File lib/qmetrics/api.rb, line 17
def stats(**args)
  if args.empty?
    @stats
  else
    @stats = Qmetrics::Stats.new(args.merge({api: self}))
  end
end

Private Instance Methods

check_status(r) click to toggle source
# File lib/qmetrics/api.rb, line 35
def check_status(r)
  if r.response.code == "200"
    r.parsed_response
  else
    raise(HTTPStatusError, r.response.code)
  end
end