Class: K8y::Client::RESTClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, context:, path: "") ⇒ RESTClient

Returns a new instance of RESTClient.



14
15
16
17
18
19
20
21
# File 'lib/k8y/client/rest_client.rb', line 14

def initialize(config:, context:, path: "")
  @config = config
  @context = context
  @path = path

  # TODO: generically handle auth depending on provided config
  hardcoded_auth
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/k8y/client/rest_client.rb', line 12

def context
  @context
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/k8y/client/rest_client.rb', line 12

def path
  @path
end

Instance Method Details

#delete(sub_path = "", headers: {}, as: :ros) ⇒ Object



43
44
45
46
# File 'lib/k8y/client/rest_client.rb', line 43

def delete(sub_path = "", headers: {}, as: :ros)
  response = connection.delete(formatted_uri(host, path, sub_path))
  format_response(response, as: as)
end

#get(sub_path = "", headers: {}, as: :ros) ⇒ Object



23
24
25
26
# File 'lib/k8y/client/rest_client.rb', line 23

def get(sub_path = "", headers: {}, as: :ros)
  response = connection.get(formatted_uri(host, path, sub_path))
  format_response(response, as: as)
end

#patch(sub_path = "", strategy:, data:, headers: {}, as: :ros) ⇒ Object



38
39
40
41
# File 'lib/k8y/client/rest_client.rb', line 38

def patch(sub_path = "", strategy:, data:, headers: {}, as: :ros)
  response = connection.patch(formatted_uri(host, path, sub_path), data, headers)
  format_response(response, as: as)
end

#post(sub_path = "", data:, headers: {}, as: :ros) ⇒ Object



28
29
30
31
# File 'lib/k8y/client/rest_client.rb', line 28

def post(sub_path = "", data:, headers: {}, as: :ros)
  response = connection.post(formatted_uri(host, path, sub_path), data, headers)
  format_response(response, as: as)
end

#put(sub_path = "", data:, headers: {}, as: :ros) ⇒ Object



33
34
35
36
# File 'lib/k8y/client/rest_client.rb', line 33

def put(sub_path = "", data:, headers: {}, as: :ros)
  response = connection.put(formatted_uri(host, path, sub_path), data, headers)
  format_response(response, as: as)
end