expander 0.0.1

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.
Files changed (2) hide show
  1. data/lib/expander.rb +40 -0
  2. metadata +67 -0
data/lib/expander.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+
3
+ module JM3
4
+ module ExpandUrl
5
+ def expand_urls!
6
+ ExpandUrl.services.each do |service|
7
+ gsub!(service[:pattern]) { |match|
8
+ ExpandUrl.expand($2, service[:host]) || $1
9
+ }
10
+ end
11
+ end
12
+
13
+ def expand_urls
14
+ s = dup
15
+ s.expand_urls!
16
+ s
17
+ end
18
+
19
+ def ExpandUrl.services
20
+ [
21
+ { :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' },
22
+ { :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' },
23
+ { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' },
24
+ { :host => "t.co", :pattern => %r'(http://t\.co(/[\w/]+))' },
25
+ ]
26
+ end
27
+
28
+ def ExpandUrl.expand(path, host)
29
+ result = ::Net::HTTP.new(host).head(path)
30
+ case result
31
+ when ::Net::HTTPRedirection
32
+ result['Location']
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ class String
39
+ include JM3::ExpandUrl
40
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: expander
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Manoogian III (jm3)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-03 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A simple URL expanding gem
23
+ email: jm3@140proof.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/expander.rb
32
+ has_rdoc: true
33
+ homepage: http://rubygems.org/gems/expander
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.6.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Expand urls!
66
+ test_files: []
67
+