veezus-vurlify 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/vurlify.rb +58 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/vurlify_spec.rb +70 -0
- data/veezus-vurlify.gemspec +61 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Veezus Kreist
|
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.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= vurlify
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Veezus Kreist. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "veezus-vurlify"
|
8
|
+
gem.summary = %Q{Gem to shorten URLs using http://vurl.me}
|
9
|
+
gem.description = %Q{Gem to shorten URLs using http://vurl.me}
|
10
|
+
gem.email = "mremsik@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/veezus/vurlify"
|
12
|
+
gem.authors = ["Veezus Kreist"]
|
13
|
+
gem.add_development_dependency "rspec", "1.2.9"
|
14
|
+
gem.add_dependency "rest-client", "1.0.3"
|
15
|
+
gem.add_dependency "jnunemaker-crack", ">= 0.1.4"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "vurlify #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/lib/vurlify.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rest_client'
|
6
|
+
require 'crack/xml'
|
7
|
+
|
8
|
+
module Vurlify
|
9
|
+
VERSION = '0.1.1'
|
10
|
+
|
11
|
+
VURL_HOST = "http://vurl.me/"
|
12
|
+
VURL_PATH = "vurls"
|
13
|
+
VURL_POST_PATH = VURL_HOST + VURL_PATH
|
14
|
+
|
15
|
+
attr_accessor :cached_vurl, :vurl_cached_at
|
16
|
+
|
17
|
+
def shorten url
|
18
|
+
begin
|
19
|
+
Timeout::timeout(5) do
|
20
|
+
response = Crack::XML.parse RestClient.post(VURL_POST_PATH, :vurl => {:url => url})
|
21
|
+
"#{VURL_HOST}#{response['vurl']['slug']}"
|
22
|
+
end
|
23
|
+
rescue
|
24
|
+
url
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def vurl_for slug
|
29
|
+
return cached_vurl if cached_vurl && Time.now <= (vurl_cached_at + 5)
|
30
|
+
begin
|
31
|
+
Timeout::timeout(5) do
|
32
|
+
response = Crack::XML.parse RestClient.get(vurl_get_path(slug))
|
33
|
+
self.cached_vurl = Vurl.new
|
34
|
+
response['vurl'].each do |k,v|
|
35
|
+
self.cached_vurl[k] = v
|
36
|
+
end
|
37
|
+
self.vurl_cached_at = Time.now
|
38
|
+
cached_vurl
|
39
|
+
end
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def vurl_get_path slug
|
48
|
+
VURL_HOST + VURL_PATH + "/#{slug}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Vurl < Hash
|
53
|
+
def method_missing method, *args, &block
|
54
|
+
method_name = method.to_s
|
55
|
+
return fetch method_name if has_key? method_name
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
include Vurlify
|
5
|
+
end
|
6
|
+
|
7
|
+
VURL_POST_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vurl>\n <clicks-count type=\"integer\">0</clicks-count>\n <created-at type=\"datetime\">2009-08-04T11:57:04-04:00</created-at>\n <description></description>\n <id type=\"integer\">7</id>\n <ip-address>::1</ip-address>\n <keywords></keywords>\n <slug>AG</slug>\n <title>Example Web Page</title>\n <updated-at type=\"datetime\">2009-08-04T11:57:04-04:00</updated-at>\n <url>http://example.com</url>\n <user-id type=\"integer\">6</user-id>\n</vurl>\n"
|
8
|
+
|
9
|
+
VURL_GET_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vurl>\n <clicks-count type=\"integer\">17</clicks-count>\n <created-at type=\"datetime\">2009-08-04T11:57:04-04:00</created-at>\n <description></description>\n <id type=\"integer\">7</id>\n <ip-address>::1</ip-address>\n <keywords>words that are key</keywords>\n <slug>AG</slug>\n <title>Example Web Page</title>\n <updated-at type=\"datetime\">2009-08-04T11:57:04-04:00</updated-at>\n <url>http://example.com</url>\n <user-id type=\"integer\">6</user-id>\n</vurl>\n"
|
10
|
+
|
11
|
+
describe Dummy do
|
12
|
+
before do
|
13
|
+
@dummy = Dummy.new
|
14
|
+
@url = 'http://example.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#shorten" do
|
18
|
+
before { RestClient.stub!(:post).and_return VURL_POST_RESPONSE }
|
19
|
+
subject { @dummy.shorten(@url) }
|
20
|
+
|
21
|
+
it "shortens URLs" do
|
22
|
+
should == 'http://vurl.me/AG'
|
23
|
+
end
|
24
|
+
it "handles RestClient errors gracefully" do
|
25
|
+
RestClient.stub!(:post).and_raise "some error"
|
26
|
+
lambda do
|
27
|
+
should == @url
|
28
|
+
end.should_not raise_error
|
29
|
+
end
|
30
|
+
it "handles Crack errors gracefully" do
|
31
|
+
Crack::XML.stub!(:parse).and_raise "some error"
|
32
|
+
lambda do
|
33
|
+
should == @url
|
34
|
+
end.should_not raise_error
|
35
|
+
end
|
36
|
+
it "handles timeouts" do
|
37
|
+
Timeout.stub!(:timeout).and_raise "some error"
|
38
|
+
lambda do
|
39
|
+
should == @url
|
40
|
+
end.should_not raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#vurl_for" do
|
45
|
+
before { RestClient.stub!(:get).and_return VURL_GET_RESPONSE }
|
46
|
+
subject { @dummy.vurl_for('AG') }
|
47
|
+
|
48
|
+
it "loads the vurl" do
|
49
|
+
subject.slug.should == 'AG'
|
50
|
+
end
|
51
|
+
it "doesn't reload the vurl within five seconds" do
|
52
|
+
vurl = @dummy.vurl_for 'AG'
|
53
|
+
sleep 3
|
54
|
+
RestClient.should_not_receive(:get)
|
55
|
+
@dummy.vurl_for('AG').object_id.should == vurl.object_id
|
56
|
+
end
|
57
|
+
it "reloads the vurl after five seconds" do
|
58
|
+
vurl = @dummy.vurl_for 'AG'
|
59
|
+
sleep 6
|
60
|
+
RestClient.should_receive(:get).and_return VURL_GET_RESPONSE
|
61
|
+
@dummy.vurl_for('AG').object_id.should_not == vurl.object_id
|
62
|
+
end
|
63
|
+
it "handles timeouts" do
|
64
|
+
Timeout.stub!(:timeout).and_raise "some error"
|
65
|
+
lambda do
|
66
|
+
should be_nil
|
67
|
+
end.should_not raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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{veezus-vurlify}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Veezus Kreist"]
|
12
|
+
s.date = %q{2009-10-24}
|
13
|
+
s.description = %q{Gem to shorten URLs using http://vurl.me}
|
14
|
+
s.email = %q{mremsik@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/vurlify.rb",
|
27
|
+
"spec/spec.opts",
|
28
|
+
"spec/spec_helper.rb",
|
29
|
+
"spec/vurlify_spec.rb",
|
30
|
+
"veezus-vurlify.gemspec"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/veezus/vurlify}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
|
+
s.summary = %q{Gem to shorten URLs using http://vurl.me}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/vurlify_spec.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
|
48
|
+
s.add_runtime_dependency(%q<rest-client>, ["= 1.0.3"])
|
49
|
+
s.add_runtime_dependency(%q<jnunemaker-crack>, [">= 0.1.4"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
52
|
+
s.add_dependency(%q<rest-client>, ["= 1.0.3"])
|
53
|
+
s.add_dependency(%q<jnunemaker-crack>, [">= 0.1.4"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
57
|
+
s.add_dependency(%q<rest-client>, ["= 1.0.3"])
|
58
|
+
s.add_dependency(%q<jnunemaker-crack>, [">= 0.1.4"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: veezus-vurlify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Veezus Kreist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-24 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jnunemaker-crack
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.4
|
44
|
+
version:
|
45
|
+
description: Gem to shorten URLs using http://vurl.me
|
46
|
+
email: mremsik@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/vurlify.rb
|
62
|
+
- spec/spec.opts
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/vurlify_spec.rb
|
65
|
+
- veezus-vurlify.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/veezus/vurlify
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Gem to shorten URLs using http://vurl.me
|
94
|
+
test_files:
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/vurlify_spec.rb
|