|
|
|
@ -111,8 +111,22 @@ class Shortener:
@@ -111,8 +111,22 @@ class Shortener:
|
|
|
|
|
|
|
|
|
|
self.session, self.proxy = _config_requests(settings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getlink(self, url): |
|
|
|
|
if self.api == 'yourls': |
|
|
|
|
# that is api -> function mapper for running service-related function when getlink() used |
|
|
|
|
servicesList = { |
|
|
|
|
'yourls': self._yourls, |
|
|
|
|
'clckru': self._clckru, |
|
|
|
|
'tinyurl': self._tinyurl, |
|
|
|
|
'isgd': self._gd, |
|
|
|
|
'vgd': self._gd, |
|
|
|
|
'cuttly': self._cuttly |
|
|
|
|
} |
|
|
|
|
# run function selected by choosen API |
|
|
|
|
servicesList[self.api](url) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _yourls(self,url): |
|
|
|
|
request = {'action': 'shorturl', 'format': 'json', 'url': url} |
|
|
|
|
request.update(self.auth_args) |
|
|
|
|
|
|
|
|
@ -143,7 +157,8 @@ class Shortener:
@@ -143,7 +157,8 @@ class Shortener:
|
|
|
|
|
else: |
|
|
|
|
PBinCLIError("YOURLS: No status, statusCode or message fields in response! Received:\n{}".format(response)) |
|
|
|
|
|
|
|
|
|
elif self.api == 'clckru': |
|
|
|
|
|
|
|
|
|
def _clckru(self, url): |
|
|
|
|
request = {'url': url} |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
@ -155,7 +170,8 @@ class Shortener:
@@ -155,7 +170,8 @@ class Shortener:
|
|
|
|
|
except Exception as ex: |
|
|
|
|
PBinCLIError("clck.ru: unexcepted behavior: {}".format(ex)) |
|
|
|
|
|
|
|
|
|
elif self.api == 'tinyurl': |
|
|
|
|
|
|
|
|
|
def _tinyurl(self, url): |
|
|
|
|
request = {'url': url} |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
@ -167,7 +183,8 @@ class Shortener:
@@ -167,7 +183,8 @@ class Shortener:
|
|
|
|
|
except Exception as ex: |
|
|
|
|
PBinCLIError("TinyURL: unexcepted behavior: {}".format(ex)) |
|
|
|
|
|
|
|
|
|
elif self.api == 'isgd' or self.api == 'vgd': |
|
|
|
|
|
|
|
|
|
def _gd(self, url): |
|
|
|
|
request = { |
|
|
|
|
'format': 'json', |
|
|
|
|
'url': url, |
|
|
|
@ -197,7 +214,8 @@ class Shortener:
@@ -197,7 +214,8 @@ class Shortener:
|
|
|
|
|
"is.gd" if self.api == 'isgd' else 'v.gd', |
|
|
|
|
ex)) |
|
|
|
|
|
|
|
|
|
elif self.api == 'cuttly': |
|
|
|
|
|
|
|
|
|
def _cuttly(self, url): |
|
|
|
|
request = { |
|
|
|
|
'url': url, |
|
|
|
|
'domain': 0 |
|
|
|
@ -212,9 +230,9 @@ class Shortener:
@@ -212,9 +230,9 @@ class Shortener:
|
|
|
|
|
except Exception as ex: |
|
|
|
|
PBinCLIError("cutt.ly: unexcepted behavior: {}".format(ex)) |
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
# That code needs testing. API requires username and apiKey or accessToken to work. |
|
|
|
|
elif self.api == 'bitly': |
|
|
|
|
|
|
|
|
|
# [WIP] That code needs testing. API requires username and apiKey or accessToken to work. |
|
|
|
|
def _bitly(self, url): |
|
|
|
|
request = {'url': url} |
|
|
|
|
headers = {'X-Requested-With': 'XMLHttpRequest'} |
|
|
|
|
|
|
|
|
@ -240,4 +258,3 @@ class Shortener:
@@ -240,4 +258,3 @@ class Shortener:
|
|
|
|
|
PBinCLIError("bitly: got error from API: {}".format(friendlyError[errcode])) |
|
|
|
|
except Exception as ex: |
|
|
|
|
PBinCLIError("bitly: unexcepted behavior: {}".format(ex)) |
|
|
|
|
''' |
|
|
|
|