Skip to content

Commit 4b1e37a

Browse files
committed
Add git.io service
1 parent 0f17ca7 commit 4b1e37a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

services/github.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Shorty
2+
## Copyright 2012 Andrea Stagi
3+
## See LICENSE
4+
5+
## @url git.io
6+
class Github(Service):
7+
8+
def shrink(self, bigurl):
9+
gitio_pattern = 'http(s)?://((gist|raw|develop(er)?)\.)?github\.com'
10+
gitio_re = re.compile(gitio_pattern)
11+
if not gitio_re.search(bigurl):
12+
raise ShortyError('URL must match %s' % gitio_pattern)
13+
resp = request('http://git.io', post_data="url=%s" % bigurl)
14+
for header in resp.info().headers:
15+
if header.startswith("Location:"):
16+
return header[10:].strip('\n\r')
17+
raise ShortyError('Failed to shrink url')

0 commit comments

Comments
 (0)