corto 0.60.0 → 0.80.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Paolo Perego
1
+ Copyright (c) 2011 Paolo Perego
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README CHANGED
@@ -0,0 +1,23 @@
1
+ CORTO - your url shortner gem
2
+ -----------------------------
3
+
4
+ - Yet another url shortner?
5
+
6
+ corto is a ruby gem that shorten a URL for you and store the result in a SQLite3 database.
7
+ Why the world needs another url shortener? Well, true to be told I don't know the answer and I'm
8
+ pretty sure this code is far away from being revolutionary.
9
+
10
+ However... it's fun!
11
+
12
+ - Note on Patches/Pull Requests
13
+
14
+ * Fork the project.
15
+ * Make your feature addition or bug fix.
16
+ * Add tests for it. This is important so I don’t break it in a future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version,
18
+ that is fine but bump version in a commit by itself I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ - Copyright
22
+
23
+ Copyright © 2011 Paolo Perego. See LICENSE for details.
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ begin
14
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
15
15
  gem.add_development_dependency "yard", ">= 0"
16
16
  gem.add_dependency "sqlite3", ">=0"
17
+ gem.add_dependency "awesome_print", ">=0"
17
18
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
19
  end
19
20
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.60.0
1
+ 0.80.0
data/bin/corto CHANGED
@@ -2,37 +2,69 @@
2
2
 
3
3
  require 'lib/corto'
4
4
  require 'getoptlong'
5
+ require 'ap'
6
+ require 'pp'
5
7
 
6
8
  opts = GetoptLong.new(
7
9
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
8
- [ '--version', '-v', GetoptLong::NO_ARGUMENT ]
10
+ [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
11
+ [ '--purge', '-P', GetoptLong::NO_ARGUMENT ],
12
+ [ '--count', '-c', GetoptLong::NO_ARGUMENT],
13
+ [ '--deflate', '-d', GetoptLong::NO_ARGUMENT]
9
14
  )
10
15
 
16
+ shrink = true
11
17
  begin
12
18
  opts.each do |opt, arg|
13
19
  case opt
14
20
  when '--help'
15
- puts 'usage: corto [-h|-v] url_to_shrink'
21
+ ap 'usage: corto [-h|-v|-c|-P] url_to_shrink'
16
22
  exit 0
17
23
  when '--version'
18
24
  @version = File.exist?('VERSION') ? File.read('VERSION') : ""
19
- puts @version
25
+ ap @version
20
26
  exit 0
27
+ when '--purge'
28
+ corto = Corto.new
29
+ corto.purge
30
+ ap 'corto: ' +corto.db_name+' successfully purged'
31
+ exit 0
32
+ when '--count'
33
+ corto = Corto.new
34
+ c = corto.count
35
+
36
+ ap 'corto: ' + corto.db_name+' contains ' + c.to_s + ' shortened urls.'
37
+
38
+ exit 0
39
+ when '--deflate'
40
+ shrink = false
41
+
21
42
  end
22
43
  end
23
44
  rescue
24
45
  exit 0
25
46
  end
26
47
  if ARGV.length != 1
27
- raise 'usage: corto [-h|-v] url_to_shrink'
48
+ raise 'usage: corto [-h|-v|-c|-P] url_to_shrink'
28
49
  exit 0
29
50
  end
30
51
 
31
52
  corto = Corto.new
32
- s = corto.shrink(ARGV[0])
33
- if (!s.nil?)
34
- puts 'corto: ' + ARGV[0] + ' shrinked as ' + s
53
+ if (shrink)
54
+ s = corto.shrink(ARGV[0])
55
+ if (!s.nil?)
56
+ puts 'corto: ' + ARGV[0] + ' shrinked as ' + s
57
+ else
58
+ puts 'corto: it seems ' + ARGV[0] + ' is not a valid url to shrink'
59
+ end
35
60
  else
36
- puts 'corto: it seems ' + ARGV[0] + ' is not a valid url to shrink'
61
+ s = corto.deflate(ARGV[0])
62
+ if (!s.nil?)
63
+ puts 'corto: ' + ARGV[0] + ' deflated is ' + s
64
+ else
65
+ puts 'corto: it seems ' + ARGV[0] + ' is not a known shrinked url'
66
+ end
37
67
  end
68
+
69
+
38
70
  exit 0
Binary file
@@ -49,7 +49,7 @@ class Corto
49
49
  def deflate(shrinked_url)
50
50
  @db = SQLite3::Database.new(@db_name)
51
51
  result = @db.execute("SELECT original FROM urls WHERE url='" +shrinked_url+"'")
52
- (! result.nil?) ? result.first.first : ''
52
+ (! result.first.nil?) ? result.first.first : nil
53
53
  end
54
54
 
55
55
  private
@@ -17,4 +17,10 @@ describe "Corto" do
17
17
  b = corto.deflate(a)
18
18
  b.should == "http://www.armoredcode.com"
19
19
  end
20
+
21
+ it "should handle a non existing shrink" do
22
+ a = corto.deflate('this can not be a valid shrinked url')
23
+ a.should.nil? == true
24
+ end
25
+
20
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corto
3
3
  version: !ruby/object:Gem::Version
4
- hash: 239
4
+ hash: 351
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 60
8
+ - 80
9
9
  - 0
10
- version: 0.60.0
10
+ version: 0.80.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paolo Perego
@@ -62,7 +62,39 @@ dependencies:
62
62
  version: "0"
63
63
  type: :runtime
64
64
  version_requirements: *id003
65
- description: ""
65
+ - !ruby/object:Gem::Dependency
66
+ name: awesome_print
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ description: "CORTO - your url shortner gem\n\
80
+ -----------------------------\n\n\
81
+ - Yet another url shortner?\n\
82
+ \t\n\
83
+ \tcorto is a ruby gem that shorten a URL for you and store the result in a SQLite3 database.\n\
84
+ \tWhy the world needs another url shortener? Well, true to be told I don't know the answer and I'm \n\
85
+ \tpretty sure this code is far away from being revolutionary.\n\
86
+ \t\n\
87
+ \tHowever... it's fun!\n\n\
88
+ - Note on Patches/Pull Requests\n\n\
89
+ \t* Fork the project.\n\
90
+ \t* Make your feature addition or bug fix.\n\
91
+ \t* Add tests for it. This is important so I don\xE2\x80\x99t break it in a future version unintentionally.\n\
92
+ \t* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, \n\
93
+ \t\tthat is fine but bump version in a commit by itself I can ignore when I pull)\n\
94
+ \t* Send me a pull request. Bonus points for topic branches.\n\n\
95
+ - Copyright\n\
96
+ \t\n\
97
+ \tCopyright \xC2\xA9 2011 Paolo Perego. See LICENSE for details."
66
98
  email: thesp0nge@gmail.com
67
99
  executables:
68
100
  - corto
@@ -71,13 +103,11 @@ extensions: []
71
103
  extra_rdoc_files:
72
104
  - LICENSE
73
105
  - README
74
- - README.rdoc
75
106
  files:
76
107
  - .document
77
108
  - .gitignore
78
109
  - LICENSE
79
110
  - README
80
- - README.rdoc
81
111
  - Rakefile
82
112
  - VERSION
83
113
  - bin/corto
@@ -1,17 +0,0 @@
1
- = corto
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 bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Paolo Perego. See LICENSE for details.