class Hawkular::Client

Public Class Methods

new(hash) click to toggle source
   # File lib/hawkular/hawkular_client.rb
10 def initialize(hash)
11   hash[:credentials] ||= {}
12   hash[:options] ||= {}
13 
14   fail Hawkular::ArgumentError, 'no parameter ":entrypoint" given' if hash[:entrypoint].nil?
15 
16   @state = hash
17 end

Public Instance Methods

alerts() click to toggle source
   # File lib/hawkular/hawkular_client.rb
40 def alerts
41   @alerts ||= Alerts::Client.new("#{@state[:entrypoint]}/hawkular/alerts",
42                                  @state[:credentials],
43                                  @state[:options])
44 end
inventory() click to toggle source
   # File lib/hawkular/hawkular_client.rb
34 def inventory
35   @inventory ||= Inventory::Client.new("#{@state[:entrypoint]}/hawkular/inventory",
36                                        @state[:credentials],
37                                        @state[:options])
38 end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
   # File lib/hawkular/hawkular_client.rb
29 def method_missing(name, *args, &block)
30   super unless respond_to?(name)
31   client_for_method(name).__send__(submethod_name_for(name), *args, &block)
32 end
operations(open_new = false) click to toggle source

adds a way to explicitly open the new web socket connection (the default is to recycle it) @param open_new [Boolean] if true, opens the new websocket connection

   # File lib/hawkular/hawkular_client.rb
48 def operations(open_new = false)
49   @operations = init_operations_client if open_new
50   @operations ||= init_operations_client
51 end
prometheus() click to toggle source
   # File lib/hawkular/hawkular_client.rb
59 def prometheus
60   @prometheus ||= Prometheus::Client.new(@state[:entrypoint],
61                                          @state[:credentials],
62                                          @state[:options])
63 end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
   # File lib/hawkular/hawkular_client.rb
19 def respond_to_missing?(method_name, include_private = false)
20   delegate_client = client_for_method(method_name)
21   return super if delegate_client.nil?
22 
23   method = submethod_name_for(method_name)
24   return super unless delegate_client.respond_to?(method)
25 
26   true
27 end
tokens() click to toggle source
   # File lib/hawkular/hawkular_client.rb
53 def tokens
54   @tokens ||= Token::Client.new(@state[:entrypoint],
55                                 @state[:credentials],
56                                 @state[:options])
57 end

Private Instance Methods

client_for_method(method_name) click to toggle source
   # File lib/hawkular/hawkular_client.rb
74 def client_for_method(method_name)
75   case method_name
76   when /^inventory_/ then inventory
77   when /^alerts_/ then alerts
78   when /^operations_/ then operations
79   when /^tokens_/ then tokens
80   when /^prometheus_/ then prometheus
81   end
82 end
init_operations_client() click to toggle source

this is in a dedicated method, because constructor opens the websocket connection to make the handshake

   # File lib/hawkular/hawkular_client.rb
68 def init_operations_client
69   Operations::Client.new(entrypoint: @state[:entrypoint],
70                          credentials: @state[:credentials],
71                          options: @state[:options])
72 end
submethod_name_for(method_name) click to toggle source
   # File lib/hawkular/hawkular_client.rb
84 def submethod_name_for(method_name)
85   method_name.to_s.sub(/^[^_]+_/, '')
86 end