diff options
author | Lorenz Diener <[email protected]> | 2017-06-15 23:34:11 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2017-06-15 23:34:11 +0200 |
commit | df98fc263e5e4dd80e1ead574fbd4c72e92ee12c (patch) | |
tree | 20f7d6343791cda26de0ed5f76b6f8b2015ec2ee | |
parent | 996219c1c8ecefc63bb00cb7e4f1bd20eb843ce9 (diff) | |
download | mastodon.py-df98fc263e5e4dd80e1ead574fbd4c72e92ee12c.tar.gz |
Auto-add protocol to URLs that do not have one. Fixes #54
-rw-r--r-- | mastodon/Mastodon.py | 10 |
1 files changed, 9 insertions, 1 deletions
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: | |||
44 | 44 | ||
45 | Returns client_id and client_secret. | 45 | Returns client_id and client_secret. |
46 | """ | 46 | """ |
47 | api_base_url = Mastodon.__protocolize(api_base_url) | ||
47 | 48 | ||
48 | request_data = { | 49 | request_data = { |
49 | 'client_name': client_name, | 50 | 'client_name': client_name, |
@@ -95,7 +96,7 @@ class Mastodon: | |||
95 | By default, a timeout of 300 seconds is used for all requests. If you wish to change this, | 96 | By default, a timeout of 300 seconds is used for all requests. If you wish to change this, |
96 | pass the desired timeout (in seconds) as request_timeout. | 97 | pass the desired timeout (in seconds) as request_timeout. |
97 | """ | 98 | """ |
98 | self.api_base_url = api_base_url | 99 | self.api_base_url = Mastodon.__protocolize(api_base_url) |
99 | self.client_id = client_id | 100 | self.client_id = client_id |
100 | self.client_secret = client_secret | 101 | self.client_secret = client_secret |
101 | self.access_token = access_token | 102 | self.access_token = access_token |
@@ -976,6 +977,13 @@ class Mastodon: | |||
976 | """Internal helper for oauth code""" | 977 | """Internal helper for oauth code""" |
977 | self._refresh_token = value | 978 | self._refresh_token = value |
978 | return | 979 | return |
980 | |||
981 | @staticmethod | ||
982 | def __protocolize(base_url): | ||
983 | """Internal add-protocol-to-url helper""" | ||
984 | if not base_url.startswith("http://") and not base_url.startswith("https://"): | ||
985 | base_url = "https://" + base_url | ||
986 | return base_url | ||
979 | 987 | ||
980 | ## | 988 | ## |
981 | # Exceptions | 989 | # Exceptions |