Permalink
Browse files

Added support to fetch referrers of a given short url or hash

  • Loading branch information...
1 parent 9c517d9 commit a221b2d6993b6c51487f7ea7a7631f058cee1fab @phretor phretor committed Sep 15, 2011
Showing with 21 additions and 0 deletions.
  1. +16 −0 bitly_api/bitly_api.py
  2. +5 −0 test/test_bitly_api.py
View
16 bitly_api/bitly_api.py
@@ -103,6 +103,22 @@ def clicks(self, hash=None, shortUrl=None):
data = self._call(self.host, 'v3/clicks', params, self.secret)
return data['data']['clicks']
+
+ def referrers(self, hash=None, shortUrl=None):
+ """ given a bit.ly url or hash, get statistics about the referrers of that link """
+ if not hash and not shortUrl:
+ raise BitlyError(500, 'MISSING_ARG_SHORTURL')
+ params = {
+ 'login' : self.login,
+ 'apiKey' : self.api_key
+ }
+ if hash:
+ params['hash'] = hash
+ if shortUrl:
+ params['shortUrl'] = shortUrl
+
+ data = self._call(self.host, 'v3/referrers', params, self.secret)
+ return data['data']['referrers']
def clicks_by_day(self, hash=None, shortUrl=None):
""" given a bit.ly url or hash, get a time series of clicks
View
5 test/test_bitly_api.py
@@ -20,3 +20,8 @@ def testExpand():
assert len(data) == 1
assert data[0]['error'] == 'NOT_FOUND'
+def testReferrer():
+ bitly = bitly_api.Connection('bitlyapidemo','R_0da49e0a9118ff35f52f629d2d71bf07')
+ data = bitly.referrers(hash='a')
+ assert data != None
+ assert len(data) > 1

0 comments on commit a221b2d

Please sign in to comment.