Skip to content

Commit 04ed0a4

Browse files
committed
Implemented snipurl.com service.
1 parent e04588a commit 04ed0a4

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Supported URL shortening services for shrinking long urls:
2020
tinyurl.com burnurl.com
2121
tr.im hurl.ws
2222
urlborg.com xr.com
23-
bit.ly
23+
bit.ly snipurl.com
2424
is.gd
2525
cli.gs
2626
twurl.nl (tweetburner)

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
API available and ready to go!
22
++++++++++++++++++++++++++++++
33
+ u.mavrev.com
4-
+ snipr.com/snipurl.com/sn.im
54
+ adjix.com
65
+ metamark.net (xrl.us)
76
+ idek.net

services/snipurl.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Shorty
2+
## Copyright 2009 Joshua Roesslein
3+
## See LICENSE
4+
5+
## @url snipurl.com snipr.com sn.im snurl.com
6+
class Snipurl(Service):
7+
8+
def __init__(self, user=None, apikey=None):
9+
self.user = user
10+
self.apikey = apikey
11+
12+
def _test(self):
13+
# prompt for username and apikey
14+
self.user = raw_input('snipurl username: ')
15+
self.apikey = raw_input('snipurl apikey: ')
16+
Service._test(self)
17+
18+
def shrink(self, bigurl, custom=None, title=None, private_key=None,
19+
owner=None, include_private_key=False):
20+
if self.user is None or self.apikey is None:
21+
raise ShortyError('Must set an user and apikey')
22+
parameters = {
23+
'sniplink': bigurl,
24+
'snipuser': self.user,
25+
'snipapi': self.apikey,
26+
'snipformat': 'simple'
27+
}
28+
if custom:
29+
parameters['snipnick'] = custom
30+
if title:
31+
parameters['sniptitle'] = title
32+
if private_key:
33+
parameters['snippk'] = private_key
34+
if owner:
35+
parameters['snipowner'] = owner
36+
if include_private_key:
37+
parameters['snipformat_includepk'] = 'Y'
38+
resp = request('http://snipurl.com/site/getsnip',
39+
post_data=urlencode(parameters))
40+
return resp.read()
41+
42+
def expand(self, tinyurl):
43+
# TODO: fetch detailed info
44+
url = Service.expand(self, tinyurl)
45+
if url.startswith('http'):
46+
return url
47+
else:
48+
raise ShortyError('Invalid url')
49+

shorty.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,53 @@ def expand(self, tinyurl):
712712

713713
sandbox = Sandbox()
714714

715+
# snipurl
716+
class Snipurl(Service):
717+
718+
def __init__(self, user=None, apikey=None):
719+
self.user = user
720+
self.apikey = apikey
721+
722+
def _test(self):
723+
# prompt for username and apikey
724+
self.user = raw_input('snipurl username: ')
725+
self.apikey = raw_input('snipurl apikey: ')
726+
Service._test(self)
727+
728+
def shrink(self, bigurl, custom=None, title=None, private_key=None,
729+
owner=None, include_private_key=False):
730+
if self.user is None or self.apikey is None:
731+
raise ShortyError('Must set an user and apikey')
732+
parameters = {
733+
'sniplink': bigurl,
734+
'snipuser': self.user,
735+
'snipapi': self.apikey,
736+
'snipformat': 'simple'
737+
}
738+
if custom:
739+
parameters['snipnick'] = custom
740+
if title:
741+
parameters['sniptitle'] = title
742+
if private_key:
743+
parameters['snippk'] = private_key
744+
if owner:
745+
parameters['snipowner'] = owner
746+
if include_private_key:
747+
parameters['snipformat_includepk'] = 'Y'
748+
resp = request('http://snipurl.com/site/getsnip',
749+
post_data=urlencode(parameters))
750+
return resp.read()
751+
752+
def expand(self, tinyurl):
753+
# TODO: fetch detailed info
754+
url = Service.expand(self, tinyurl)
755+
if url.startswith('http'):
756+
return url
757+
else:
758+
raise ShortyError('Invalid url')
759+
760+
snipurl = Snipurl()
761+
715762
# tinyurl
716763
class Tinyurl(Service):
717764

@@ -746,6 +793,7 @@ def expand(self, tinyurl):
746793
bukme = Bukme()
747794

748795
services = {
796+
'snipr.com': snipurl,
749797
'chilp.it': chilpit,
750798
'bit.ly': bitly,
751799
'short.to': shortto,
@@ -754,6 +802,7 @@ def expand(self, tinyurl):
754802
'buk.me': bukme,
755803
'fon.gs': fongs,
756804
'ub0.cc': urlborg,
805+
'snurl.com': snipurl,
757806
'fwd4.me': fwd4me,
758807
'xr.com': xr,
759808
'short.ie': shortie,
@@ -768,8 +817,10 @@ def expand(self, tinyurl):
768817
'cli.gs': cligs,
769818
'urlborg.com': urlborg,
770819
'is.gd': isgd,
820+
'sn.im': snipurl,
771821
'tweetburner.com': tweetburner,
772822
'x.bb': xr,
773823
'tinyurl.com': tinyurl,
824+
'snipurl.com': snipurl,
774825
}
775826

0 commit comments

Comments
 (0)