Skip to content

Commit 420da36

Browse files
committed
Updated goo.gl service
1 parent 4b1e37a commit 420da36

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __str__(self):
1313
return repr(self.reason)
1414

1515
"""Do a http request"""
16-
def request(url, parameters=None, username_pass=None, post_data=None):
16+
def request(url, parameters=None, username_pass=None, post_data=None, headers={}):
1717

1818
# build url + parameters
1919
if parameters:
@@ -22,7 +22,6 @@ def request(url, parameters=None, username_pass=None, post_data=None):
2222
url_params = url
2323

2424
# if username and pass supplied, build basic auth header
25-
headers = {}
2625
if username_pass:
2726
headers['Authorization'] = 'Basic %s' % base64.b64encode('%s:%s' % username_pass)
2827

services/google.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
class Google(Service):
77

88
def shrink(self, bigurl):
9-
resp = request('http://goo.gl/api/url', {'url': bigurl}, post_data = 'toolbar')
9+
resp = request('https://www.googleapis.com/urlshortener/v1/url',
10+
headers={"content-type":"application/json"},
11+
post_data=json.dumps({"longUrl": bigurl}))
1012
data = resp.read()
1113
jdata = json.loads(data)
12-
if 'short_url' not in jdata:
14+
if 'id' not in jdata:
1315
raise ShortyError(data)
1416
else:
15-
return jdata['short_url']
17+
return jdata['id']
1618

1719
def qrcode(self, tinyurl):
1820
qrdata = request(tinyurl + '.qr').read()

0 commit comments

Comments
 (0)