Class: K8y::REST::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/k8y/rest/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ Client

Returns a new instance of Client.



32
33
34
35
# File 'lib/k8y/rest/client.rb', line 32

def initialize(connection:)
  @connection = connection
  @request_wrapper = RequestWrapper.new
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



16
17
18
# File 'lib/k8y/rest/client.rb', line 16

def connection
  @connection
end

Class Method Details

.from_config(config) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/k8y/rest/client.rb', line 21

def from_config(config)
  new(
    connection: Connection.new(
      base_path: config.base_path,
      ssl: config.transport.to_faraday_options,
      auth: config.auth
    )
  )
end

Instance Method Details

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



65
66
67
68
69
70
# File 'lib/k8y/rest/client.rb', line 65

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

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



37
38
39
40
41
42
# File 'lib/k8y/rest/client.rb', line 37

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

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



58
59
60
61
62
63
# File 'lib/k8y/rest/client.rb', line 58

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

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



44
45
46
47
48
49
# File 'lib/k8y/rest/client.rb', line 44

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

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



51
52
53
54
55
56
# File 'lib/k8y/rest/client.rb', line 51

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