Skip to content

Loading…

adding support for /v3/bitly_pro_domain #7

Merged
merged 1 commit into from

2 participants

@alexlines
  • added one method and a supporting test
@jehiah jehiah merged commit a1746bd into bitly:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 22, 2011
  1. @alexlines
Showing with 36 additions and 0 deletions.
  1. +19 −0 bitly_api/bitly_api.py
  2. +17 −0 test/test_bitly_api.py
View
19 bitly_api/bitly_api.py
@@ -183,6 +183,25 @@ def lookup(self, url):
data = self._call(self.host, 'v3/lookup', params, self.secret)
return data['data']['lookup']
+ def pro_domain(self, domain, format='json'):
+ """ is the domain assigned for bitly.pro? """
+ end_point = 'v3/bitly_pro_domain'
+
+ if not domain:
+ raise BitlyError(500, 'MISSING_ARG_DOMAIN')
+
+ protocol_prefix = ('http://', 'https://')
+ if domain.lower().startswith(protocol_prefix):
+ raise BitlyError(500, 'INVALID_BARE_DOMAIN')
+ params = {
+ 'domain': domain,
+ 'login' : self.login,
+ 'apiKey' : self.api_key,
+ 'format': format,
+ }
+ data = self._call(self.host, end_point, params, self.secret)
+ return data['data']['bitly_pro_domain']
+
@classmethod
def _generateSignature(self, params, secret):
if not params or not secret:
View
17 test/test_bitly_api.py
@@ -25,3 +25,20 @@ def testReferrer():
data = bitly.referrers(hash='a')
assert data != None
assert len(data) > 1
+
+def testProDomain():
+ bitly = bitly_api.Connection('bitlyapidemo','R_0da49e0a9118ff35f52f629d2d71bf07')
+ test_data = {
+ 'cnn.com': False,
+ 'nyti.ms': True,
+ 'g.co': False,
+ 'j.mp': False,
+ 'pep.si': True,
+ 'http://pep.si': 'INVALID_BARE_DOMAIN',
+ }
+ for domain in test_data:
+ try:
+ result = bitly.pro_domain(domain)
+ assert result == test_data[domain], domain
+ except bitly_api.BitlyError, e:
+ assert str(e) == test_data[domain]
Something went wrong with that request. Please try again.