Skip to content

Conversation

@bougyman
Copy link
Member

@bougyman bougyman commented Jan 5, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 5, 2026 14:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR renames the #get_without_prefix method to #get_url for improved clarity, adds URL validation to ensure only HTTP/HTTPS schemes are accepted, and includes comprehensive test coverage for the renamed method.

  • Renamed method from #get_without_prefix to #get_url with URL validation
  • Added URI parsing and scheme validation (http/https only)
  • Added test coverage for successful URL fetching and invalid URL scenarios

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
lib/kalshi/client.rb Renamed method to #get_url, added URL validation with scheme checking and error handling
test/kalshi/client_test.rb Added comprehensive test suite for #get_url covering success case and invalid URL scenarios
Gemfile.lock Version bumped from 0.0.3 to 0.0.4

Comment on lines +33 to +47
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
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following BetterSpecs guidelines, use context blocks to group related test cases by scenario. Consider wrapping these validation tests in a 'context "with invalid URLs"' block to make the test organization clearer.

Copilot generated this review using guidance from repository custom instructions.
# Get response from a URL
# Must pass a full URL, including scheme (http/https), host, etc.
#
# @param path [String] The full URL path
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
# @param path [String] The full URL path
# @param url [String] The full URL

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +47
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
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
# Get response from a URL
# Must pass a full URL, including scheme (http/https), host, etc.
#
# @param path [String] The full URL path
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation says '@param path [String] The full URL path' but the parameter represents a complete URL, not a path. It should read '@param url [String] The full URL' to accurately describe what's expected.

Suggested change
# @param path [String] The full URL path
# @param url [String] The full URL

Copilot uses AI. Check for mistakes.
end

describe '#get_url' do
it 'fetches from a full URL' do
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following BetterSpecs guidelines, test descriptions should focus on behavior rather than implementation. Consider renaming to 'returns data from a full URL' to describe what the method accomplishes rather than how it works.

Copilot generated this review using guidance from repository custom instructions.
@bougyman bougyman merged commit a641a5f into main Jan 5, 2026
12 checks passed
@bougyman bougyman deleted the better-method-names branch January 5, 2026 15:02
This was referenced Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants