@@ -56,7 +56,7 @@ def __str__(self):
56
56
return repr (self .reason )
57
57
58
58
"""Do a http request"""
59
- def request (url , parameters = None , username_pass = None ):
59
+ def request (url , parameters = None , username_pass = None , post_data = None ):
60
60
61
61
# build url + parameters
62
62
if parameters :
@@ -72,6 +72,8 @@ def request(url, parameters=None, username_pass=None):
72
72
# send request
73
73
try :
74
74
req = Request (url_params , headers = headers )
75
+ if post_data :
76
+ req .add_data (post_data )
75
77
return urlopen (req )
76
78
except URLError , e :
77
79
raise ShortyError (e )
@@ -96,13 +98,13 @@ def http_error_301(self, req, fp, code, smg, headers):
96
98
"""Base interface that all services implement."""
97
99
class Service (object ):
98
100
99
- def shrink (bigurl ):
101
+ def shrink (self , bigurl ):
100
102
"""Take a big url and make it smaller"""
101
103
102
104
return None
103
105
104
- def expand (tinyurl ):
105
- return None
106
+ def expand (self , tinyurl ):
107
+ return get_redirect ( tinyurl )
106
108
107
109
""" Services """
108
110
@@ -147,9 +149,6 @@ def shrink(self, bigurl):
147
149
resp = request ('http://tinyurl.com/api-create.php' , {'url' : bigurl })
148
150
return resp .read ()
149
151
150
- def expand (self , tinyurl ):
151
- return get_redirect (tinyurl )
152
-
153
152
tinyurl = Tinyurl ()
154
153
155
154
# tr.im
@@ -286,9 +285,6 @@ def shrink(self, bigurl):
286
285
raise ShortyError (turl )
287
286
return turl
288
287
289
- def expand (self , tinyurl ):
290
- return get_redirect (tinyurl )
291
-
292
288
isgd = Isgd ()
293
289
294
290
# cli.gs
@@ -317,6 +313,15 @@ def expand(self, tinyurl):
317
313
318
314
cligs = Cligs ()
319
315
316
+ # tweetburner.com
317
+ class Tweetburner (Service ):
318
+
319
+ def shrink (self , bigurl ):
320
+ resp = request ('http://tweetburner.com/links' , post_data = 'link[url]=%s' % bigurl )
321
+ return resp .read ()
322
+
323
+ tweetburner = Tweetburner ()
324
+
320
325
"""Mapping of domain to service class"""
321
326
services = {
322
327
'sandbox' : sandbox ,
@@ -325,7 +330,8 @@ def expand(self, tinyurl):
325
330
'urlborg.com' : urlborg , 'ub0.cc' : urlborg ,
326
331
'bit.ly' : bitly ,
327
332
'is.gd' : isgd ,
328
- 'cli.gs' : cligs
333
+ 'cli.gs' : cligs ,
334
+ 'tweetburner' : tweetburner , 'twurl.nl' : tweetburner
329
335
}
330
336
331
337
"""
0 commit comments