From df98fc263e5e4dd80e1ead574fbd4c72e92ee12c Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Thu, 15 Jun 2017 23:34:11 +0200 Subject: Auto-add protocol to URLs that do not have one. Fixes #54 --- mastodon/Mastodon.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 64f4775..be6ea3f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -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 @@ -976,6 +977,13 @@ class Mastodon: """Internal helper for oauth code""" 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 -- cgit v1.2.3