Class: Kubr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kubr/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/kubr/client.rb', line 7

def initialize
  Kubr.configuration ||= Kubr::Configuration.new
  @cl = RestClient::Resource.new(Kubr.configuration.url,
                                 :user => Kubr.configuration.username,
                                 :password => Kubr.configuration.password,
                                 :verify_ssl => OpenSSL::SSL::VERIFY_NONE)
end

Instance Method Details

#parse_labels_hash(labels) ⇒ Object



28
29
30
31
32
# File 'lib/kubr/client.rb', line 28

def parse_labels_hash(labels)
  labels_string = '?labels='
  labels.each { |key, value| labels_string << "#{key}=#{value}," }
  labels_string
end

#process_response(response) ⇒ Object



24
25
26
# File 'lib/kubr/client.rb', line 24

def process_response(response)
  JSON.parse(response).recursively_symbolize_keys!
end

#send_request(method, path, body = nil, labels = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/kubr/client.rb', line 15

def send_request(method, path, body=nil, labels=nil)
  args = [method]
  args << body.to_json if body
  path += parse_labels_hash(labels) if labels
  process_response @cl[path].send(*args)
rescue RestClient::UnprocessableEntity, RestClient::InternalServerError => e
  process_response e.response
end