urlshort 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
1
  lib/**/*.rb
3
2
  bin/*
3
+ -
4
4
  features/**/*.feature
5
- LICENSE
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec" #, "~> 2.8.0"
10
+ gem "rdoc" #, "~> 3.12"
11
+ gem "bundler" #, "~> 1.0.0"
12
+ gem "jeweler" #, "~> 1.8.4"
13
+ gem "simplecov" #, ">= 0"
14
+ end
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.5)
12
+ multi_json (1.3.6)
13
+ rake (0.9.2.2)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.11.0)
17
+ rspec-core (~> 2.11.0)
18
+ rspec-expectations (~> 2.11.0)
19
+ rspec-mocks (~> 2.11.0)
20
+ rspec-core (2.11.1)
21
+ rspec-expectations (2.11.3)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.11.3)
24
+ simplecov (0.6.4)
25
+ multi_json (~> 1.0)
26
+ simplecov-html (~> 0.5.3)
27
+ simplecov-html (0.5.3)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler
34
+ jeweler
35
+ rdoc
36
+ rspec
37
+ simplecov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Doug P.
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.
@@ -1,17 +1,19 @@
1
1
  = urlshort
2
2
 
3
- Makes URLs short using services like is.gd and TinyUrl.
3
+ Description goes here.
4
4
 
5
- == Note on Patches/Pull Requests
5
+ == Contributing to urlshort
6
6
 
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
7
9
  * 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 bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
14
 
15
15
  == Copyright
16
16
 
17
- Copyright (c) 2010 Doug P.. See LICENSE for details.
17
+ Copyright (c) 2012 Doug P.. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile CHANGED
@@ -1,41 +1,44 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
2
12
  require 'rake'
3
13
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "urlshort"
8
- gem.summary = %Q{Makes URLs short using services like is.gd and TinyUrl.}
9
- gem.description = %Q{Makes URLs short using services like is.gd and TinyUrl.}
10
- gem.email = "dougtko@gmail.com"
11
- gem.homepage = "http://github.com/dougsko/urlshort"
12
- gem.authors = ["Doug P."]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_dependency "httpclient"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "urlshort"
18
+ gem.homepage = "http://github.com/dougsko/urlshort"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Gem for shortening URLs}
21
+ gem.description = %Q{Gem for shortening URLs}
22
+ gem.email = "dougtko@gmail.com"
23
+ gem.authors = ["Doug P."]
24
+ # dependencies defined in Gemfile
20
25
  end
26
+ Jeweler::RubygemsDotOrgTasks.new
21
27
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
26
32
  end
27
33
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
30
35
  spec.pattern = 'spec/**/*_spec.rb'
31
36
  spec.rcov = true
32
37
  end
33
38
 
34
- task :spec => :check_dependencies
35
-
36
39
  task :default => :spec
37
40
 
38
- require 'rake/rdoctask'
41
+ require 'rdoc/task'
39
42
  Rake::RDocTask.new do |rdoc|
40
43
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
44
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'urlshort'
4
+
5
+ res = IsGd.shorten(ARGV[0])
6
+ if(res == 1)
7
+ exit 1
8
+ else
9
+ puts res
10
+ end
data/bin/vgd ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'urlshort'
4
+
5
+ res = VGd.shorten(ARGV[0])
6
+ if(res == 1)
7
+ exit 1
8
+ else
9
+ puts res
10
+ end
Binary file
@@ -3,24 +3,97 @@
3
3
  ## URL Shortener
4
4
  ##
5
5
  #
6
- require 'rubygems'
6
+
7
7
  require 'httpclient'
8
8
 
9
- module UrlShort
9
+ class BadRequest < RuntimeError
10
+ def initialize(msg)
11
+ puts "There was a problem with the original long URL provided."
12
+ puts msg
13
+ end
14
+ end
10
15
 
11
- class IsGd
12
- def self.shorten(link)
13
- clnt = HTTPClient.new
14
- clnt.get('http://is.gd/api.php', {:longurl => link} ).content
15
- end
16
+ class NotAcceptable < RuntimeError
17
+ def initialize(msg)
18
+ puts "There was a problem with the short URL provided."
19
+ puts msg
16
20
  end
21
+ end
17
22
 
18
- class TinyUrl
19
- def self.shorten(link)
20
- clnt = HTTPClient.new
21
- clnt.get('http://tinyurl.com/api-create.php', {:url => link} ).content
22
- end
23
+ class BadGateway < RuntimeError
24
+ def initialize(msg)
25
+ puts "Our rate limit was exceeded."
26
+ puts msg
27
+ end
28
+ end
29
+
30
+ class ServiceUnavailable < RuntimeError
31
+ def initialize(msg)
32
+ puts "This service is temporarily unavailable."
33
+ puts msg
23
34
  end
35
+ end
24
36
 
37
+ class IsGd
38
+ def self.shorten(link)
39
+ err = 0
40
+ clnt = HTTPClient.new
41
+ resp = clnt.get('http://is.gd/create.php',
42
+ {:format => 'simple', :url => link} )#.content
43
+ begin
44
+ case resp.status_code
45
+ when 200
46
+ return resp.content
47
+ when 400
48
+ raise BadRequest.new(resp.content)
49
+ when 406
50
+ raise NotAcceptable.new(resp.content)
51
+ when 502
52
+ raise BadGateway.new(resp.content)
53
+ when 503
54
+ raise ServiceUnavailable.new(resp.content)
55
+ end
56
+ rescue BadRequest
57
+ err = 1
58
+ rescue NotAcceptable
59
+ err = 1
60
+ rescue BadGateway
61
+ err = 1
62
+ rescue ServiceUnavailable
63
+ err = 1
64
+ end
65
+ return err
66
+ end
67
+ end
25
68
 
69
+ class VGd
70
+ def self.shorten(link)
71
+ err = 0
72
+ clnt = HTTPClient.new
73
+ resp = clnt.get('http://v.gd/create.php',
74
+ {:format => 'simple', :url => link} )#.content
75
+ begin
76
+ case resp.status_code
77
+ when 200
78
+ return resp.content
79
+ when 400
80
+ raise BadRequest.new(resp.content)
81
+ when 406
82
+ raise NotAcceptable.new(resp.content)
83
+ when 502
84
+ raise BadGateway.new(resp.content)
85
+ when 503
86
+ raise ServiceUnavailable.new(resp.content)
87
+ end
88
+ rescue BadRequest
89
+ err = 1
90
+ rescue NotAcceptable
91
+ err = 1
92
+ rescue BadGateway
93
+ err = 1
94
+ rescue ServiceUnavailable
95
+ err = 1
96
+ end
97
+ return err
98
+ end
26
99
  end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'urlshort'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "urlshort"
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 = ["Doug P."]
12
+ s.date = "2012-09-29"
13
+ s.description = "Gem for shortening URLs"
14
+ s.email = "dougtko@gmail.com"
15
+ s.executables = ["isgd", "vgd"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE",
27
+ "LICENSE.txt",
28
+ "README.rdoc",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "bin/isgd",
32
+ "bin/vgd",
33
+ "lib/.urlshort.rb.swp",
34
+ "lib/urlshort.rb",
35
+ "spec/spec.opts",
36
+ "spec/spec_helper.rb",
37
+ "spec/urlshort_spec.rb",
38
+ "spec_helper.rb",
39
+ "urlshort.gemspec",
40
+ "urlshort_spec.rb"
41
+ ]
42
+ s.homepage = "http://github.com/dougsko/urlshort"
43
+ s.licenses = ["MIT"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = "1.8.10"
46
+ s.summary = "Gem for shortening URLs"
47
+
48
+ if s.respond_to? :specification_version then
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
54
+ s.add_development_dependency(%q<bundler>, [">= 0"])
55
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
+ s.add_dependency(%q<simplecov>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rspec>, [">= 0"])
66
+ s.add_dependency(%q<rdoc>, [">= 0"])
67
+ s.add_dependency(%q<bundler>, [">= 0"])
68
+ s.add_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_dependency(%q<simplecov>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Urlshort" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata CHANGED
@@ -1,98 +1,127 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: urlshort
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Doug P.
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-05-22 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
16
+ requirement: &75249970 !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: *75249970
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &75249130 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *75249130
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &75248710 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
22
45
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 2
30
- - 9
31
- version: 1.2.9
46
+ version_requirements: *75248710
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &75248340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
32
55
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: httpclient
36
56
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
44
- type: :runtime
45
- version_requirements: *id002
46
- description: Makes URLs short using services like is.gd and TinyUrl.
57
+ version_requirements: *75248340
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &75247800 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *75247800
69
+ description: Gem for shortening URLs
47
70
  email: dougtko@gmail.com
48
- executables: []
49
-
71
+ executables:
72
+ - isgd
73
+ - vgd
50
74
  extensions: []
51
-
52
- extra_rdoc_files:
75
+ extra_rdoc_files:
53
76
  - LICENSE
77
+ - LICENSE.txt
54
78
  - README.rdoc
55
- files:
79
+ files:
56
80
  - .document
57
- - .gitignore
81
+ - .rspec
82
+ - Gemfile
83
+ - Gemfile.lock
58
84
  - LICENSE
85
+ - LICENSE.txt
59
86
  - README.rdoc
60
87
  - Rakefile
61
88
  - VERSION
89
+ - bin/isgd
90
+ - bin/vgd
91
+ - lib/.urlshort.rb.swp
62
92
  - lib/urlshort.rb
63
93
  - spec/spec.opts
64
94
  - spec/spec_helper.rb
65
95
  - spec/urlshort_spec.rb
66
- has_rdoc: true
96
+ - spec_helper.rb
97
+ - urlshort.gemspec
98
+ - urlshort_spec.rb
67
99
  homepage: http://github.com/dougsko/urlshort
68
- licenses: []
69
-
100
+ licenses:
101
+ - MIT
70
102
  post_install_message:
71
- rdoc_options:
72
- - --charset=UTF-8
73
- require_paths:
103
+ rdoc_options: []
104
+ require_paths:
74
105
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- segments:
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
87
113
  - 0
88
- version: "0"
114
+ hash: 173180691
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
89
121
  requirements: []
90
-
91
122
  rubyforge_project:
92
- rubygems_version: 1.3.6
123
+ rubygems_version: 1.8.10
93
124
  signing_key:
94
125
  specification_version: 3
95
- summary: Makes URLs short using services like is.gd and TinyUrl.
96
- test_files:
97
- - spec/urlshort_spec.rb
98
- - spec/spec_helper.rb
126
+ summary: Gem for shortening URLs
127
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC