longurl 0.1.5 → 0.1.6

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/Rakefile CHANGED
@@ -19,7 +19,7 @@ end
19
19
 
20
20
  desc "build rdoc using hanna theme"
21
21
  task :rdoc do
22
- `rm -rf rdoc && rdoc -o rdoc --inline-source --format=html -T hanna README* lib/**/*.rb`
22
+ `rm -rf rdoc && rdoc --op=rdoc --title=LongURL --inline-source --format=darkfish LICENSE README* lib/**/*.rb`
23
23
  end
24
24
 
25
25
  require 'rake/testtask'
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 5
2
+ :patch: 6
3
3
  :major: 0
4
4
  :minor: 1
@@ -19,7 +19,7 @@ module LongURL
19
19
  # e.expand("http://www.linuxfr.org") # => "http://www.linuxfr.org"
20
20
  #
21
21
  # # not expandable urls, calling longurl.org only
22
- # e.expand_with_service_only("http://www.linuxfr.org") # => "http://www.linuxfr.org/pub"
22
+ # e.expand("http://www.linuxfr.org", :direct_resolution => true) # => "http://www.linuxfr.org/pub"
23
23
  #
24
24
  # # not expandable urls, direct resolution only
25
25
  # e.direct_resolution("http://www.linuxfr.org") # => "http://www.linuxfr.org/pub"
@@ -48,11 +48,12 @@ module LongURL
48
48
  @@service = Service.new(:cache => @@cache)
49
49
  end
50
50
 
51
- # Expand given url using LongURL::Service class first and then try a direct_resolution.
52
- def expand(url)
51
+ # Expand given url using LongURL::Service class first and then try a direct_resolution,
52
+ # unless :direct_resolution is set to false in options hash.
53
+ def expand(url, options = {})
53
54
  @@service.query_supported_service_only url
54
55
  rescue UnsupportedService
55
- direct_resolution url
56
+ options[:direct_resolution] == false ? raise(UnsupportedService) : direct_resolution(url)
56
57
  end
57
58
 
58
59
  # Try to directly resolve url using LongURL::Direct to get final redirection.
@@ -66,24 +67,22 @@ module LongURL
66
67
  end
67
68
  end
68
69
 
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)
70
+ # Expand all url in the given string, if an error occurs while expanding url, then the original url is used.
71
+ # <tt>options</tt> accepts same options as expand, see expand for more details.
72
+ def expand_each_in(text, options = {})
71
73
  text.gsub(ShortURLMatchRegexp) do |shorturl|
72
74
  begin
73
- expand shorturl
74
- rescue LongURL::InvalidURL,
75
- LongURL::NetworkError,
76
- LongURL::TooManyRedirections,
77
- LongURL::UnknownError,
75
+ expand shorturl, options
76
+ rescue InvalidURL,
77
+ NetworkError,
78
+ TooManyRedirections,
79
+ UnknownError,
80
+ UnsupportedService,
78
81
  JSON::ParserError
79
82
  shorturl
80
83
  end
81
84
  end
82
- end
85
+ end # expand_each_in
83
86
 
84
- # Expand given url using LongURL::Service only. If given url is not a expandable url, it will still be given to Service.
85
- def expand_with_service_only(url)
86
- @@service.query url
87
- end
88
- end
89
- end
87
+ end # Expander
88
+ end # LongURL
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{longurl}
5
- s.version = "0.1.5"
5
+ s.version = "0.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fabien Jakimowicz"]
9
- s.date = %q{2009-06-13}
9
+ s.date = %q{2009-07-20}
10
10
  s.default_executable = %q{longurl}
11
11
  s.description = %q{LongURL expands short urls (tinyurl, is.gd, ...) to original ones, using on LongURL.org, internal resolution or direct resolution}
12
12
  s.email = %q{fabien@jakimowicz.com}
@@ -22,4 +22,34 @@ class TextExpander < Test::Unit::TestCase
22
22
  assert_equal "Those websites are great: http://www.flickr.com/photos/jakimowicz & http://www.google.com/profiles/fabien.jakimowicz",
23
23
  @expander.expand_each_in("Those websites are great: http://tinyurl.com/r9cm9p & http://is.gd/Bnxy")
24
24
  end
25
+
26
+ def test_expand_each_in_should_not_replace_unexpandable_urls_if_direct_resolution_is_false
27
+ assert_equal "Those websites are great: http://www.flickr.com/photos/jakimowicz & http://www.google.com/profiles/fabien.jakimowicz",
28
+ @expander.expand_each_in( "Those websites are great: http://www.flickr.com/photos/jakimowicz & http://is.gd/Bnxy",
29
+ :direct_resolution => false )
30
+ end
31
+
32
+ def test_expand_should_raise_UnsupportedService_if_service_is_not_supported_and_direct_resolution_disabled
33
+ assert_raise(LongURL::UnsupportedService) do
34
+ @expander.expand("http://www.google.com", :direct_resolution => false)
35
+ end
36
+ end
37
+
38
+ def test_expand_should_use_direct_resolution_by_default
39
+ assert_nothing_raised do
40
+ assert_equal "http://fabien.jakimowicz.com", @expander.expand("http://fabien.jakimowicz.com")
41
+ end
42
+ end
43
+
44
+ def test_expand_should_expand_supported_services
45
+ assert_equal "http://www.flickr.com/photos/jakimowicz", @expander.expand('http://tinyurl.com/r9cm9p')
46
+ end
47
+
48
+ def test_expand_should_handle_direct_resolution_if_asked
49
+ assert_equal "http://fabien.jakimowicz.com", @expander.expand("http://fabien.jakimowicz.com", :direct_resolution => true)
50
+ end
51
+
52
+ def test_expand_with_should_continue_to_resolve_urls_even_if_direct_resolution_is_true
53
+ assert_equal "http://www.flickr.com/photos/jakimowicz", @expander.expand('http://tinyurl.com/r9cm9p', :direct_resolution => true)
54
+ end
25
55
  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.5
4
+ version: 0.1.6
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-06-13 00:00:00 +02:00
12
+ date: 2009-10-30 00:00:00 +01:00
13
13
  default_executable: longurl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,8 @@ files:
59
59
  - test/url_test.rb
60
60
  has_rdoc: true
61
61
  homepage: http://longurl.rubyforge.org
62
+ licenses: []
63
+
62
64
  post_install_message:
63
65
  rdoc_options:
64
66
  - --charset=UTF-8
@@ -79,9 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
81
  requirements: []
80
82
 
81
83
  rubyforge_project: longurl
82
- rubygems_version: 1.3.1
84
+ rubygems_version: 1.3.5
83
85
  signing_key:
84
- specification_version: 2
86
+ specification_version: 3
85
87
  summary: LongURL expands shorten urls (tinyurl, is.gd, ...)
86
88
  test_files:
87
89
  - test/cache_mock.rb