shurl 0.1.0
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/.gitignore +2 -0
- data/LICENSE +20 -0
- data/README.markdown +38 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/shurl.rb +29 -0
- data/shurl.gemspec +50 -0
- data/test/test_helper.rb +25 -0
- data/test/test_shurl.rb +24 -0
- metadata +72 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Mark Sands
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# shurl
|
2
|
+
### Shortest URL
|
3
|
+
|
4
|
+
## TODO
|
5
|
+
|
6
|
+
There's still a lot left to be done. I'd like to add more url shorteners, and find a way to make tinyarrows actually work. But it works for now.
|
7
|
+
|
8
|
+
## What + Why
|
9
|
+
|
10
|
+
Shurl finds the shortest URL from a list of URL shortening APIs. If there's one I don't have, please let me know and I'll add it. It queries each API for
|
11
|
+
a short url and then gives the user the shortest one back. Pretty simple stuff.
|
12
|
+
|
13
|
+
This is pretty much your stereotypical product of a college student. When I'm bored and not paying attention to lectures, this is what happens.
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
Updates are pushed to gemcutter.org
|
18
|
+
|
19
|
+
sudo gem install shurl
|
20
|
+
|
21
|
+
Optionally clone it from here and make sure the tests pass
|
22
|
+
|
23
|
+
git clone git://github.com/marksands/shurl.git
|
24
|
+
|
25
|
+
Test with `rake` or `turn`
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
require 'shurl'
|
30
|
+
|
31
|
+
foo = Shurl::Shortener.new
|
32
|
+
|
33
|
+
mini = foo.shorten("http://www.cnn.com")
|
34
|
+
# mini => "http://is.gd/aMH0W"
|
35
|
+
|
36
|
+
## Credit
|
37
|
+
|
38
|
+
© 2010 [marksands](http://twitter.com/marksands).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "shurl"
|
8
|
+
gem.summary = %Q{A url shortener that scales}
|
9
|
+
gem.description = %Q{A url shortener that queries a lot of APIs and returns the shortest url evar.}
|
10
|
+
gem.email = "marksands07@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/marksands/shurl"
|
12
|
+
gem.authors = ["Mark Sands"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :test => :check_dependencies
|
28
|
+
|
29
|
+
task :default => :test
|
30
|
+
|
31
|
+
require 'rake/rdoctask'
|
32
|
+
Rake::RDocTask.new do |rdoc|
|
33
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
34
|
+
|
35
|
+
rdoc.rdoc_dir = 'rdoc'
|
36
|
+
rdoc.title = "shurl #{version}"
|
37
|
+
rdoc.rdoc_files.include('README*')
|
38
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/shurl.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# http://ow.ly/url/shorten-url -- not out yet
|
2
|
+
# http://api.bit.ly/shorten?version=2.0.1&login=shurl&apiKey=R_a08944fe85b63e4e35dd04d78d180611&longUrl=
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Shurl
|
6
|
+
class Shortener
|
7
|
+
def initialize
|
8
|
+
@@mini = []
|
9
|
+
@@shorteners = %w{http://is.gd/api.php?longurl=
|
10
|
+
http://tinyarro.ws/api-create.php?url=
|
11
|
+
http://idek.net/shorten/?idek-api=true&idek-ref=your_app&idek-anchor=anchortag&idek-url=
|
12
|
+
http://chilp.it/api.php?url= }
|
13
|
+
end
|
14
|
+
|
15
|
+
def shorten(url)
|
16
|
+
@@shorteners.each do |u|
|
17
|
+
@@mini << Net::HTTP.get_response(URI.parse(u+urle(url))).body
|
18
|
+
end
|
19
|
+
@@mini.sort_by { |url| url.length } [0]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def url_encode(url)
|
25
|
+
URI.encode(url)
|
26
|
+
end
|
27
|
+
alias_method :urle, :url_encode
|
28
|
+
end
|
29
|
+
end
|
data/shurl.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{shurl}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Sands"]
|
12
|
+
s.date = %q{2010-03-17}
|
13
|
+
s.description = %q{A url shortener that queries a lot of APIs and returns the shortest url evar.}
|
14
|
+
s.email = %q{marksands07@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/shurl.rb",
|
26
|
+
"shurl.gemspec",
|
27
|
+
"test/test_helper.rb",
|
28
|
+
"test/test_shurl.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/marksands/shurl}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.6}
|
34
|
+
s.summary = %q{A url shortener that scales}
|
35
|
+
s.test_files = [
|
36
|
+
"test/test_helper.rb",
|
37
|
+
"test/test_shurl.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shurl'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
def long_url
|
10
|
+
"http://cnn.com"
|
11
|
+
end
|
12
|
+
|
13
|
+
@@shorten_urls = %w{
|
14
|
+
http://is.gd/api.php?longurl=
|
15
|
+
http://tinyarro.ws/api-create.php?url=
|
16
|
+
http://idek.net/shorten/?idek-api=true&idek-ref=your_app&idek-anchor=anchortag&idek-url=
|
17
|
+
http://chilp.it/api.php?url=
|
18
|
+
}
|
19
|
+
|
20
|
+
[:isgd, :tinyarrows, :idek, :chilp].each_with_index do |url, i|
|
21
|
+
define_method url do
|
22
|
+
@@shorten_urls[i]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_shurl.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestShurl < Test::Unit::TestCase
|
4
|
+
[:isgd, :tinyarrows, :idek, :chilp].each do |url|
|
5
|
+
define_method "test_#{url}" do
|
6
|
+
Net::HTTP.get_response(URI.parse( instance_eval(url.to_s) + long_url )).body
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_shortest
|
11
|
+
@@mini = []
|
12
|
+
[:test_isgd, :test_tinyarrows, :test_idek, :test_chilp].each do |test|
|
13
|
+
@@mini << instance_eval(test.to_s)
|
14
|
+
end
|
15
|
+
@@result = @@mini.sort_by { |url| url.length } [0]
|
16
|
+
|
17
|
+
# a big `wtf` test, just verifies that it's a url #embarrassingcode
|
18
|
+
assert_match %r{http://.+}, @@result
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_shortest_is_short
|
22
|
+
@@mini.map { |m| assert_operator @@result.length, :<=, m.length }
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shurl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mark Sands
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-17 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A url shortener that queries a lot of APIs and returns the shortest url evar.
|
22
|
+
email: marksands07@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.markdown
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- LICENSE
|
33
|
+
- README.markdown
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- lib/shurl.rb
|
37
|
+
- shurl.gemspec
|
38
|
+
- test/test_helper.rb
|
39
|
+
- test/test_shurl.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/marksands/shurl
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.6
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A url shortener that scales
|
70
|
+
test_files:
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/test_shurl.rb
|