shorturl 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.8.0:
2
+ - Made some improvements to bin/shorturl
3
+
1
4
  0.7.0:
2
5
  - Added shortify.com, 0rz.net
3
6
  - Modified unit tests
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = ShortURL 0.7.0
1
+ = ShortURL 0.8.0
2
2
 
3
3
  == Summary
4
4
  ShortURL is a very simple library to use URL shortening services such as
@@ -33,6 +33,7 @@ Here is the list of the services supported by ShortURL:
33
33
  * http://0rz.net
34
34
 
35
35
  == Usage:
36
+
36
37
  call-seq:
37
38
  require "shorturl"
38
39
  puts ShortURL.shorten("http://mypage.com")
@@ -63,6 +64,15 @@ You can use <tt>ShortURL.valid_services</tt> to obtain a
63
64
  list of the valid services (in case I forget to update the
64
65
  documentation)
65
66
 
67
+ You can also use the small script in bin/ which can be used from the
68
+ command line:
69
+ call-seq:
70
+ $ shorturl www.google.com
71
+ http://rubyurl.com/fuuUw
72
+ $ shorturl -s tinyurl www.google.com
73
+ http://tinyurl.com/1c2
74
+ $
75
+
66
76
  == Thanks
67
77
  - Marcel Molina Jr., Devin Mullins for some ideas
68
78
  - imperator from #ruby-lang (I don't know your real name, sorry) for
data/bin/shorturl CHANGED
@@ -2,35 +2,37 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "shorturl"
5
+ require "optparse"
5
6
 
6
- def usage
7
- puts "Usage: #$0 <url> [<service>]"
8
- puts "Available services:"
9
- ShortURL.valid_services.each { |s| puts "\t#{s}" }
10
- exit(-1)
7
+ def service_list
8
+ ShortURL.valid_services.map { |s| s.to_s }.sort.join("\n\t")
11
9
  end
12
10
 
13
11
  def main
14
- if ARGV.size < 1
15
- usage
12
+ service = :rubyurl
13
+ op = OptionParser.new do |opts|
14
+ opts.banner = "Usage: #{File.basename($0)} [<options>] <url>"
15
+ opts.on("-h", "--help", "Displays help") { puts opts; exit }
16
+ opts.on("-s", "--service <service>", String,
17
+ "Uses <service> instead of RubyURL
18
+ Available services:\n\t" + service_list) { |s| service = s.to_sym }
19
+ opts.parse!
16
20
  end
17
21
 
18
- url = ARGV[0]
19
- service = ARGV[1]
20
-
21
- shorturl = if service.nil?
22
- ShortURL.shorten(url)
22
+ if ARGV.empty?
23
+ puts op
24
+ exit(-1)
25
+ end
26
+
27
+ url = ARGV.shift
28
+ shorturl = if ShortURL.valid_services.include?(service)
29
+ ShortURL.shorten(url, service)
23
30
  else
24
- if ShortURL.valid_services.include?(service.to_sym)
25
- ShortURL.shorten(url, service.to_sym)
26
- else
27
- puts "Invalid service"
28
- exit(-1)
29
- end
31
+ puts "Invalid service"
32
+ exit(-1)
30
33
  end
31
34
 
32
- puts shorturl
33
-
35
+ puts shorturl || "Unable to get shortened URL. Maybe the URL is already too short?"
34
36
  end
35
37
 
36
38
  main
@@ -214,10 +214,14 @@ Now that our service is set up, call it with all the parameters to
214
214
  41: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:get</span><span class="ruby-operator">:</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-node">&quot;#{@action}?#{@field}=#{CGI.escape(url)}&quot;</span>)
215
215
  42: <span class="ruby-keyword kw">end</span>
216
216
  43: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@code</span>.<span class="ruby-identifier">to_s</span>
217
- 44: <span class="ruby-ivar">@block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">read_body</span>)
218
- 45: <span class="ruby-keyword kw">end</span>
219
- 46: }
220
- 47: <span class="ruby-keyword kw">end</span>
217
+ 44: <span class="ruby-keyword kw">begin</span>
218
+ 45: <span class="ruby-ivar">@block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">read_body</span>)
219
+ 46: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span>
220
+ 47: <span class="ruby-keyword kw">nil</span>
221
+ 48: <span class="ruby-keyword kw">end</span>
222
+ 49: <span class="ruby-keyword kw">end</span>
223
+ 50: }
224
+ 51: <span class="ruby-keyword kw">end</span>
221
225
  </pre>
222
226
  </div>
223
227
  </div>
@@ -195,14 +195,14 @@ call-seq:
195
195
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
196
196
  <div class="method-source-code" id="M000002-source">
197
197
  <pre>
198
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 197</span>
199
- 197: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">shorten</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">service</span> = <span class="ruby-identifier">:rubyurl</span>)
200
- 198: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">valid_services</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">service</span>
201
- 199: <span class="ruby-ivar">@@services</span>[<span class="ruby-identifier">service</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
202
- 200: <span class="ruby-keyword kw">else</span>
203
- 201: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidService</span>
204
- 202: <span class="ruby-keyword kw">end</span>
205
- 203: <span class="ruby-keyword kw">end</span>
198
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 201</span>
199
+ 201: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">shorten</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">service</span> = <span class="ruby-identifier">:rubyurl</span>)
200
+ 202: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">valid_services</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">service</span>
201
+ 203: <span class="ruby-ivar">@@services</span>[<span class="ruby-identifier">service</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
202
+ 204: <span class="ruby-keyword kw">else</span>
203
+ 205: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidService</span>
204
+ 206: <span class="ruby-keyword kw">end</span>
205
+ 207: <span class="ruby-keyword kw">end</span>
206
206
  </pre>
207
207
  </div>
208
208
  </div>
@@ -225,10 +225,10 @@ Returns @@<a href="ShortURL.html#M000001">valid_services</a>
225
225
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
226
226
  <div class="method-source-code" id="M000001-source">
227
227
  <pre>
228
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 164</span>
229
- 164: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">valid_services</span>
230
- 165: <span class="ruby-ivar">@@valid_services</span>
231
- 166: <span class="ruby-keyword kw">end</span>
228
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 168</span>
229
+ 168: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">valid_services</span>
230
+ 169: <span class="ruby-ivar">@@valid_services</span>
231
+ 170: <span class="ruby-keyword kw">end</span>
232
232
  </pre>
233
233
  </div>
234
234
  </div>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Mon Sep 26 19:17:22 EDT 2005
1
+ Sun Oct 02 14:18:23 EDT 2005
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Sep 26 18:49:23 EDT 2005</td>
59
+ <td>Sun Oct 02 14:08:57 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,11 +70,18 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
+ 0.8.0:
74
+ </p>
75
+ <pre>
76
+ - Made some improvements to bin/shorturl
77
+ </pre>
78
+ <p>
73
79
  0.7.0:
74
80
  </p>
75
81
  <pre>
76
82
  - Added shortify.com, 0rz.net
77
83
  - Modified unit tests
84
+ - Started using CVS on RubyForge
78
85
  </pre>
79
86
  <p>
80
87
  0.6.0:
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Sep 26 18:53:49 EDT 2005</td>
59
+ <td>Sun Oct 02 14:18:21 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,7 +69,7 @@
69
69
  <div id="contextContent">
70
70
 
71
71
  <div id="description">
72
- <h1><a href="../classes/ShortURL.html">ShortURL</a> 0.7.0</h1>
72
+ <h1><a href="../classes/ShortURL.html">ShortURL</a> 0.8.0</h1>
73
73
  <h2>Summary</h2>
74
74
  <p>
75
75
  <a href="../classes/ShortURL.html">ShortURL</a> is a very simple library to
@@ -220,6 +220,17 @@ href="../classes/ShortURL.html#M000001">ShortURL.valid_services</a></tt> to
220
220
  obtain a list of the valid services (in case I forget to update the
221
221
  documentation)
222
222
  </p>
223
+ <p>
224
+ You can also use the small script in bin/ which can be used from the
225
+ command line: call-seq:
226
+ </p>
227
+ <pre>
228
+ $ shorturl www.google.com
229
+ http://rubyurl.com/fuuUw
230
+ $ shorturl -s tinyurl www.google.com
231
+ http://tinyurl.com/1c2
232
+ $
233
+ </pre>
223
234
  <h2>Thanks</h2>
224
235
  <ul>
225
236
  <li>Marcel Molina Jr., Devin Mullins for some ideas
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Sep 26 19:09:28 EDT 2005</td>
59
+ <td>Thu Sep 29 23:03:41 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
data/lib/shorturl.rb CHANGED
@@ -41,7 +41,11 @@ class Service
41
41
  when :get: http.get("#{@action}?#{@field}=#{CGI.escape(url)}")
42
42
  end
43
43
  if response.code == @code.to_s
44
- @block.call(response.read_body)
44
+ begin
45
+ @block.call(response.read_body)
46
+ rescue NoMethodError
47
+ nil
48
+ end
45
49
  end
46
50
  }
47
51
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: shorturl
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2005-09-26 00:00:00 -04:00
6
+ version: 0.8.0
7
+ date: 2005-10-02 00:00:00 -04:00
8
8
  summary: Shortens URLs using services such as TinyURL and RubyURL
9
9
  require_paths:
10
10
  - lib