Auto-add protocol to URLs that do not have one. Fixes #54

This commit is contained in:
Lorenz Diener 2017-06-15 23:34:11 +02:00
pare 996219c1c8
commit df98fc263e

Veure arxiu

@ -44,6 +44,7 @@ class Mastodon:
Returns client_id and client_secret.
"""
api_base_url = Mastodon.__protocolize(api_base_url)
request_data = {
'client_name': client_name,
@ -95,7 +96,7 @@ class Mastodon:
By default, a timeout of 300 seconds is used for all requests. If you wish to change this,
pass the desired timeout (in seconds) as request_timeout.
"""
self.api_base_url = api_base_url
self.api_base_url = Mastodon.__protocolize(api_base_url)
self.client_id = client_id
self.client_secret = client_secret
self.access_token = access_token
@ -977,6 +978,13 @@ class Mastodon:
self._refresh_token = value
return
@staticmethod
def __protocolize(base_url):
"""Internal add-protocol-to-url helper"""
if not base_url.startswith("http://") and not base_url.startswith("https://"):
base_url = "https://" + base_url
return base_url
##
# Exceptions
##