Class: Hanko::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hanko/client.rb

Overview

Main entry point for interacting with the Hanko API.

A client merges any per-instance options with the global Configuration, then exposes admin and public API namespaces.

Examples:

Create a client with inline options

client = Hanko::Client.new(api_url: "https://example.hanko.io", api_key: "key")
client.admin.users.list

Create a client using global configuration

Hanko.configure { |c| c.api_url = "https://example.hanko.io" }
client = Hanko::Client.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Client

Creates a new Hanko API client.

Options override values from the global Hanko.configuration.

Parameters:

  • options (Hash)

    configuration overrides

Options Hash (**options):

  • :api_url (String)

    the Hanko API base URL

  • :api_key (String)

    the API key for admin endpoints

  • :timeout (Integer)

    request timeout in seconds

  • :open_timeout (Integer)

    connection open timeout in seconds

  • :retry_count (Integer)

    number of retries on failure

  • :adapter (Array)

    Faraday adapter (for testing)

Raises:



32
33
34
35
36
37
# File 'lib/hanko/client.rb', line 32

def initialize(**options)
  @adapter = options.delete(:adapter)
  @config = build_config(options)
  validate_config!
  @connection = Connection.new(@config, adapter: @adapter)
end

Instance Attribute Details

#configConfiguration (readonly)

Returns the resolved configuration for this client.

Returns:



18
19
20
# File 'lib/hanko/client.rb', line 18

def config
  @config
end

Instance Method Details

#adminApi::AdminNamespace

Returns the admin API namespace for managing users, emails, etc.

Returns:



42
43
44
# File 'lib/hanko/client.rb', line 42

def admin
  @admin ||= Api::AdminNamespace.new(@connection)
end

#inspectString

Returns a human-readable representation with the API key redacted.

Returns:

  • (String)


56
57
58
# File 'lib/hanko/client.rb', line 56

def inspect
  "#<#{self.class} api_url=#{config.api_url.inspect} api_key=[REDACTED]>"
end

#publicApi::PublicNamespace

Returns the public API namespace for flows, well-known endpoints, etc.



49
50
51
# File 'lib/hanko/client.rb', line 49

def public
  @public ||= Api::PublicNamespace.new(@connection)
end