22
33require 'httpx'
44require 'json'
5+ require 'uri'
56
67module Rubyists
78 module Kalshi
@@ -19,13 +20,33 @@ def initialize(base_url: Kalshi.config.base_url)
1920 . with ( origin : base_url )
2021 end
2122
23+ # Get response from a path, adding the base_url,
24+ # and a prefix, if set on the client.
25+ #
26+ # see #full_path for details
27+ #
28+ # @param path [String] The URL path
29+ #
30+ # @return [Hash] The parsed JSON response
2231 def get ( path , params : { } )
23- get_without_prefix ( full_url ( path ) , params :)
32+ get_url ( full_url ( path ) , params :)
2433 end
2534
26- def get_without_prefix ( path , params : { } )
27- response = @http . get ( path , params :)
35+ # Get response from a URL
36+ # Must pass a full URL, including scheme (http/https), host, etc.
37+ #
38+ # @param path [String] The full URL path
39+ #
40+ # @return [Hash] The parsed JSON response
41+ def get_url ( url , params : { } )
42+ uri = URI . parse ( url )
43+ raise ArgumentError , 'URL must be http or https' unless %w[ http https ] . include? ( uri . scheme )
44+
45+ response = @http . get ( url , params :)
2846 handle_response ( response )
47+ rescue ArgumentError => e
48+ logger . error ( 'Invalid URL' , url :, exception : e )
49+ raise Error , "Invalid URL: #{ e . message } "
2950 end
3051
3152 def market
0 commit comments