Class: K8y::REST::Connection

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

Constant Summary collapse

VERBS =
[:get, :post, :put, :patch, :delete]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path:, ssl:, auth:, &conn_options) ⇒ Connection

Returns a new instance of Connection.



25
26
27
28
29
30
31
32
33
# File 'lib/k8y/rest/connection.rb', line 25

def initialize(base_path:, ssl:, auth:, &conn_options)
  @base_path = base_path
  @auth = auth
  @connection = Faraday.new(base_path, ssl: ssl) do |connection|
    connection.use(Faraday::Response::RaiseError)
    auth.configure_connection(connection)
    yield connection if block_given?
  end
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



12
13
14
# File 'lib/k8y/rest/connection.rb', line 12

def base_path
  @base_path
end

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/k8y/rest/connection.rb', line 12

def connection
  @connection
end

#token_storeObject

Returns the value of attribute token_store.



13
14
15
# File 'lib/k8y/rest/connection.rb', line 13

def token_store
  @token_store
end

Class Method Details

.from_config(config) ⇒ Object

Initialize a Connection object using a provided REST::Config instance



20
21
22
# File 'lib/k8y/rest/connection.rb', line 20

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

Instance Method Details

#generate_token!Object



35
36
37
# File 'lib/k8y/rest/connection.rb', line 35

def generate_token!
  auth.generate_token!(self) if auth.respond_to?(:generate_token!)
end

#hostObject



39
40
41
# File 'lib/k8y/rest/connection.rb', line 39

def host
  URI(base_path).host
end