Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Added support to fetch referrers of a given short url or hash
Browse files Browse the repository at this point in the history
  • Loading branch information
phretor committed Sep 15, 2011
1 parent 9c517d9 commit a221b2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bitly_api/bitly_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/test_bitly_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.