-
Notifications
You must be signed in to change notification settings - Fork 0
fix: renamed #get_without_prefix to #get_url for clarity #11
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,6 +2,7 @@ | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| require 'httpx' | ||||||||||||||||||||||
| require 'json' | ||||||||||||||||||||||
| require 'uri' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| module Rubyists | ||||||||||||||||||||||
| module Kalshi | ||||||||||||||||||||||
|
|
@@ -19,13 +20,33 @@ def initialize(base_url: Kalshi.config.base_url) | |||||||||||||||||||||
| .with(origin: base_url) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Get response from a path, adding the base_url, | ||||||||||||||||||||||
| # and a prefix, if set on the client. | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # see #full_path for details | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # @param path [String] The URL path | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # @return [Hash] The parsed JSON response | ||||||||||||||||||||||
| def get(path, params: {}) | ||||||||||||||||||||||
| get_without_prefix(full_url(path), params:) | ||||||||||||||||||||||
| get_url(full_url(path), params:) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_without_prefix(path, params: {}) | ||||||||||||||||||||||
| response = @http.get(path, params:) | ||||||||||||||||||||||
| # Get response from a URL | ||||||||||||||||||||||
| # Must pass a full URL, including scheme (http/https), host, etc. | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # @param path [String] The full URL path | ||||||||||||||||||||||
|
||||||||||||||||||||||
| # @param path [String] The full URL path | |
| # @param url [String] The full URL |
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 error raised is ArgumentError but caught and re-raised as Error. This creates inconsistency - URI.parse raises URI::InvalidURIError for invalid URIs, not ArgumentError. The custom ArgumentError on line 43 won't be caught by the rescue on line 47 if URI.parse fails first. Consider rescuing URI::InvalidURIError and StandardError to handle both validation scenarios properly.
| raise ArgumentError, 'URL must be http or https' unless %w[http https].include?(uri.scheme) | |
| response = @http.get(url, params:) | |
| handle_response(response) | |
| rescue ArgumentError => e | |
| raise URI::InvalidURIError, 'URL must be http or https' unless %w[http https].include?(uri.scheme) | |
| response = @http.get(url, params:) | |
| handle_response(response) | |
| rescue URI::InvalidURIError => e |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,35 @@ | |
| end | ||
| end | ||
|
|
||
| describe '#get_url' do | ||
| it 'fetches from a full URL' do | ||
|
||
| url = 'https://example.com/api/resource' | ||
| stub_request(:get, url) | ||
| .to_return(status: 200, body: '{"data": "value"}', headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| client = Rubyists::Kalshi::Client.new | ||
| response = client.get_url(url) | ||
|
|
||
| assert_equal({ data: 'value' }, response) | ||
| end | ||
|
|
||
| it 'raises Error for invalid URL scheme' do | ||
| client = Rubyists::Kalshi::Client.new | ||
| error = assert_raises(Rubyists::Kalshi::Error) do | ||
| client.get_url('ftp://example.com') | ||
| end | ||
| assert_match(/Invalid URL/, error.message) | ||
| end | ||
|
|
||
| it 'raises Error for invalid URL format' do | ||
| client = Rubyists::Kalshi::Client.new | ||
| error = assert_raises(Rubyists::Kalshi::Error) do | ||
| client.get_url('not_a_url') | ||
| end | ||
| assert_match(/Invalid URL/, error.message) | ||
| end | ||
|
Comment on lines
+33
to
+47
|
||
| end | ||
|
|
||
| describe '#market' do | ||
| it 'returns a Market::Client instance' do | ||
| client = Rubyists::Kalshi::Client.new | ||
|
|
||
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 parameter is named 'path' but the method now expects a full URL. The parameter name should be 'url' to match the method name and its documentation.