shortie 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
- SERVICES
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
- SERVICES.find { |s| s.key == key }
17
+ @@services.find { |s| s.key == key }
9
18
  end
10
19
 
11
- attr_accessor :key, :name, :class_name
20
+ attr_accessor :key, :name, :shortener
12
21
 
13
- def initialize(key, name, class_name)
14
- self.key, self.name, self.class_name = key, name, class_name
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
- eval("Shortie::Shorteners::#{class_name}").shorten(url)
28
+ shortener.shorten(url)
19
29
  end
20
30
  end
21
31
  end
@@ -17,5 +17,6 @@ module Shortie
17
17
  url_element.text
18
18
  end
19
19
  end
20
+ Service.register("bitly", "bit.ly", Bitly)
20
21
  end
21
22
  end
@@ -5,5 +5,6 @@ module Shortie
5
5
  SimpleHttp.get("http://cli.gs/api/v1/cligs/create?url=#{escaped_url}")
6
6
  end
7
7
  end
8
+ Service.register("cligs", "cli.gs", Cligs)
8
9
  end
9
10
  end
@@ -1,9 +1,15 @@
1
1
  module Shortie
2
2
  module Shorteners
3
- class Cllk < Snipurl
3
+ class Cllk < BaseShortener
4
4
  def shorten
5
- super("http://cl.lk")
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
@@ -5,5 +5,6 @@ module Shortie
5
5
  SimpleHttp.get("http://idek.net/shorten/?idek-api=true&idek-url=#{escaped_url}")
6
6
  end
7
7
  end
8
+ Service.register("idek", "idek.net", Idek)
8
9
  end
9
10
  end
@@ -5,5 +5,6 @@ module Shortie
5
5
  SimpleHttp.get("http://is.gd/api.php?longurl=#{escaped_url}")
6
6
  end
7
7
  end
8
+ Service.register("isgd", "is.gd", Isgd)
8
9
  end
9
10
  end
@@ -8,5 +8,6 @@ module Shortie
8
8
  doc.elements["link/permalink"].text
9
9
  end
10
10
  end
11
+ Service.register("rubyurl", "RubyURL", Rubyurl)
11
12
  end
12
13
  end
@@ -11,5 +11,6 @@ module Shortie
11
11
  doc.elements["short/shortened"].text
12
12
  end
13
13
  end
14
+ Service.register("shortie", "short.ie", Shortie)
14
15
  end
15
16
  end
@@ -1,9 +1,15 @@
1
1
  module Shortie
2
2
  module Shorteners
3
- class Snim < Snipurl
3
+ class Snim < BaseShortener
4
4
  def shorten
5
- super("http://sn.im")
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 < Snipurl
3
+ class Snipr < BaseShortener
4
4
  def shorten
5
- super("http://snipr.com")
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(base_path = "http://snipurl.com")
5
- SimpleHttp.post("#{base_path}/site/getsnip", {
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 < Snipurl
3
+ class Snurl < BaseShortener
4
4
  def shorten
5
- super("http://snurl.com")
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
@@ -11,5 +11,6 @@ module Shortie
11
11
  doc.elements["restapi/results/*/shorturl"].text
12
12
  end
13
13
  end
14
+ Service.register("tinycc", "tiny.cc", Tinycc)
14
15
  end
15
16
  end
@@ -5,5 +5,6 @@ module Shortie
5
5
  SimpleHttp.get("http://tinyurl.com/api-create.php?url=#{escaped_url}")
6
6
  end
7
7
  end
8
+ Service.register("tinyurl", "TinyURL", Tinyurl)
8
9
  end
9
10
  end
@@ -5,5 +5,6 @@ module Shortie
5
5
  SimpleHttp.post("http://tweetburner.com/links", "link[url]" => url)
6
6
  end
7
7
  end
8
+ Service.register("twurl", "Twurl", Twurl)
8
9
  end
9
10
  end
@@ -1,14 +1,16 @@
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'
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
- prerelease: false
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-30 00:00:00 +02:00
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
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
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
- type: :runtime
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.6
76
+ rubygems_version: 1.3.5
89
77
  signing_key:
90
78
  specification_version: 3
91
79
  summary: Shorten URLs with any service.
@@ -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