Skip to content

Commit 98ce28a

Browse files
committed
Implemented fwd4.me service. Few fixes to fon.gs service.
1 parent 2535ded commit 98ce28a

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Supported URL shortening services for shrinking long urls:
2121
a.gd
2222
buk.me
2323
fon.gs
24+
fwd4.me
2425

2526
Shorty can expand any url service by getting the redirect
2627
location by requesting the tiny url.

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
+ burnurl.com
22
+ chilp.it
3-
+ fwd4.me

shorty.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def expand(self, tinyurl):
406406

407407
bukme = Bukme()
408408

409+
# fon.gs
409410
class Fongs(Service):
410411

411412
def shrink(self, bigurl, tag=None):
@@ -433,15 +434,37 @@ def check(self, tag):
433434
else:
434435
raise ShortyError(data)
435436

436-
def expand(self, bigurl):
437-
if bigurl[-1] != '/':
438-
burl = bigurl + '/'
437+
def expand(self, tinyurl):
438+
if tinyurl[-1] != '/':
439+
turl = tinyurl + '/'
439440
else:
440-
burl = bigurl
441-
return Service.expand(self, burl)
441+
turl = tinyurl
442+
return Service.expand(self, turl)
442443

443444
fongs = Fongs()
444445

446+
# fwd4.me
447+
class Fwd4me(Service):
448+
449+
ecodes = {
450+
'1': 'Invalid long url',
451+
'2': 'Invalid api key',
452+
'3': 'Account suspended or revoked',
453+
'4': 'Long url is black listed',
454+
'5': 'Internal system error'
455+
}
456+
457+
def shrink(self, bigurl):
458+
resp = request('http://api.fwd4.me/', {'url': bigurl})
459+
data = resp.read()
460+
if data.startswith('ERROR:'):
461+
ecode = data.lstrip('ERROR:')
462+
raise ShortyError(Fwd4me.ecodes.get(ecode, 'Unkown error'))
463+
else:
464+
return data
465+
466+
fwd4me = Fwd4me()
467+
445468
"""Mapping of domain to service class"""
446469
services = {
447470
'sandbox': sandbox,
@@ -455,7 +478,8 @@ def expand(self, bigurl):
455478
'digg.com': digg,
456479
'a.gd': agd,
457480
'buk.me': bukme,
458-
'fon.gs': fongs
481+
'fon.gs': fongs,
482+
'fwd4.me': fwd4me
459483
}
460484

461485
"""

0 commit comments

Comments
 (0)