url_hunter 0.0.1 → 0.0.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.
- data/Rakefile +11 -2
- data/Readme.md +1 -1
- data/lib/url_hunter.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/url_hunter_spec.rb +22 -0
- data/url_hunter.gemspec +1 -0
- metadata +19 -4
data/Rakefile
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
2
4
|
|
3
5
|
desc "Open a shell with local libraries loaded"
|
4
6
|
task :shell do
|
5
|
-
exec "
|
7
|
+
exec "bundle exec irb -r url_hunter"
|
6
8
|
end
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
RSpec::Core::RakeTask.new do |t|
|
12
|
+
t.rspec_opts = %w(-fs --color)
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :spec
|
data/Readme.md
CHANGED
data/lib/url_hunter.rb
CHANGED
@@ -2,7 +2,7 @@ require 'uri'
|
|
2
2
|
require 'net/http'
|
3
3
|
|
4
4
|
class UrlHunter
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.2"
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
attr_reader :url, :original_url, :limit, :tries
|
@@ -42,7 +42,7 @@ class UrlHunter
|
|
42
42
|
redirect = res['Location']
|
43
43
|
# Append Location re-direct to previous URL if it's relative
|
44
44
|
if not redirect =~ /^(http|https):\/\//i
|
45
|
-
redirect =
|
45
|
+
redirect = u.scheme + '://' + u.hostname + redirect
|
46
46
|
end
|
47
47
|
@url = redirect
|
48
48
|
@tries += 1
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UrlHunter, '#resolve' do
|
4
|
+
it "Should require http:// or https:// prefixes" do
|
5
|
+
lambda { UrlHunter.resolve('no_prefix') }.should raise_error(UrlHunter::Error)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "Should resolve bit.ly urls pretty well" do
|
9
|
+
UrlHunter.resolve('http://bit.ly/DhAoX').should eq('http://www.apple.com/')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Should resolve the bit.ly url for http://www.apple.com/ in one try" do
|
13
|
+
u = UrlHunter.new('http://bit.ly/DhAoX')
|
14
|
+
u.resolve.should eq('http://www.apple.com/')
|
15
|
+
u.tries.should eq(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "Should handle relative paths mixed in Location tags" do
|
19
|
+
u = UrlHunter.new('http://flic.kr/p/bBqyXJ')
|
20
|
+
u.resolve.should_not include('bBqyXJ')
|
21
|
+
end
|
22
|
+
end
|
data/url_hunter.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_hunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70161664070420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70161664070420
|
14
25
|
description: Wait a minute, before I go anywhere with you, I want to know where you're
|
15
26
|
taking me.
|
16
27
|
email:
|
@@ -24,6 +35,8 @@ files:
|
|
24
35
|
- Rakefile
|
25
36
|
- Readme.md
|
26
37
|
- lib/url_hunter.rb
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/url_hunter_spec.rb
|
27
40
|
- url_hunter.gemspec
|
28
41
|
homepage: https://github.com/bshelton229/url_hunter
|
29
42
|
licenses: []
|
@@ -49,4 +62,6 @@ rubygems_version: 1.8.11
|
|
49
62
|
signing_key:
|
50
63
|
specification_version: 3
|
51
64
|
summary: Resolves URL re-directs given a limit
|
52
|
-
test_files:
|
65
|
+
test_files:
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/url_hunter_spec.rb
|