Permalink
Browse files

Add git.io service

  • Loading branch information...
1 parent 0f17ca7 commit 4b1e37a58074b848b384a4bebdb1004ad62d9015 @astagi astagi committed Feb 3, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 services/github.py
View
@@ -0,0 +1,17 @@
+## Shorty
+## Copyright 2012 Andrea Stagi
+## See LICENSE
+
+## @url git.io
+class Github(Service):
+
+ def shrink(self, bigurl):
+ gitio_pattern = 'http(s)?://((gist|raw|develop(er)?)\.)?github\.com'
+ gitio_re = re.compile(gitio_pattern)
+ if not gitio_re.search(bigurl):
+ raise ShortyError('URL must match %s' % gitio_pattern)
+ resp = request('http://git.io', post_data="url=%s" % bigurl)
+ for header in resp.info().headers:
+ if header.startswith("Location:"):
+ return header[10:].strip('\n\r')
+ raise ShortyError('Failed to shrink url')

0 comments on commit 4b1e37a

Please sign in to comment.