shorturl 0.6.0 → 0.7.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/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.7.0:
2
+ - Added shortify.com, 0rz.net
3
+ - Modified unit tests
4
+ - Started using CVS on RubyForge
5
+
1
6
  0.6.0:
2
7
  - Changed the method for getting the URL for ln-s.net to use their
3
8
  API. So basically, this means the new additional argument attribute
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = ShortURL 0.5.0
1
+ = ShortURL 0.7.0
2
2
 
3
3
  == Summary
4
4
  ShortURL is a very simple library to use URL shortening services such as
@@ -29,6 +29,8 @@ Here is the list of the services supported by ShortURL:
29
29
  * http://shiturl.com
30
30
  * http://littlink.com
31
31
  * http://clipurl.com
32
+ * http://shortify.com
33
+ * http://0rz.net
32
34
 
33
35
  == Usage:
34
36
  call-seq:
@@ -53,6 +55,8 @@ The second parameter represents the service you want to use. These are:
53
55
  * <tt>:shiturl</tt>
54
56
  * <tt>:littlink</tt>
55
57
  * <tt>:clipurl</tt>
58
+ * <tt>:shortify</tt>
59
+ * <tt>:orz</tt>
56
60
 
57
61
 
58
62
  You can use <tt>ShortURL.valid_services</tt> to obtain a
@@ -61,7 +65,7 @@ documentation)
61
65
 
62
66
  == Thanks
63
67
  - Marcel Molina Jr., Devin Mullins for some ideas
64
- - imperator from #ruby-lang (don't know your real name, sorry) for
68
+ - imperator from #ruby-lang (I don't know your real name, sorry) for
65
69
  helping me with creating and uploading a RubyGem
66
70
  - Daniel Dipaolo for telling me about ln-s.net and fyad.org
67
71
 
@@ -210,8 +210,8 @@ Now that our service is set up, call it with all the parameters to
210
210
  37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
211
211
  38: <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-ivar">@hostname</span>, <span class="ruby-ivar">@port</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
212
212
  39: <span class="ruby-identifier">response</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@method</span>
213
- 40: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:post</span><span class="ruby-operator">:</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">send</span>(<span class="ruby-ivar">@method</span>, <span class="ruby-ivar">@action</span>, <span class="ruby-node">&quot;#@field=#{url}&quot;</span>)
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">send</span>(<span class="ruby-ivar">@method</span>, <span class="ruby-node">&quot;#@action?#@field=#{CGI.escape(url)}&quot;</span>)
213
+ 40: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:post</span><span class="ruby-operator">:</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-ivar">@action</span>, <span class="ruby-node">&quot;#{@field}=#{url}&quot;</span>)
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
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>)
@@ -176,6 +176,12 @@ Valid <tt>service</tt> values:
176
176
  </li>
177
177
  <li><tt>:clipurl</tt>
178
178
 
179
+ </li>
180
+ <li><tt>:shortify</tt>
181
+
182
+ </li>
183
+ <li><tt>:orz</tt>
184
+
179
185
  </li>
180
186
  </ul>
181
187
  <p>
@@ -189,14 +195,14 @@ call-seq:
189
195
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
190
196
  <div class="method-source-code" id="M000002-source">
191
197
  <pre>
192
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 185</span>
193
- 185: <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>)
194
- 186: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@valid_services</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">service</span>
195
- 187: <span class="ruby-ivar">@@services</span>[<span class="ruby-identifier">service</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
196
- 188: <span class="ruby-keyword kw">else</span>
197
- 189: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidService</span>
198
- 190: <span class="ruby-keyword kw">end</span>
199
- 191: <span class="ruby-keyword kw">end</span>
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>
200
206
  </pre>
201
207
  </div>
202
208
  </div>
@@ -219,10 +225,10 @@ Returns @@<a href="ShortURL.html#M000001">valid_services</a>
219
225
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
220
226
  <div class="method-source-code" id="M000001-source">
221
227
  <pre>
222
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 154</span>
223
- 154: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">valid_services</span>
224
- 155: <span class="ruby-ivar">@@valid_services</span>
225
- 156: <span class="ruby-keyword kw">end</span>
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>
226
232
  </pre>
227
233
  </div>
228
234
  </div>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Wed Jun 29 21:33:29 EDT 2005
1
+ Mon Sep 26 19:17:22 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>Wed Jun 29 21:28:47 EDT 2005</td>
59
+ <td>Mon Sep 26 18:49:23 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,6 +70,13 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
+ 0.7.0:
74
+ </p>
75
+ <pre>
76
+ - Added shortify.com, 0rz.net
77
+ - Modified unit tests
78
+ </pre>
79
+ <p>
73
80
  0.6.0:
74
81
  </p>
75
82
  <pre>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jun 29 00:31:55 EDT 2005</td>
59
+ <td>Fri Jul 15 15:31:20 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jun 29 21:33:23 EDT 2005</td>
59
+ <td>Mon Sep 26 18:53:49 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.5.0</h1>
72
+ <h1><a href="../classes/ShortURL.html">ShortURL</a> 0.7.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
@@ -138,6 +138,12 @@ href="../classes/ShortURL.html">ShortURL</a>:
138
138
  </li>
139
139
  <li><a href="http://clipurl.com">clipurl.com</a>
140
140
 
141
+ </li>
142
+ <li><a href="http://shortify.com">shortify.com</a>
143
+
144
+ </li>
145
+ <li><a href="http://0rz.net">0rz.net</a>
146
+
141
147
  </li>
142
148
  </ul>
143
149
  <h2>Usage:</h2>
@@ -159,7 +165,7 @@ The second parameter represents the service you want to use. These are:
159
165
  <li><tt>:tinyurl</tt>
160
166
 
161
167
  </li>
162
- <li><tt>:snorl</tt>
168
+ <li><tt>:shorl</tt>
163
169
 
164
170
  </li>
165
171
  <li><tt>:snipurl</tt>
@@ -180,7 +186,7 @@ The second parameter represents the service you want to use. These are:
180
186
  <li><tt>:shorterlink</tt>
181
187
 
182
188
  </li>
183
- <li><tt>:minilink</tt>
189
+ <li><tt>:minlink</tt>
184
190
 
185
191
  </li>
186
192
  <li><tt>:lns</tt>
@@ -200,6 +206,12 @@ The second parameter represents the service you want to use. These are:
200
206
  </li>
201
207
  <li><tt>:clipurl</tt>
202
208
 
209
+ </li>
210
+ <li><tt>:shortify</tt>
211
+
212
+ </li>
213
+ <li><tt>:orz</tt>
214
+
203
215
  </li>
204
216
  </ul>
205
217
  <p>
@@ -213,7 +225,7 @@ documentation)
213
225
  <li>Marcel Molina Jr., Devin Mullins for some ideas
214
226
 
215
227
  </li>
216
- <li>imperator from ruby-lang (don&#8217;t know your real name, sorry) for
228
+ <li>imperator from ruby-lang (I don&#8217;t know your real name, sorry) for
217
229
  helping me with creating and uploading a RubyGem
218
230
 
219
231
  </li>
data/doc/files/TODO.html CHANGED
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jun 29 01:39:21 EDT 2005</td>
59
+ <td>Fri Jul 15 15:31:20 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Jun 29 21:27:27 EDT 2005</td>
59
+ <td>Mon Sep 26 19:09:28 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
data/lib/shorturl.rb CHANGED
@@ -37,8 +37,8 @@ class Service
37
37
  def call(url)
38
38
  Net::HTTP.start(@hostname, @port) { |http|
39
39
  response = case @method
40
- when :post: http.send(@method, @action, "#@field=#{url}")
41
- when :get: http.send(@method, "#@action?#@field=#{CGI.escape(url)}")
40
+ when :post: http.post(@action, "#{@field}=#{url}")
41
+ when :get: http.get("#{@action}?#{@field}=#{CGI.escape(url)}")
42
42
  end
43
43
  if response.code == @code.to_s
44
44
  @block.call(response.read_body)
@@ -64,9 +64,7 @@ class ShortURL
64
64
 
65
65
  :tinyurl => Service.new("tinyurl.com") { |s|
66
66
  s.action = "/create.php"
67
- s.block = lambda { |body|
68
- URI.extract(body).grep(/tinyurl/)[-1]
69
- }
67
+ s.block = lambda { |body| URI.extract(body).grep(/tinyurl/)[-1] }
70
68
  },
71
69
 
72
70
  :shorl => Service.new("shorl.com") { |s|
@@ -144,8 +142,20 @@ class ShortURL
144
142
  :clipurl => Service.new("clipurl.com") { |s|
145
143
  s.action = "/create.asp"
146
144
  s.block = lambda { |body| URI.extract(body).grep(/clipurl/)[0] }
145
+ },
146
+
147
+ :shortify => Service.new("shortify.com") { |s|
148
+ s.method = :get
149
+ s.action = "/shorten.php"
150
+ s.block = lambda { |body| URI.extract(body).grep(/shortify/)[0] }
151
+ },
152
+
153
+ :orz => Service.new("0rz.net") { |s|
154
+ s.action = "/create.php"
155
+ s.block = lambda { |body| URI.extract(body).grep(/0rz/)[0] }
147
156
  }
148
157
  }
158
+
149
159
  # Array containing symbols representing all the implemented URL
150
160
  # shortening services
151
161
  @@valid_services = @@services.keys
@@ -178,12 +188,14 @@ class ShortURL
178
188
  # * <tt>:shiturl</tt>
179
189
  # * <tt>:littlink</tt>
180
190
  # * <tt>:clipurl</tt>
191
+ # * <tt>:shortify</tt>
192
+ # * <tt>:orz</tt>
181
193
  #
182
194
  # call-seq:
183
195
  # ShortURL.shorten("http://mypage.com") => Uses RubyURL
184
196
  # ShortURL.shorten("http://mypage.com", :tinyurl)
185
197
  def self.shorten(url, service = :rubyurl)
186
- if @@valid_services.include? service
198
+ if valid_services.include? service
187
199
  @@services[service].call(url)
188
200
  else
189
201
  raise InvalidService
data/test/tc_shorturl.rb CHANGED
@@ -8,35 +8,28 @@ $:.unshift($test_lib_dir)
8
8
  require "test/unit"
9
9
  require "shorturl"
10
10
 
11
+ class String
12
+ def url?
13
+ self[0..6].downcase == "http://"
14
+ end
15
+ end
11
16
 
12
17
  class TestShortURL < Test::Unit::TestCase
13
18
  def setup
14
- @url = "http://darkhost.mine.nu:81/~vince/rails/tutorial.html"
19
+ @url = "http://groups.google.com/group/comp.lang.ruby/"
15
20
  end
16
21
 
17
22
  def test_shorten
18
23
  # Default service (RubyURL)
19
- assert ShortURL.shorten(@url) == "http://rubyurl.com/Q9ToW"
24
+ assert ShortURL.shorten(@url).url?
20
25
 
21
- # All the services (in the order in which they were added)
22
- assert ShortURL.shorten(@url, :rubyurl) == "http://rubyurl.com/Q9ToW"
23
- assert ShortURL.shorten(@url, :tinyurl) == "http://tinyurl.com/9mop8"
24
- assert ShortURL.shorten(@url, :shorl) =~ /^http:\/\/shorl.com/ # Never the same URL
25
- assert ShortURL.shorten(@url, :snipurl) == "http://snipurl.com/fbkl"
26
- assert ShortURL.shorten(@url, :metamark) == "http://xrl.us/ga8c"
27
- assert ShortURL.shorten(@url, :makeashorterlink) == "http://makeashorterlink.com/?O1752235A"
28
- assert ShortURL.shorten(@url, :skinnylink) == "http://skinnylink.com?nqvcce"
29
- assert ShortURL.shorten(@url, :linktrim) =~ /http:\/\/linktrim/ # Never the same URL
30
- assert ShortURL.shorten(@url, :shorterlink) == "http://shorterlink.com/?PQD096"
31
- assert ShortURL.shorten(@url, :minilink) == "http://lnk.nu/darkhost.mine.nu:81/2zr.html"
32
- assert ShortURL.shorten(@url, :lns) == "http://ln-s.net/5UL"
33
- assert ShortURL.shorten(@url, :fyad) == "http://fyad.org/15zu"
34
- assert ShortURL.shorten(@url, :d62) == "http://y5o49.d62.net"
35
- assert ShortURL.shorten(@url, :shiturl) == "http://www.shiturl.com/b53b3a"
36
- assert ShortURL.shorten(@url, :littlink) == "http://littlink.com/2kc87"
37
- assert ShortURL.shorten(@url, :clipurl) == "http://clipurl.com?BH"
38
-
26
+ # All the services (I can't test exact URLs since they seem to
27
+ # change semi regularly)
28
+ ShortURL.valid_services.each do |service|
29
+ assert ShortURL.shorten(@url, service).url?
30
+ end
39
31
 
32
+ # An invalid service
40
33
  assert_raise(InvalidService) { ShortURL.shorten(@url, :foobar) }
41
34
  end
42
35
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: shorturl
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2005-06-29
6
+ version: 0.7.0
7
+ date: 2005-09-26 00:00:00 -04:00
8
8
  summary: Shortens URLs using services such as TinyURL and RubyURL
9
9
  require_paths:
10
10
  - lib
@@ -24,28 +24,30 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
24
  version: 0.0.0
25
25
  version:
26
26
  platform: ruby
27
+ signing_key:
28
+ cert_chain:
27
29
  authors:
28
30
  - Vincent Foley
29
31
  files:
30
32
  - bin/shorturl
31
33
  - lib/shorturl.rb
34
+ - doc/classes
32
35
  - doc/created.rid
33
- - doc/rdoc-style.css
34
36
  - doc/files
35
- - doc/classes
36
- - doc/fr_file_index.html
37
37
  - doc/fr_class_index.html
38
+ - doc/fr_file_index.html
38
39
  - doc/fr_method_index.html
39
40
  - doc/index.html
40
- - doc/files/README.html
41
- - doc/files/TODO.html
42
- - doc/files/MIT-LICENSE.html
41
+ - doc/rdoc-style.css
42
+ - doc/classes/InvalidService.html
43
+ - doc/classes/Service.html
44
+ - doc/classes/ShortURL.html
43
45
  - doc/files/ChangeLog.html
44
46
  - doc/files/lib
47
+ - doc/files/MIT-LICENSE.html
48
+ - doc/files/README.html
49
+ - doc/files/TODO.html
45
50
  - doc/files/lib/shorturl_rb.html
46
- - doc/classes/ShortURL.html
47
- - doc/classes/InvalidService.html
48
- - doc/classes/Service.html
49
51
  - test/tc_service.rb
50
52
  - test/tc_shorturl.rb
51
53
  - test/ts_all.rb