-
Notifications
You must be signed in to change notification settings - Fork 0
fix: correct path to filter_by_sport, adds ApiClient helper #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,12 +2,46 @@ | |||||||||
|
|
||||||||||
| module Rubyists | ||||||||||
| module Kalshi | ||||||||||
| # API Client Base Class | ||||||||||
| # Base class for API client wrappers that automatically configure URL prefixes | ||||||||||
| # | ||||||||||
| # @example 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 | ||||||||||
| # | ||||||||||
| # @example Overriding the automatic prefix | ||||||||||
| # class CustomClient < ApiClient | ||||||||||
| # self.prefix = 'custom_api' | ||||||||||
| # end | ||||||||||
| class ApiClient | ||||||||||
| attr_reader :client | ||||||||||
|
|
||||||||||
| # 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" | ||||||||||
| # | ||||||||||
| # @return [String] the URL prefix for API calls | ||||||||||
| def self.prefix | ||||||||||
| @prefix ||= to_s.split('::')[-2].downcase | ||||||||||
| end | ||||||||||
|
|
||||||||||
| # Set a custom URL prefix for API calls, for overriding the default behavior | ||||||||||
| def self.prefix=(value) # rubocop:disable Style/TrivialAccessors | ||||||||||
| @prefix = value | ||||||||||
| end | ||||||||||
|
|
||||||||||
| # Initialize the ApiClient with a given client instance | ||||||||||
| # | ||||||||||
| # @param client [Rubyists::Kalshi::Client] the client instance to wrap | ||||||||||
| # | ||||||||||
| # @return [void] | ||||||||||
| def initialize(client) | ||||||||||
| @client = client | ||||||||||
| client.prefix = self.class.prefix | ||||||||||
|
Comment on lines
10
to
+44
|
||||||||||
| @client = client | |
| client.prefix = self.class.prefix | |
| @client = client.dup | |
| @client.prefix = self.class.prefix |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialize method in ApiClient lacks test coverage. Consider adding a test that verifies the client is properly assigned and that the prefix is set on the client instance when an ApiClient subclass is instantiated.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,11 @@ def initialize(base_url: Kalshi.config.base_url) | |
| end | ||
|
|
||
| def get(path, params: {}) | ||
| response = @http.get(full_url(path), params:) | ||
| get_without_prefix(full_url(path), params:) | ||
| end | ||
|
|
||
| def get_without_prefix(path, params: {}) | ||
| response = @http.get(path, params:) | ||
| handle_response(response) | ||
| end | ||
|
Comment on lines
22
to
29
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../helper' | ||
|
|
||
| describe Rubyists::Kalshi::ApiClient do | ||
| # rubocop:disable Lint/ConstantDefinitionInBlock | ||
| class TestApiClient < Rubyists::Kalshi::ApiClient | ||
| end | ||
| # rubocop:enable Lint/ConstantDefinitionInBlock | ||
|
|
||
| describe '.prefix=' do | ||
| it 'sets the prefix' do | ||
| TestApiClient.prefix = 'test' | ||
|
|
||
| assert_equal 'test', TestApiClient.prefix | ||
| end | ||
| end | ||
bougyman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.