I have a URL of this format:
https://clientjiberish:clientsecretjiberish@api.example.com/users?username=tralala
when I do:
url = 'https://clientjiberish:clientsecretjiberish@api.example.com/users?username=tralala'
uri = URI(url)
I get all that I need.
uri.host => "api.example.com"
uri.userinfo => "clientjiberish:clientsecretjiberish"
uri.path => '/users'
uri.scheme => 'https'
The problem rises when the userinfo part has a forward slash in it. I have no power to change the API that serves the API keys, so I need to figure out a way to extract the mentioned parts of the URI.
Here's an example on what you can test the URI:
url = 'https://clientjiberish:client/secretjiberish@api.example.com/users?username=tralala'
uri = URI(url)
The error:
URI::InvalidURIError: bad URI(is not URI?)
I found out that you can create your own parser like this:
parser = URI::Parser.new(:RESERVED => ";/?:@&=+$,\\[\\]")
uri = parser.parse(url)
but I don't know enough about regex to make it work.