@@ -47,14 +47,14 @@ def pyeval(code, pastebin=True):
4747# Public API
4848
4949
50- def shorten (url , custom = None , service = DEFAULT_SHORTENER ):
50+ def shorten (url , custom = None , key = None , service = DEFAULT_SHORTENER ):
5151 impl = shorteners [service ]
52- return impl .shorten (url , custom )
52+ return impl .shorten (url , custom , key )
5353
5454
55- def try_shorten (url , custom = None , service = DEFAULT_SHORTENER ):
55+ def try_shorten (url , custom = None , key = None , service = DEFAULT_SHORTENER ):
5656 impl = shorteners [service ]
57- return impl .try_shorten (url , custom )
57+ return impl .try_shorten (url , custom , key )
5858
5959
6060def expand (url , service = None ):
@@ -91,12 +91,12 @@ class Shortener:
9191 def __init__ (self ):
9292 pass
9393
94- def shorten (self , url , custom = None ):
94+ def shorten (self , url , custom = None , key = None ):
9595 return url
9696
97- def try_shorten (self , url , custom = None ):
97+ def try_shorten (self , url , custom = None , key = None ):
9898 try :
99- return self .shorten (url , custom )
99+ return self .shorten (url , custom , key )
100100 except ServiceError :
101101 return url
102102
@@ -138,7 +138,7 @@ def _decorate(impl):
138138
139139@_shortener ('is.gd' )
140140class Isgd (Shortener ):
141- def shorten (self , url , custom = None ):
141+ def shorten (self , url , custom = None , key = None ):
142142 p = {'url' : url , 'shorturl' : custom , 'format' : 'json' }
143143 r = requests .get ('http://is.gd/create.php' , params = p )
144144 j = r .json ()
@@ -161,10 +161,11 @@ def expand(self, url):
161161
162162@_shortener ('goo.gl' )
163163class Googl (Shortener ):
164- def shorten (self , url , custom = None ):
164+ def shorten (self , url , custom = None , key = None ):
165165 h = {'content-type' : 'application/json' }
166+ k = {'key' : key }
166167 p = {'longUrl' : url }
167- r = requests .post ('https://www.googleapis.com/urlshortener/v1/url' , data = json .dumps (p ), headers = h )
168+ r = requests .post ('https://www.googleapis.com/urlshortener/v1/url' , params = k , data = json .dumps (p ), headers = h )
168169 j = r .json ()
169170
170171 if 'error' not in j :
@@ -185,7 +186,7 @@ def expand(self, url):
185186
186187@_shortener ('git.io' )
187188class Gitio (Shortener ):
188- def shorten (self , url , custom = None ):
189+ def shorten (self , url , custom = None , key = None ):
189190 p = {'url' : url , 'code' : custom }
190191 r = requests .post ('http://git.io' , data = p )
191192
0 commit comments