shortie 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/shortie/base_shortener.rb +4 -2
- data/lib/shortie/service.rb +16 -6
- data/lib/shortie/shorteners/bitly.rb +1 -0
- data/lib/shortie/shorteners/cligs.rb +1 -0
- data/lib/shortie/shorteners/cllk.rb +8 -2
- data/lib/shortie/shorteners/idek.rb +1 -0
- data/lib/shortie/shorteners/isgd.rb +1 -0
- data/lib/shortie/shorteners/rubyurl.rb +1 -0
- data/lib/shortie/shorteners/shortie.rb +1 -0
- data/lib/shortie/shorteners/snim.rb +8 -2
- data/lib/shortie/shorteners/snipr.rb +8 -2
- data/lib/shortie/shorteners/snipurl.rb +3 -2
- data/lib/shortie/shorteners/snurl.rb +8 -2
- data/lib/shortie/shorteners/tinycc.rb +1 -0
- data/lib/shortie/shorteners/tinyurl.rb +1 -0
- data/lib/shortie/shorteners/twurl.rb +1 -0
- data/lib/shortie/shorteners.rb +16 -14
- data/lib/shortie.rb +3 -2
- metadata +9 -21
- data/lib/shortie/services.rb +0 -18
@@ -1,7 +1,8 @@
|
|
1
1
|
module Shortie
|
2
2
|
class BaseShortener
|
3
3
|
attr_accessor :url
|
4
|
-
|
4
|
+
|
5
|
+
# Shortens a url.
|
5
6
|
def self.shorten(url)
|
6
7
|
self.new(url).shorten
|
7
8
|
end
|
@@ -9,7 +10,8 @@ module Shortie
|
|
9
10
|
def initialize(url)
|
10
11
|
self.url = url
|
11
12
|
end
|
12
|
-
|
13
|
+
|
14
|
+
# Shorten method to be called. Must be implemented by classes inheriting this class.
|
13
15
|
def shorten
|
14
16
|
raise "Invalid shortener. It must implement the shorten method."
|
15
17
|
end
|
data/lib/shortie/service.rb
CHANGED
@@ -1,21 +1,31 @@
|
|
1
1
|
module Shortie
|
2
2
|
class Service
|
3
|
+
@@services = []
|
4
|
+
|
5
|
+
# Register a new service by key, name, and shortener, e.g. register("bitly", "bit.ly", Bitly).
|
6
|
+
def self.register(key, name, shortener)
|
7
|
+
@@services << Service.new(key, name, shortener)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get a list of all services.
|
3
11
|
def self.all
|
4
|
-
|
12
|
+
@@services
|
5
13
|
end
|
6
14
|
|
15
|
+
# Find a service by key, e.g. 'bitly'.
|
7
16
|
def self.find_by_key(key)
|
8
|
-
|
17
|
+
@@services.find { |s| s.key == key }
|
9
18
|
end
|
10
19
|
|
11
|
-
attr_accessor :key, :name, :
|
20
|
+
attr_accessor :key, :name, :shortener
|
12
21
|
|
13
|
-
def initialize(key, name,
|
14
|
-
self.key, self.name, self.
|
22
|
+
def initialize(key, name, shortener)
|
23
|
+
self.key, self.name, self.shortener = key, name, shortener
|
15
24
|
end
|
16
25
|
|
26
|
+
# Shorten a URL. This calls the shorten(url) method on the shortener.
|
17
27
|
def shorten(url)
|
18
|
-
|
28
|
+
shortener.shorten(url)
|
19
29
|
end
|
20
30
|
end
|
21
31
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Shortie
|
2
2
|
module Shorteners
|
3
|
-
class Cllk <
|
3
|
+
class Cllk < BaseShortener
|
4
4
|
def shorten
|
5
|
-
|
5
|
+
SimpleHttp.post("http://cl.lk/site/getsnip", {
|
6
|
+
"sniplink" => url,
|
7
|
+
"snipuser" => "lassebunk",
|
8
|
+
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
9
|
+
"snipformat" => "simple"
|
10
|
+
})
|
6
11
|
end
|
7
12
|
end
|
13
|
+
Service.register("cllk", "cl.lk", Cllk)
|
8
14
|
end
|
9
15
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Shortie
|
2
2
|
module Shorteners
|
3
|
-
class Snim <
|
3
|
+
class Snim < BaseShortener
|
4
4
|
def shorten
|
5
|
-
|
5
|
+
SimpleHttp.post("http://sn.im/site/getsnip", {
|
6
|
+
"sniplink" => url,
|
7
|
+
"snipuser" => "lassebunk",
|
8
|
+
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
9
|
+
"snipformat" => "simple"
|
10
|
+
})
|
6
11
|
end
|
7
12
|
end
|
13
|
+
Service.register("snim", "sn.im", Snim)
|
8
14
|
end
|
9
15
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Shortie
|
2
2
|
module Shorteners
|
3
|
-
class Snipr <
|
3
|
+
class Snipr < BaseShortener
|
4
4
|
def shorten
|
5
|
-
|
5
|
+
SimpleHttp.post("http://snipr.com/site/getsnip", {
|
6
|
+
"sniplink" => url,
|
7
|
+
"snipuser" => "lassebunk",
|
8
|
+
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
9
|
+
"snipformat" => "simple"
|
10
|
+
})
|
6
11
|
end
|
7
12
|
end
|
13
|
+
Service.register("snipr", "Snipr", Snipr)
|
8
14
|
end
|
9
15
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Shortie
|
2
2
|
module Shorteners
|
3
3
|
class Snipurl < BaseShortener
|
4
|
-
def shorten
|
5
|
-
SimpleHttp.post("
|
4
|
+
def shorten
|
5
|
+
SimpleHttp.post("http://snipurl.com/site/getsnip", {
|
6
6
|
"sniplink" => url,
|
7
7
|
"snipuser" => "lassebunk",
|
8
8
|
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
@@ -10,5 +10,6 @@ module Shortie
|
|
10
10
|
})
|
11
11
|
end
|
12
12
|
end
|
13
|
+
Service.register("snipurl", "Snipurl", Snipurl)
|
13
14
|
end
|
14
15
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Shortie
|
2
2
|
module Shorteners
|
3
|
-
class Snurl <
|
3
|
+
class Snurl < BaseShortener
|
4
4
|
def shorten
|
5
|
-
|
5
|
+
SimpleHttp.post("http://snurl.com/site/getsnip", {
|
6
|
+
"sniplink" => url,
|
7
|
+
"snipuser" => "lassebunk",
|
8
|
+
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
9
|
+
"snipformat" => "simple"
|
10
|
+
})
|
6
11
|
end
|
7
12
|
end
|
13
|
+
Service.register("snurl", "Snurl", Snurl)
|
8
14
|
end
|
9
15
|
end
|
data/lib/shortie/shorteners.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'shortie/shorteners/
|
4
|
-
require 'shortie/shorteners/
|
5
|
-
require 'shortie/shorteners/
|
6
|
-
require 'shortie/shorteners/
|
7
|
-
require 'shortie/shorteners/
|
8
|
-
require 'shortie/shorteners/
|
9
|
-
require 'shortie/shorteners/
|
10
|
-
require 'shortie/shorteners/
|
11
|
-
require 'shortie/shorteners/
|
12
|
-
require 'shortie/shorteners/
|
13
|
-
require 'shortie/shorteners/
|
14
|
-
require 'shortie/shorteners/
|
1
|
+
Dir["shortie/shorteners/*.rb"].each {|file| require file }
|
2
|
+
|
3
|
+
#require 'shortie/shorteners/snipurl'
|
4
|
+
#require 'shortie/shorteners/bitly'
|
5
|
+
#require 'shortie/shorteners/cligs'
|
6
|
+
#require 'shortie/shorteners/cllk'
|
7
|
+
#require 'shortie/shorteners/idek'
|
8
|
+
#require 'shortie/shorteners/isgd'
|
9
|
+
#require 'shortie/shorteners/rubyurl'
|
10
|
+
#require 'shortie/shorteners/shortie'
|
11
|
+
#require 'shortie/shorteners/snim'
|
12
|
+
#require 'shortie/shorteners/snipr'
|
13
|
+
#require 'shortie/shorteners/snurl'
|
14
|
+
#require 'shortie/shorteners/tinycc'
|
15
|
+
#require 'shortie/shorteners/tinyurl'
|
16
|
+
#require 'shortie/shorteners/twurl'
|
data/lib/shortie.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'shortie/base_shortener'
|
2
2
|
require 'shortie/service'
|
3
|
-
require 'shortie/services'
|
4
3
|
require 'shortie/shorteners'
|
5
4
|
|
6
5
|
require 'rubygems'
|
7
6
|
require 'simplehttp'
|
8
|
-
require 'rexml/document'
|
7
|
+
require 'rexml/document'
|
8
|
+
|
9
|
+
Shortie::Service.all.each { |s| puts s.name }
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shortie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 0.0.2
|
4
|
+
version: 0.0.3
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Lasse Bunk
|
@@ -14,23 +9,19 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-06
|
12
|
+
date: 2010-07-06 00:00:00 +02:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: simplehttp
|
22
|
-
|
23
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 1
|
30
|
-
- 3
|
31
23
|
version: 0.1.3
|
32
|
-
|
33
|
-
version_requirements: *id001
|
24
|
+
version:
|
34
25
|
description: Shortie makes it easy to shorten URLs with any service.
|
35
26
|
email: lassebunk@gmail.com
|
36
27
|
executables: []
|
@@ -42,7 +33,6 @@ extra_rdoc_files: []
|
|
42
33
|
files:
|
43
34
|
- lib/shortie/base_shortener.rb
|
44
35
|
- lib/shortie/service.rb
|
45
|
-
- lib/shortie/services.rb
|
46
36
|
- lib/shortie/shorteners/bitly.rb
|
47
37
|
- lib/shortie/shorteners/cligs.rb
|
48
38
|
- lib/shortie/shorteners/cllk.rb
|
@@ -72,20 +62,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
62
|
requirements:
|
73
63
|
- - ">="
|
74
64
|
- !ruby/object:Gem::Version
|
75
|
-
segments:
|
76
|
-
- 0
|
77
65
|
version: "0"
|
66
|
+
version:
|
78
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
68
|
requirements:
|
80
69
|
- - ">="
|
81
70
|
- !ruby/object:Gem::Version
|
82
|
-
segments:
|
83
|
-
- 0
|
84
71
|
version: "0"
|
72
|
+
version:
|
85
73
|
requirements: []
|
86
74
|
|
87
75
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.3.
|
76
|
+
rubygems_version: 1.3.5
|
89
77
|
signing_key:
|
90
78
|
specification_version: 3
|
91
79
|
summary: Shorten URLs with any service.
|
data/lib/shortie/services.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Shortie
|
2
|
-
SERVICES = [
|
3
|
-
Service.new("bitly", "bit.ly", "Bitly"),
|
4
|
-
Service.new("tinyurl", "TinyURL", "Tinyurl"),
|
5
|
-
Service.new("isgd", "is.gd", "Isgd"),
|
6
|
-
Service.new("cligs", "cli.gs", "Cligs"),
|
7
|
-
Service.new("twurl", "Twurl", "Twurl"),
|
8
|
-
Service.new("snipurl", "Snipurl", "Snipurl"),
|
9
|
-
Service.new("snurl", "Snurl", "Snurl"),
|
10
|
-
Service.new("snipr", "Snipr", "Snipr"),
|
11
|
-
Service.new("snim", "sn.im", "Snim"),
|
12
|
-
Service.new("cllk", "cl.lk", "Cllk"),
|
13
|
-
Service.new("shortie", "short.ie", "Shortie"),
|
14
|
-
Service.new("idek", "idek.net", "Idek"),
|
15
|
-
Service.new("tinycc", "tiny.cc", "Tinycc"),
|
16
|
-
Service.new("rubyurl", "RubyURL", "Rubyurl")
|
17
|
-
]
|
18
|
-
end
|