shortie 0.0.1
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 +23 -0
- data/lib/shortie/service.rb +21 -0
- data/lib/shortie/services.rb +18 -0
- data/lib/shortie/shorteners/bitly.rb +21 -0
- data/lib/shortie/shorteners/cligs.rb +9 -0
- data/lib/shortie/shorteners/cllk.rb +9 -0
- data/lib/shortie/shorteners/idek.rb +9 -0
- data/lib/shortie/shorteners/isgd.rb +9 -0
- data/lib/shortie/shorteners/rubyurl.rb +12 -0
- data/lib/shortie/shorteners/shortie.rb +15 -0
- data/lib/shortie/shorteners/snim.rb +9 -0
- data/lib/shortie/shorteners/snipr.rb +9 -0
- data/lib/shortie/shorteners/snipurl.rb +14 -0
- data/lib/shortie/shorteners/snurl.rb +9 -0
- data/lib/shortie/shorteners/tinycc.rb +15 -0
- data/lib/shortie/shorteners/tinyurl.rb +9 -0
- data/lib/shortie/shorteners/twurl.rb +9 -0
- data/lib/shortie/shorteners.rb +14 -0
- data/lib/shortie.rb +10 -0
- metadata +93 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shortie
|
2
|
+
class BaseShortener
|
3
|
+
attr_accessor :url
|
4
|
+
|
5
|
+
def self.shorten(url)
|
6
|
+
self.new(url).shorten
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
self.url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def shorten
|
14
|
+
raise "Invalid shortener. It must implement the shorten method."
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def escaped_url
|
20
|
+
CGI::escape(url)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shortie
|
2
|
+
class Service
|
3
|
+
def self.all
|
4
|
+
SERVICES
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.find_by_key(key)
|
8
|
+
SERVICES.find { |s| s.key == key }
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :key, :name, :class_name
|
12
|
+
|
13
|
+
def initialize(key, name, class_name)
|
14
|
+
self.key, self.name, self.class_name = key, name, class_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def shorten(url)
|
18
|
+
eval("Shortie::Shorteners::#{class_name}").shorten(url)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shortie
|
2
|
+
module Shorteners
|
3
|
+
class Bitly < BaseShortener
|
4
|
+
def shorten
|
5
|
+
xml = SimpleHttp.get("http://api.bit.ly/v3/shorten?login=lassebunk&apiKey=R_f7df445f30899b8aec8ad5af7c732f0b&longUrl=#{escaped_url}&format=xml")
|
6
|
+
doc = REXML::Document.new(xml)
|
7
|
+
|
8
|
+
status_element = doc.elements["response/status_txt"]
|
9
|
+
raise "No status text (status_txt) returned from bit.ly." if status_element.nil?
|
10
|
+
|
11
|
+
status = status_element.text
|
12
|
+
raise status unless status == "OK"
|
13
|
+
|
14
|
+
url_element = doc.elements["response/data/url"]
|
15
|
+
raise "No URL returned from bit.ly." if url_element.nil?
|
16
|
+
|
17
|
+
url_element.text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Shortie
|
2
|
+
module Shorteners
|
3
|
+
class Rubyurl < BaseShortener
|
4
|
+
def shorten
|
5
|
+
xml = SimpleHttp.post("http://rubyurl.com/api/links", "website_url" => url)
|
6
|
+
doc = REXML::Document.new(xml)
|
7
|
+
|
8
|
+
doc.elements["link/permalink"].text
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shortie
|
2
|
+
module Shorteners
|
3
|
+
class Shortie < BaseShortener
|
4
|
+
def shorten
|
5
|
+
xml = SimpleHttp.get("http://short.ie/api?url=#{escaped_url}&format=xml")
|
6
|
+
doc = REXML::Document.new(xml)
|
7
|
+
|
8
|
+
error_msg = doc.elements["short/error/msg"]
|
9
|
+
raise error_msg.text if error_msg
|
10
|
+
|
11
|
+
doc.elements["short/shortened"].text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Shortie
|
2
|
+
module Shorteners
|
3
|
+
class Snipurl < BaseShortener
|
4
|
+
def shorten(base_path = "http://snipurl.com")
|
5
|
+
SimpleHttp.post("#{base_path}/site/getsnip", {
|
6
|
+
"sniplink" => url,
|
7
|
+
"snipuser" => "lassebunk",
|
8
|
+
"snipapi" => "55656c5bbaf92f859aa657be1482fc3a",
|
9
|
+
"snipformat" => "simple"
|
10
|
+
})
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shortie
|
2
|
+
module Shorteners
|
3
|
+
class Tinycc < BaseShortener
|
4
|
+
def shorten
|
5
|
+
xml = SimpleHttp.get("http://tiny.cc/?c=rest_api&m=shorten&version=2.0.1&format=xml&longUrl=#{escaped_url}&login=lassebunk&apiKey=7ec76292-2999-48ab-ad8a-91798282ad59")
|
6
|
+
doc = REXML::Document.new(xml)
|
7
|
+
|
8
|
+
error_msg = doc.elements["restapi/errorMessage"]
|
9
|
+
raise error_msg.text unless error_msg.text.nil?
|
10
|
+
|
11
|
+
doc.elements["restapi/results/*/shorturl"].text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'shortie/shorteners/snipurl'
|
2
|
+
require 'shortie/shorteners/bitly'
|
3
|
+
require 'shortie/shorteners/cligs'
|
4
|
+
require 'shortie/shorteners/cllk'
|
5
|
+
require 'shortie/shorteners/idek'
|
6
|
+
require 'shortie/shorteners/isgd'
|
7
|
+
require 'shortie/shorteners/rubyurl'
|
8
|
+
require 'shortie/shorteners/shortie'
|
9
|
+
require 'shortie/shorteners/snim'
|
10
|
+
require 'shortie/shorteners/snipr'
|
11
|
+
require 'shortie/shorteners/snurl'
|
12
|
+
require 'shortie/shorteners/tinycc'
|
13
|
+
require 'shortie/shorteners/tinyurl'
|
14
|
+
require 'shortie/shorteners/twurl'
|
data/lib/shortie.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'shortie/base_shortener'
|
2
|
+
require 'shortie/service'
|
3
|
+
require 'shortie/services'
|
4
|
+
require 'shortie/shorteners'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'simplehttp'
|
8
|
+
require 'rexml/document'
|
9
|
+
|
10
|
+
puts Shortie::Service.all.first.shorten("http://www.saxo.com")
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shortie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Lasse Bunk
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-30 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: simplehttp
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
- 3
|
31
|
+
version: 0.1.3
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Shortie makes it easy to shorten URLs with any service.
|
35
|
+
email: lassebunk@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- lib/shortie/base_shortener.rb
|
44
|
+
- lib/shortie/service.rb
|
45
|
+
- lib/shortie/services.rb
|
46
|
+
- lib/shortie/shorteners/bitly.rb
|
47
|
+
- lib/shortie/shorteners/cligs.rb
|
48
|
+
- lib/shortie/shorteners/cllk.rb
|
49
|
+
- lib/shortie/shorteners/idek.rb
|
50
|
+
- lib/shortie/shorteners/isgd.rb
|
51
|
+
- lib/shortie/shorteners/rubyurl.rb
|
52
|
+
- lib/shortie/shorteners/shortie.rb
|
53
|
+
- lib/shortie/shorteners/snim.rb
|
54
|
+
- lib/shortie/shorteners/snipr.rb
|
55
|
+
- lib/shortie/shorteners/snipurl.rb
|
56
|
+
- lib/shortie/shorteners/snurl.rb
|
57
|
+
- lib/shortie/shorteners/tinycc.rb
|
58
|
+
- lib/shortie/shorteners/tinyurl.rb
|
59
|
+
- lib/shortie/shorteners/twurl.rb
|
60
|
+
- lib/shortie/shorteners.rb
|
61
|
+
- lib/shortie.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/lassebunk/shortie
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Shorten URLs with any service.
|
92
|
+
test_files: []
|
93
|
+
|