Class: PetstoreApiClient::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/petstore_api_client/client.rb

Overview

Base HTTP client for Petstore API

Provides low-level HTTP communication with the Petstore API. This class includes Connection and Request modules to handle connection management and HTTP request execution.

Most users should use the higher-level PetClient or StoreClient instead of using this class directly.

Examples:

Creating a client with default configuration

client = PetstoreApiClient::Client.new

Creating a client with custom configuration

config = PetstoreApiClient::Configuration.new
config.api_key = "special-key"
config.timeout = 60
client = PetstoreApiClient::Client.new(config)

Configuring an existing client

client = PetstoreApiClient::Client.new
client.configure do |c|
  c.api_key = "special-key"
  c.timeout = 60
end

See Also:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#delete, #get, #post, #put

Constructor Details

#initialize(config = nil) ⇒ Client

Initialize a new HTTP client

Creates a new client instance with the provided configuration. If no configuration is provided, uses default configuration. Validates configuration before creating the client.

Examples:

With default configuration

client = Client.new

With custom configuration

config = Configuration.new
config.api_key = "special-key"
client = Client.new(config)

Parameters:

  • config (Configuration, nil) (defaults to: nil)

    Optional configuration object. If nil, creates a new Configuration with defaults.

Raises:

Since:

  • 0.1.0



59
60
61
62
# File 'lib/petstore_api_client/client.rb', line 59

def initialize(config = nil)
  @configuration = config || Configuration.new
  @configuration.validate!
end

Instance Attribute Details

#configurationObject (readonly)

Since:

  • 0.1.0



38
39
40
# File 'lib/petstore_api_client/client.rb', line 38

def configuration
  @configuration
end

Instance Method Details

#configure {|configuration| ... } ⇒ Client

Configure the client via block

Yields the configuration object to the block for modification. Automatically resets the connection after configuration changes to ensure new settings are applied.

Examples:

client = Client.new
client.configure do |config|
  config.api_key = "special-key"
  config.timeout = 60
  config.retry_enabled = false
end

Yield Parameters:

Returns:

  • (Client)

    self for method chaining

Since:

  • 0.1.0



81
82
83
84
85
# File 'lib/petstore_api_client/client.rb', line 81

def configure
  yield(configuration) if block_given?
  reset_connection! # Need to reset when config changes
  self
end