Class: K8y::REST::Connection
- Inherits:
-
Object
- Object
- K8y::REST::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/k8y/rest/connection.rb
Constant Summary collapse
- VERBS =
[:get, :post, :put, :patch, :delete]
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
Class Method Summary collapse
-
.from_config(config) ⇒ Object
Initialize a Connection object using a provided REST::Config instance.
Instance Method Summary collapse
- #generate_token! ⇒ Object
- #host ⇒ Object
-
#initialize(base_path:, ssl:, auth:, &conn_options) ⇒ Connection
constructor
A new instance of Connection.
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:, &) @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_path ⇒ Object (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 |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/k8y/rest/connection.rb', line 12 def connection @connection end |
#token_store ⇒ Object
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., 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 |
#host ⇒ Object
39 40 41 |
# File 'lib/k8y/rest/connection.rb', line 39 def host URI(base_path).host end |