diff --git a/bitly_api/bitly_api.py b/bitly_api/bitly_api.py index 2a85522..4cb4f4e 100644 --- a/bitly_api/bitly_api.py +++ b/bitly_api/bitly_api.py @@ -714,6 +714,16 @@ def search(self, query, offset=None, cities=None, domain=None, fields=None, data = self._call_oauth2_metrics("v3/search", params, limit=limit) return data['results'] + def custom_keyword(self, keyword_link, target_link, overwrite=False): + """ Save a Custom Bitlink for a custom short domain. + @parameter keyword_link: the Custom Bitlink (short domain and keyword combination) to set + @parameter target_link: the Bitlink the specified keyword will map to (as returned from /v3/shorten) + @parameter overwrite: Optional. true|false. Overwrite existing entry if one exists. Default: false. + """ + params = dict(keyword_link=keyword_link, target_link=target_link, overwrite=overwrite) + data = self._call(self.host, 'v3/user/save_custom_domain_keyword', params, self.secret) + return data['data'] + @classmethod def _generateSignature(self, params, secret): if not params or not secret: diff --git a/test/test_bitly_api.py b/test/test_bitly_api.py index 18f7bfd..00fb7cf 100644 --- a/test/test_bitly_api.py +++ b/test/test_bitly_api.py @@ -8,6 +8,8 @@ """ import os import sys +import random +import string sys.path.append('../') import bitly_api @@ -69,3 +71,16 @@ def testUserInfo(): data = bitly.user_info() assert data is not None assert 'login' in data + +def testCustomKeyword(): + bitly = get_connection() + data = bitly.shorten('http://google.com/') + short_url = data.get("url") + + random_string = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(6)) + custom_url = 'http://bit.ly/Custom%s' % random_string + + new_data = bitly.custom_keyword(custom_url, short_url) + assert new_data is not None + assert new_data['target_link'] == 'http://google.com/' + assert new_data['keyword_link'] == custom_url \ No newline at end of file