Class: FlyIO::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, **options)
  if configuration && !options.empty?
    raise ConfigurationError, "provide a Configuration or keyword options, not both"
  end

  @configuration = configuration || Configuration.new(**options)
  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

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/fly_io/client.rb', line 8

def configuration
  @configuration
end

#transportObject (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

#graphqlObject



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