Class: Rubyists::Kalshi::ApiClient

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

Overview

Base class for API client wrappers that automatically configure URL prefixes

Examples:

Using ApiClient with a Search namespace

# For Rubyists::Kalshi::Search::Client, the prefix will be "search"
class Search::Client < ApiClient
  # API calls will automatically use /search/ prefix
end

Overriding the automatic prefix

class CustomClient < ApiClient
  self.prefix = 'custom_api'
end

Direct Known Subclasses

Events::Client, Search::Client, Series::Client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ void

Initialize the ApiClient with a given client instance

Parameters:



42
43
44
45
# File 'lib/kalshi/api_client.rb', line 42

def initialize(client)
  @client = client
  client.prefix = self.class.prefix
end

Instance Attribute Details

#client ⇒ Object (readonly)

Returns the value of attribute client.



18
19
20
# File 'lib/kalshi/api_client.rb', line 18

def client
  @client
end

Class Method Details

.prefix ⇒ String

Automatically extract the URL prefix from the module hierarchy

The prefix is derived by taking the second-to-last component of the fully qualified class name and converting it to lowercase. For example:

- Rubyists::Kalshi::Search::Client => "search"
- Rubyists::Kalshi::Market::Client => "market"

Returns:

  • (String) —

    the URL prefix for API calls



28
29
30
# File 'lib/kalshi/api_client.rb', line 28

def self.prefix
  @prefix ||= to_s.split('::')[-2].downcase
end

.prefix=(value) ⇒ Object

Set a custom URL prefix for API calls, for overriding the default behavior



33
34
35
# File 'lib/kalshi/api_client.rb', line 33

def self.prefix=(value) # rubocop:disable Style/TrivialAccessors
  @prefix = value
end