Module: Xapixctl::PhoenixClient

Defined in:
lib/xapixctl/phoenix_client.rb,
lib/xapixctl/phoenix_client/connection.rb,
lib/xapixctl/phoenix_client/result_handler.rb,
lib/xapixctl/phoenix_client/project_connection.rb,
lib/xapixctl/phoenix_client/organization_connection.rb

Defined Under Namespace

Classes: Connection, OrganizationConnection, ProjectConnection, ResultHandler

Constant Summary collapse

SUPPORTED_RESOURCE_TYPES =

sorting is intentional to reflect dependencies when exporting

%w[
  Project
  Ambassador
  AuthScheme
  Credential
  Proxy
  CacheConnection
  Schema
  DataSource
  Service
  ServiceInstall
  Pipeline
  EndpointGroup
  Endpoint
  StreamGroup
  Stream
  StreamProcessor
  Scheduler
  ApiPublishing
  ApiPublishingRole
  ApiPublishingAccessRule
].freeze
TEXT_FORMATTERS =
{
  all: ->(data) { "id  : %<id>s\nkind: %<kind>s\nname: %<name>s\n\n" % { id: data.dig('metadata', 'id'), kind: data['kind'], name: data.dig('definition', 'name') } }
}.freeze
FORMATTERS =
{
  json: ->(data) { JSON.pretty_generate(data) },
  yaml: ->(data) { Psych.dump(data) },
  text: ->(data) { (TEXT_FORMATTERS[data.dig('metadata', 'type')] || TEXT_FORMATTERS[:all]).call(data) }
}.freeze
PREVIEW_FORMATTERS =
{
  json: ->(data) { JSON.pretty_generate(data) },
  yaml: ->(data) { Psych.dump(data) },
  text: ->(data) do
    preview = data['preview']
    if ['RestJson', 'SoapXml'].include?(data['content_type'])
      res = StringIO.new
      if preview.is_a?(Hash)
        res.puts "HTTP #{preview['status']}"
        preview['headers']&.each { |h, v| res.puts "#{h}: #{v}" }
        res.puts
        res.puts preview['body']
      else
        res.puts preview
      end
      res.string
    else
      Psych.dump(preview)
    end
  end
}.freeze
DEFAULT_SUCCESS_HANDLER =
->(result) { result }
DEFAULT_ERROR_HANDLER =
->(err, _response) { warn "Could not get data: #{err}" }

Class Method Summary collapse

Class Method Details

.connection(url, token, default_success_handler: DEFAULT_SUCCESS_HANDLER, default_error_handler: DEFAULT_ERROR_HANDLER, logging: nil) ⇒ Object



72
73
74
# File 'lib/xapixctl/phoenix_client.rb', line 72

def self.connection(url, token, default_success_handler: DEFAULT_SUCCESS_HANDLER, default_error_handler: DEFAULT_ERROR_HANDLER, logging: nil)
  Connection.new(url, token, default_success_handler, default_error_handler, logging)
end

.supported_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/xapixctl/phoenix_client.rb', line 76

def self.supported_type?(type)
  SUPPORTED_RESOURCE_TYPES.include?(type)
end