longurl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009, Fabien Jakimowicz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README ADDED
@@ -0,0 +1,40 @@
1
+ == LongURL
2
+
3
+ LongURL expands short urls (tinyurl, is.gd, ...) to original ones, using on LongURL.org, internal resolution or direct resolution
4
+ First, expand will try to expand url using longurl.org service.
5
+ Then, it will try to direct follow redirections on the given url and returns final one.
6
+
7
+ === Options
8
+ * <tt>:cache</tt> : cache object to use, must implement [] and []= functions.
9
+
10
+ === Types
11
+ <tt>url</tt> is expected to be a String and returns a String with the url.
12
+
13
+ === Examples
14
+ # simple expands
15
+ LongURL.expand("http://tinyurl.com/1c2") # => "http://www.google.com"
16
+ LongURL.expand("http://tinyurl.com/blnhsg") # => "http://www.google.com/search?q=number+of+horns+on+a+unicorn&ie=UTF-8"
17
+ LongURL.expand("http://is.gd/iUKg") # => "http://fabien.jakimowicz.com"
18
+
19
+ # not expandable urls, without any http call
20
+ LongURL.expand("http://www.linuxfr.org") # => "http://www.linuxfr.org"
21
+
22
+ # Use MemCache
23
+ LongURL.expand("http://is.gd/iUKg", :cache => MemCache.new("localhost:11211", :namespace => "LongURL"))
24
+ # => "http://fabien.jakimowicz.com"
25
+
26
+ # Expander class
27
+ expander = LongURL::Expander.new
28
+ expander.expand("http://tinyurl.com/1c2") # => "http://www.google.com"
29
+ # not expandable urls, direct resolution only
30
+ expander.direct_resolution("http://www.linuxfr.org") # => "http://www.linuxfr.org/pub"
31
+ # not expandable urls, calling longurl.org only
32
+ expander.expand_with_service_only("http://www.linuxfr.org") # => "http://www.linuxfr.org/pub"
33
+ # ... with MemCache
34
+ expander = LongURL::Expander.new(:cache => MemCache.new("localhost:11211", :namespace => "LongURL"))
35
+ expander.expand("http://tinyurl.com/1c2") # => "http://www.google.com"
36
+
37
+ === Exceptions
38
+ * LongURL::InvalidURL : will occurs if given url is nil, empty or invalid
39
+ * LongURL::NetworkError : a network (timeout, host could be reached, ...) error occurs
40
+ * LongURL::UnknownError : an unknown error occurs
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "longurl"
7
+ s.summary = %q{LongURL expands shorten urls (tinyurl, is.gd, ...)}
8
+ s.homepage = "http://longurl.rubyforge.org"
9
+ s.description = %q{LongURL expands short urls (tinyurl, is.gd, ...) to original ones, using on LongURL.org, internal resolution or direct resolution}
10
+ s.authors = ["Fabien Jakimowicz"]
11
+ s.email = "fabien@jakimowicz.com"
12
+ s.rubyforge_project = 'longurl'
13
+
14
+ s.add_dependency 'json'
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ require 'rake/rdoctask'
21
+ Rake::RDocTask.new do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'longurl'
24
+ rdoc.options << '--line-numbers' << '--inline-source'
25
+ rdoc.rdoc_files.include('README*')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
27
+ end
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib' << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |t|
39
+ t.libs << 'test'
40
+ t.test_files = FileList['test/**/*_test.rb']
41
+ t.verbose = true
42
+ end
43
+ rescue LoadError
44
+ puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+
47
+ task :default => :test
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
2
+ :patch: 1
3
3
  :major: 0
4
4
  :minor: 1
@@ -8,12 +8,14 @@ module LongURL
8
8
  # === Exceptions
9
9
  # * LongURL::NetworkError in case of a network error (timeout, socket error, ...)
10
10
  # * LongURL::InvalidURL in case of a bad url (nil, empty, not http scheme ...)
11
- def self.follow_redirections(orig)
11
+ # * LongURL::TooManyRedirections if there are too many redirection for destination
12
+ def self.follow_redirections(orig, limit = 5)
13
+ raise LongURL::TooManyRedirections if limit == 0
12
14
  uri = LongURL::URL.check(orig)
13
15
  Net::HTTP.start(uri.host, uri.port) do |http|
14
16
  answer = http.get(uri.path.empty? ? '/' : uri.path)
15
17
  dest = answer['Location']
16
- (dest && dest[0, 7] == 'http://' && follow_redirections(dest)) || orig
18
+ (dest && dest[0, 7] == 'http://' && follow_redirections(dest, limit - 1)) || orig
17
19
  end
18
20
  rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
19
21
  raise LongURL::NetworkError
@@ -14,4 +14,8 @@ module LongURL
14
14
  # Raised if a network error occurs : timeout, unreachable network, ...
15
15
  class NetworkError < StandardError
16
16
  end
17
+
18
+ # Raised if there are too many redirection in a direct resolution.
19
+ class TooManyRedirections < StandardError
20
+ end
17
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: longurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien Jakimowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-08 00:00:00 +01:00
12
+ date: 2009-05-04 00:00:00 +02:00
13
13
  default_executable: longurl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,12 +28,15 @@ executables:
28
28
  - longurl
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files: []
32
-
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
33
34
  files:
35
+ - LICENSE
36
+ - Rakefile
34
37
  - VERSION.yml
35
38
  - bin/longurl
36
- - lib/longurl
39
+ - lib/longurl.rb
37
40
  - lib/longurl/constants.rb
38
41
  - lib/longurl/direct.rb
39
42
  - lib/longurl/exceptions.rb
@@ -41,20 +44,18 @@ files:
41
44
  - lib/longurl/expander.rb
42
45
  - lib/longurl/service.rb
43
46
  - lib/longurl/url.rb
44
- - lib/longurl.rb
45
47
  - test/cache_mock.rb
46
48
  - test/constants.rb
47
- - test/service
48
49
  - test/service/no_cache_service_test.rb
49
50
  - test/service/service_cache_test.rb
50
51
  - test/service/service_test.rb
51
52
  - test/service/supported_services_test.rb
52
53
  - test/url_test.rb
54
+ - README
53
55
  has_rdoc: true
54
56
  homepage: http://longurl.rubyforge.org
55
57
  post_install_message:
56
58
  rdoc_options:
57
- - --inline-source
58
59
  - --charset=UTF-8
59
60
  require_paths:
60
61
  - lib
@@ -77,5 +78,11 @@ rubygems_version: 1.3.1
77
78
  signing_key:
78
79
  specification_version: 2
79
80
  summary: LongURL expands shorten urls (tinyurl, is.gd, ...)
80
- test_files: []
81
-
81
+ test_files:
82
+ - test/cache_mock.rb
83
+ - test/constants.rb
84
+ - test/service/no_cache_service_test.rb
85
+ - test/service/service_cache_test.rb
86
+ - test/service/service_test.rb
87
+ - test/service/supported_services_test.rb
88
+ - test/url_test.rb