hugeurl 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/bin/hugeurl +1 -1
- data/examples/example.rb +7 -1
- data/lib/hugeurl.rb +10 -1
- data/test/test_helper.rb +1 -1
- data/test/test_hugeurl.rb +4 -0
- metadata +2 -2
data/History.txt
CHANGED
data/bin/hugeurl
CHANGED
data/examples/example.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hugeurl'
|
3
6
|
|
4
7
|
puts tinyurl = "http://tinyurl.com/242tthb"
|
5
8
|
puts " => " + Hugeurl.get(tinyurl).to_s
|
@@ -13,3 +16,6 @@ puts " => #{tco.to_huge}"
|
|
13
16
|
|
14
17
|
puts gyamp = URI.parse("http://gyamp.com/shokai/shokai")
|
15
18
|
puts " => #{gyamp.to_huge}"
|
19
|
+
|
20
|
+
puts bitly_tinyurl_nested = URI.parse("http://bit.ly/TSLl6M")
|
21
|
+
puts " => #{bitly_tinyurl_nested.to_huge}"
|
data/lib/hugeurl.rb
CHANGED
@@ -4,9 +4,18 @@ require 'net/http'
|
|
4
4
|
require 'net/https'
|
5
5
|
|
6
6
|
module Hugeurl
|
7
|
-
VERSION = '0.0.
|
7
|
+
VERSION = '0.0.7'
|
8
8
|
def self.get(uri)
|
9
9
|
uri = URI.parse uri unless uri.class.to_s =~ /^URI::/
|
10
|
+
loop do
|
11
|
+
res = self.get_redirect_to uri
|
12
|
+
return res if res.to_s == uri.to_s
|
13
|
+
uri = res
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def self.get_redirect_to(uri)
|
10
19
|
if uri.class == URI::HTTPS
|
11
20
|
http = Net::HTTP.new(uri.host, 443)
|
12
21
|
http.use_ssl = true
|
data/test/test_helper.rb
CHANGED
data/test/test_hugeurl.rb
CHANGED
@@ -6,6 +6,7 @@ class TestHugeurl < Test::Unit::TestCase
|
|
6
6
|
@source = "http://shokai.org"
|
7
7
|
@tinyurl = URI.parse("http://tinyurl.com/242tthb").to_huge
|
8
8
|
@tco = URI.parse("http://t.co/sdMbEC7n").to_huge
|
9
|
+
@bitly_tinyurl_nested = URI.parse("http://bit.ly/TSLl6M").to_huge
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_response
|
@@ -20,4 +21,7 @@ class TestHugeurl < Test::Unit::TestCase
|
|
20
21
|
assert @tinyurl.to_s == @source
|
21
22
|
end
|
22
23
|
|
24
|
+
def test_bitly_tinyurl_nested
|
25
|
+
assert @bitly_tinyurl_nested.to_s == @source
|
26
|
+
end
|
23
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hugeurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|