Class: Stellwerk::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stellwerk/api_client.rb

Overview

HTTP client wrapper for Stellwerk API communication

Uses net/http from Ruby stdlib for zero external dependencies. Handles authentication, retries, timeouts, and JSON parsing.

Constant Summary collapse

DEFAULT_TIMEOUT =

Default timeout for HTTP requests (seconds)

10
MAX_ATTEMPTS =

Maximum total attempts for transient failures (initial + retries)

3
RETRY_DELAY =

Delay between retries (seconds)

1

Instance Method Summary collapse

Constructor Details

#initialize(api_url:, api_key:, timeout: DEFAULT_TIMEOUT, verify_ssl: true) ⇒ ApiClient

Returns a new instance of ApiClient.

Parameters:

  • api_url (String) —

    Base URL for the API

  • api_key (String) —

    API key for authentication

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT) —

    Request timeout in seconds

  • verify_ssl (Boolean) (defaults to: true) —

    Whether to verify SSL certificates



28
29
30
31
32
33
# File 'lib/stellwerk/api_client.rb', line 28

def initialize(api_url:, api_key:, timeout: DEFAULT_TIMEOUT, verify_ssl: true)
  @api_url = api_url.chomp("/")
  @api_key = api_key
  @timeout = timeout
  @verify_ssl = verify_ssl
end

Instance Method Details

#get(path) ⇒ Hash

Make a GET request

Parameters:

  • path (String) —

    API endpoint path

Returns:

  • (Hash) —

    Parsed JSON response

Raises:



40
41
42
# File 'lib/stellwerk/api_client.rb', line 40

def get(path)
  request(:get, path)
end

#post(path, body = {}) ⇒ Hash

Make a POST request

Parameters:

  • path (String) —

    API endpoint path

  • body (Hash) (defaults to: {}) —

    Request body (will be JSON encoded)

Returns:

  • (Hash) —

    Parsed JSON response

Raises:



50
51
52
# File 'lib/stellwerk/api_client.rb', line 50

def post(path, body = {})
  request(:post, path, body)
end