Class: FlyIO::Client
- Inherits:
-
Object
- Object
- FlyIO::Client
- Defined in:
- lib/fly_io/client.rb
Constant Summary collapse
- RESOURCE_NAMES =
%w[apps certificates machines secrets volumes organizations platform postgres_clusters tokens network_policies metrics].freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #graphql ⇒ Object
-
#initialize(configuration = nil, **options) ⇒ Client
constructor
A new instance of Client.
- #operation(operation_id, method: nil, path: nil, **arguments) ⇒ Object
- #request(method:, path:, path_params: {}, query: {}, headers: {}, body: FlyIO::UNSET, content_type: "application/json", accept: "application/json", retry_unsafe: nil, timeout: nil) ⇒ Object
- #transport_for(operation) ⇒ Object
Constructor Details
#initialize(configuration = nil, **options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fly_io/client.rb', line 10 def initialize(configuration = nil, **) if configuration && !.empty? raise ConfigurationError, "provide a Configuration or keyword options, not both" end @configuration = configuration || Configuration.new(**) unless @configuration.is_a?(Configuration) raise ConfigurationError, "configuration must be a FlyIO::Configuration" end @transport = Transport.new(@configuration) @metrics_transport = Transport.new(@configuration.with(base_url: @configuration.metrics_url)) @resources = RESOURCE_NAMES.to_h do |name| [name, Resources.class_for(name).new(self)] end.freeze freeze end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/fly_io/client.rb', line 8 def configuration @configuration end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
8 9 10 |
# File 'lib/fly_io/client.rb', line 8 def transport @transport end |
Instance Method Details
#graphql ⇒ Object
33 34 35 |
# File 'lib/fly_io/client.rb', line 33 def graphql GraphQLClient.new(configuration) end |
#operation(operation_id, method: nil, path: nil, **arguments) ⇒ Object
47 48 49 50 |
# File 'lib/fly_io/client.rb', line 47 def operation(operation_id, method: nil, path: nil, **arguments) operation = OperationRegistry.fetch(operation_id, method: method, path: path) @resources.fetch(operation.ruby_resource).operation(operation_id, method: method, path: path, **arguments) end |
#request(method:, path:, path_params: {}, query: {}, headers: {}, body: FlyIO::UNSET, content_type: "application/json", accept: "application/json", retry_unsafe: nil, timeout: nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/fly_io/client.rb', line 41 def request(method:, path:, path_params: {}, query: {}, headers: {}, body: FlyIO::UNSET, content_type: "application/json", accept: "application/json", retry_unsafe: nil, timeout: nil) transport.request(method: method, path: path, path_params: path_params, query: query, headers: headers, body: body, content_type: content_type, accept: accept, retry_unsafe: retry_unsafe, timeout: timeout) end |
#transport_for(operation) ⇒ Object
37 38 39 |
# File 'lib/fly_io/client.rb', line 37 def transport_for(operation) operation.surface == "prometheus_metrics" ? @metrics_transport : transport end |