longurl 0.1.1 → 0.1.2

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.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ doc
3
+ pkg
4
+ rdoc
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009, Fabien Jakimowicz
1
+ Copyright (c) 2009, Fabien Jakimowicz <fabien@jakimowicz.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
@@ -0,0 +1,13 @@
1
+ bin/longurl
2
+ ChangeLog
3
+ lib/longurl/constants.rb
4
+ lib/longurl/direct.rb
5
+ lib/longurl/exceptions.rb
6
+ lib/longurl/service.rb
7
+ lib/longurl.rb
8
+ LICENSE
9
+ longurl.gemspec
10
+ Manifest
11
+ Rakefile
12
+ README
13
+ TODO
@@ -1,9 +1,11 @@
1
- == LongURL
1
+ = LongURL
2
2
 
3
+ == DESCRIPTION
3
4
  LongURL expands short urls (tinyurl, is.gd, ...) to original ones, using on LongURL.org, internal resolution or direct resolution
4
5
  First, expand will try to expand url using longurl.org service.
5
6
  Then, it will try to direct follow redirections on the given url and returns final one.
6
7
 
8
+ == SYNOPSIS
7
9
  === Options
8
10
  * <tt>:cache</tt> : cache object to use, must implement [] and []= functions.
9
11
 
@@ -37,4 +39,35 @@ Then, it will try to direct follow redirections on the given url and returns fin
37
39
  === Exceptions
38
40
  * LongURL::InvalidURL : will occurs if given url is nil, empty or invalid
39
41
  * LongURL::NetworkError : a network (timeout, host could be reached, ...) error occurs
40
- * LongURL::UnknownError : an unknown error occurs
42
+ * LongURL::UnknownError : an unknown error occurs
43
+
44
+ == REQUIREMENTS
45
+
46
+ * json gem
47
+
48
+ == INSTALL
49
+ gem install longurl
50
+
51
+ == LICENSE
52
+
53
+ (The MIT License)
54
+
55
+ Copyright (c) 2009, Fabien Jakimowicz <fabien@jakimowicz.com>
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
58
+ this software and associated documentation files (the "Software"), to deal in
59
+ the Software without restriction, including without limitation the rights to
60
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
61
+ of the Software, and to permit persons to whom the Software is furnished to do
62
+ so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in all
65
+ copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ SOFTWARE.
data/Rakefile CHANGED
@@ -44,4 +44,31 @@ rescue LoadError
44
44
  puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
45
  end
46
46
 
47
- task :default => :test
47
+ # Rubyforge publishing
48
+ begin
49
+ require 'rake/contrib/sshpublisher'
50
+ namespace :rubyforge do
51
+
52
+ desc "Release gem and RDoc documentation to RubyForge"
53
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
54
+
55
+ namespace :release do
56
+ desc "Publish RDoc to RubyForge."
57
+ task :docs => [:rdoc] do
58
+ config = YAML.load(
59
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
60
+ )
61
+
62
+ host = "#{config['username']}@rubyforge.org"
63
+ remote_dir = "/var/www/gforge-projects/longurl/"
64
+ local_dir = 'rdoc'
65
+
66
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
67
+ end
68
+ end
69
+ end
70
+ rescue LoadError
71
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
72
+ end
73
+
74
+ task :default => :test
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ * add a cache to avoid multiple calls for same url
2
+ * cache could be : hash, memcache, ...
3
+ * handle http errors
4
+ * handle json parsing errors
5
+ * handle ServiceUnknown exception
6
+ * possible infinite loop in Direct::follow_redirections
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
3
2
  :major: 0
4
3
  :minor: 1
4
+ :patch: 2
@@ -1,6 +1,9 @@
1
1
  require "uri"
2
2
 
3
3
  module LongURL
4
+ ShortURLMatchRegexp = /http:\/\/[\/\-_.a-z0-9]+/im
5
+
6
+ # Urls for longurl
4
7
  EndPoint = URI.parse("http://api.longurl.org/v1/expand")
5
8
  ServiceEndPoint = URI.parse("http://api.longurl.org/v1/services")
6
9
  end
@@ -66,6 +66,21 @@ module LongURL
66
66
  end
67
67
  end
68
68
 
69
+ # Expand all url in the given string, if an error occurs while expanding url, then the original url is used
70
+ def expand_each_in(text)
71
+ text.gsub(ShortURLMatchRegexp) do |shorturl|
72
+ begin
73
+ expand shorturl
74
+ rescue LongURL::InvalidURL,
75
+ LongURL::NetworkError,
76
+ LongURL::TooManyRedirections,
77
+ LongURL::UnknownError,
78
+ JSON::ParserError
79
+ shorturl
80
+ end
81
+ end
82
+ end
83
+
69
84
  # Expand given url using LongURL::Service only. If given url is not a expandable url, it will still be given to Service.
70
85
  def expand_with_service_only(url)
71
86
  @@service.query url
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{longurl}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Fabien Jakimowicz"]
9
+ s.date = %q{2009-05-19}
10
+ s.default_executable = %q{longurl}
11
+ s.description = %q{LongURL expands short urls (tinyurl, is.gd, ...) to original ones, using on LongURL.org, internal resolution or direct resolution}
12
+ s.email = %q{fabien@jakimowicz.com}
13
+ s.executables = ["longurl"]
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "Manifest",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "TODO",
25
+ "VERSION.yml",
26
+ "bin/longurl",
27
+ "lib/longurl.rb",
28
+ "lib/longurl/constants.rb",
29
+ "lib/longurl/direct.rb",
30
+ "lib/longurl/exceptions.rb",
31
+ "lib/longurl/expand.rb",
32
+ "lib/longurl/expander.rb",
33
+ "lib/longurl/service.rb",
34
+ "lib/longurl/url.rb",
35
+ "longurl.gemspec",
36
+ "test/cache_mock.rb",
37
+ "test/constants.rb",
38
+ "test/expander_test.rb",
39
+ "test/service/no_cache_service_test.rb",
40
+ "test/service/service_cache_test.rb",
41
+ "test/service/service_test.rb",
42
+ "test/service/supported_services_test.rb",
43
+ "test/url_test.rb"
44
+ ]
45
+ s.has_rdoc = true
46
+ s.homepage = %q{http://longurl.rubyforge.org}
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.require_paths = ["lib"]
49
+ s.rubyforge_project = %q{longurl}
50
+ s.rubygems_version = %q{1.3.1}
51
+ s.summary = %q{LongURL expands shorten urls (tinyurl, is.gd, ...)}
52
+ s.test_files = [
53
+ "test/cache_mock.rb",
54
+ "test/constants.rb",
55
+ "test/expander_test.rb",
56
+ "test/service/no_cache_service_test.rb",
57
+ "test/service/service_cache_test.rb",
58
+ "test/service/service_test.rb",
59
+ "test/service/supported_services_test.rb",
60
+ "test/url_test.rb"
61
+ ]
62
+
63
+ if s.respond_to? :specification_version then
64
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
+ s.specification_version = 2
66
+
67
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<json>, [">= 0"])
69
+ else
70
+ s.add_dependency(%q<json>, [">= 0"])
71
+ end
72
+ else
73
+ s.add_dependency(%q<json>, [">= 0"])
74
+ end
75
+ end
@@ -6,5 +6,9 @@ ShortToLong = {
6
6
  :is_gd => {
7
7
  "http://is.gd/iUKg" => "http://fabien.jakimowicz.com",
8
8
  "http://is.gd/iYCo" => "http://www.google.com/search?q=number+of+horns+on+a+unicorn&ie=UTF-8"
9
+ },
10
+ :friendfeed => {
11
+ "http://ff.im/-31OFh" => "http://en.wikipedia.org/wiki/Product_requirements_document",
12
+ "http://ff.im/-31MWm" => "http://www.infrasystems.com/how-to-write-an-mrd.html"
9
13
  }
10
14
  }
@@ -0,0 +1,25 @@
1
+ $test_lib_dir = File.join(File.dirname(__FILE__), "..", "lib")
2
+ $:.unshift($test_lib_dir)
3
+
4
+ require "test/unit"
5
+ require "longurl/expander"
6
+
7
+ class TextExpander < Test::Unit::TestCase
8
+ def setup
9
+ @expander = LongURL::Expander.new
10
+ end
11
+
12
+ def test_expand_each_in_should_expand_friendfeed_urls
13
+ assert_equal "Product requirements document - Wikipedia, http://en.wikipedia.org/wiki/Product_requirements_document the free encyclopedia",
14
+ @expander.expand_each_in("Product requirements document - Wikipedia, http://ff.im/-31OFh the free encyclopedia")
15
+ end
16
+
17
+ def test_expand_each_in_should_not_change_strings_with_no_urls
18
+ assert_equal "i'm not to be changed !!!", @expander.expand_each_in("i'm not to be changed !!!")
19
+ end
20
+
21
+ def test_expand_each_in_should_be_able_to_expand_multiple_urls
22
+ assert_equal "Those websites are great: http://www.flickr.com/photos/jakimowicz & http://www.google.com/profiles/fabien.jakimowicz",
23
+ @expander.expand_each_in("Those websites are great: http://tinyurl.com/r9cm9p & http://is.gd/Bnxy")
24
+ end
25
+ end
@@ -2,7 +2,6 @@ $test_lib_dir = File.join(File.dirname(__FILE__), "..", "lib")
2
2
  $:.unshift($test_lib_dir)
3
3
 
4
4
  require "test/unit"
5
- require "constants"
6
5
  require "longurl/exceptions"
7
6
  require "longurl/service"
8
7
 
@@ -17,9 +17,10 @@ class TestURL < Test::Unit::TestCase
17
17
  "bleh://asfd.com",
18
18
  "ftp://asdf.com",
19
19
  "google.com",
20
- "asdf@toto.com"]
20
+ "asdf@toto.com",
21
+ "httpd://asdf.com"]
21
22
 
22
- GoodURL = "http://www.google.com"
23
+ GoodURLs = ["http://www.google.com", "https://rubyonrails.org"]
23
24
 
24
25
  def test_check_should_raise_invalid_url_if_url_is_nil
25
26
  assert_raise(LongURL::InvalidURL) { LongURL::URL.check nil }
@@ -38,6 +39,6 @@ class TestURL < Test::Unit::TestCase
38
39
  end
39
40
 
40
41
  def test_check_should_returns_parsed_url_on_success
41
- assert_equal URI.parse(GoodURL), LongURL::URL.check(GoodURL)
42
+ GoodURLs.each {|good_url| assert_equal URI.parse(good_url), LongURL::URL.check(good_url)}
42
43
  end
43
44
  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.1
4
+ version: 0.1.2
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-05-04 00:00:00 +02:00
12
+ date: 2009-05-19 00:00:00 +02:00
13
13
  default_executable: longurl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,10 +30,14 @@ extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
32
  - LICENSE
33
- - README
33
+ - README.rdoc
34
34
  files:
35
+ - .gitignore
35
36
  - LICENSE
37
+ - Manifest
38
+ - README.rdoc
36
39
  - Rakefile
40
+ - TODO
37
41
  - VERSION.yml
38
42
  - bin/longurl
39
43
  - lib/longurl.rb
@@ -44,14 +48,15 @@ files:
44
48
  - lib/longurl/expander.rb
45
49
  - lib/longurl/service.rb
46
50
  - lib/longurl/url.rb
51
+ - longurl.gemspec
47
52
  - test/cache_mock.rb
48
53
  - test/constants.rb
54
+ - test/expander_test.rb
49
55
  - test/service/no_cache_service_test.rb
50
56
  - test/service/service_cache_test.rb
51
57
  - test/service/service_test.rb
52
58
  - test/service/supported_services_test.rb
53
59
  - test/url_test.rb
54
- - README
55
60
  has_rdoc: true
56
61
  homepage: http://longurl.rubyforge.org
57
62
  post_install_message:
@@ -81,6 +86,7 @@ summary: LongURL expands shorten urls (tinyurl, is.gd, ...)
81
86
  test_files:
82
87
  - test/cache_mock.rb
83
88
  - test/constants.rb
89
+ - test/expander_test.rb
84
90
  - test/service/no_cache_service_test.rb
85
91
  - test/service/service_cache_test.rb
86
92
  - test/service/service_test.rb