···19192020 @endpoint = check_endpoint(endpoint)
2121 @cursor = check_cursor(cursor)
2222- @root_url = @root_url.chomp('/')
2323-2424- if URI(@root_url).path != ''
2525- raise ArgumentError, "Server parameter should not include any path"
2626- end
2222+ @root_url = ensure_empty_path(@root_url)
2723 end
28242925 def handle_message(msg)
+1-6
lib/skyfall/jetstream.rb
···1212 require_relative 'jetstream/message'
1313 super(server)
14141515- @root_url = @root_url.chomp('/')
1616-1717- if URI(@root_url).path != ''
1818- raise ArgumentError, "Server parameter should not include any path"
1919- end
2020-2115 @params = check_params(params)
2216 @cursor = @params.delete(:cursor)
1717+ @root_url = ensure_empty_path(@root_url)
2318 end
24192520 def handle_message(msg)
+27-15
lib/skyfall/stream.rb
···1212 attr_accessor :auto_reconnect, :last_update, :user_agent
1313 attr_accessor :heartbeat_timeout, :heartbeat_interval, :check_heartbeat
14141515- def initialize(service)
1616- @root_url = build_root_url(service)
1515+ def initialize(server)
1616+ @root_url = build_root_url(server)
17171818 @handlers = {}
1919 @auto_reconnect = true
···188188 @root_url
189189 end
190190191191- def build_root_url(service)
192192- if service.is_a?(String)
193193- if service.include?('/')
194194- uri = URI(service)
195195- if uri.scheme != 'ws' && uri.scheme != 'wss'
196196- raise ArgumentError, "Service parameter should be a hostname or a ws:// or wss:// URL"
197197- end
198198- uri.to_s
199199- else
200200- service = "wss://#{service}"
201201- uri = URI(service) # raises if invalid
202202- service
191191+ def build_root_url(server)
192192+ if !server.is_a?(String)
193193+ raise ArgumentError, "Server parameter should be a string"
194194+ end
195195+196196+ if server.include?('://')
197197+ uri = URI(server)
198198+199199+ if uri.scheme != 'ws' && uri.scheme != 'wss'
200200+ raise ArgumentError, "Server parameter should be a hostname or a ws:// or wss:// URL"
203201 end
202202+203203+ uri.to_s
204204 else
205205- raise ArgumentError, "Service parameter should be a string"
205205+ server = "wss://#{server}"
206206+ uri = URI(server) # raises if invalid
207207+ server
208208+ end
209209+ end
210210+211211+ def ensure_empty_path(url)
212212+ url = url.chomp('/')
213213+214214+ if URI(url).path != ''
215215+ raise ArgumentError, "Server URL should only include a hostname, without any path"
206216 end
217217+218218+ url
207219 end
208220 end
209221end