shorturl 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,5 @@
1
+ 0.2.0:
2
+ - Added shorl.com, snipurl.com and metamark.net
1
3
  0.1.0:
2
4
  - Refactored the tinyurl and rubyurl methods
3
5
  - URI.extract to get URLs instead of regular expressions
@@ -7,4 +9,4 @@
7
9
  - Made tinyurl, rubyurl and get_short_url private class methods
8
10
 
9
11
  0.0.1:
10
- - Initial Version
12
+ - Initial release
data/README CHANGED
@@ -13,6 +13,13 @@ call-seq:
13
13
  puts ShortURL.shorten("http://mypage.com")
14
14
  puts ShortURL.shorten("http://mypage.com", :tinyurl)
15
15
 
16
+ The second parameter represents the service you want to use. These are:
17
+ - <tt>:rubyurl</tt>
18
+ - <tt>:tinyurl</tt>
19
+ - <tt>:snorl</tt>
20
+ - <tt>:snipurl</tt>
21
+ - <tt>:metamark</tt>
22
+
16
23
  == Thanks
17
24
  - Marcel Molina Jr., Devin Mullins for some ideas
18
25
  - imperator from #ruby-lang (don't know your real name, sorry) for
@@ -87,8 +87,11 @@
87
87
 
88
88
  <div class="name-list">
89
89
  <a href="#M000002">get_short_url</a>&nbsp;&nbsp;
90
+ <a href="#M000007">metamark</a>&nbsp;&nbsp;
90
91
  <a href="#M000003">rubyurl</a>&nbsp;&nbsp;
92
+ <a href="#M000005">shorl</a>&nbsp;&nbsp;
91
93
  <a href="#M000001">shorten</a>&nbsp;&nbsp;
94
+ <a href="#M000006">snipurl</a>&nbsp;&nbsp;
92
95
  <a href="#M000004">tinyurl</a>&nbsp;&nbsp;
93
96
  </div>
94
97
  </div>
@@ -154,9 +157,12 @@ call-seq:
154
157
  27: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">service</span>
155
158
  28: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:rubyurl</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">rubyurl</span>(<span class="ruby-identifier">url</span>)
156
159
  29: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:tinyurl</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">tinyurl</span>(<span class="ruby-identifier">url</span>)
157
- 30: <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid service&quot;</span>
158
- 31: <span class="ruby-keyword kw">end</span>
159
- 32: <span class="ruby-keyword kw">end</span>
160
+ 30: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:shorl</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">shorl</span>(<span class="ruby-identifier">url</span>)
161
+ 31: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:snipurl</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">snipurl</span>(<span class="ruby-identifier">url</span>)
162
+ 32: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:metamark</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">metamark</span>(<span class="ruby-identifier">url</span>)
163
+ 33: <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid service&quot;</span>
164
+ 34: <span class="ruby-keyword kw">end</span>
165
+ 35: <span class="ruby-keyword kw">end</span>
160
166
  </pre>
161
167
  </div>
162
168
  </div>
@@ -191,20 +197,51 @@ Parameters:
191
197
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
192
198
  <div class="method-source-code" id="M000002-source">
193
199
  <pre>
194
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 42</span>
195
- 42: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_short_url</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">code</span>, <span class="ruby-identifier">action</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt"># :yields: html_body</span>
196
- 43: <span class="ruby-keyword kw">begin</span>
197
- 44: <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-identifier">hostname</span>, <span class="ruby-value">80</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
198
- 45: <span class="ruby-identifier">response</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-identifier">action</span>)
199
- 46:
200
- 47: <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-identifier">code</span>.<span class="ruby-identifier">to_s</span>
201
- 48: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">read_body</span>)
202
- 49: <span class="ruby-keyword kw">end</span>
203
- 50: }
204
- 51: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPExceptions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
205
- 52: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
206
- 53: <span class="ruby-keyword kw">end</span>
207
- 54: <span class="ruby-keyword kw">end</span>
200
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 45</span>
201
+ 45: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_short_url</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">code</span>, <span class="ruby-identifier">action</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt"># :yields: html_body</span>
202
+ 46: <span class="ruby-keyword kw">begin</span>
203
+ 47: <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-identifier">hostname</span>, <span class="ruby-value">80</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
204
+ 48: <span class="ruby-identifier">response</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-identifier">action</span>)
205
+ 49:
206
+ 50: <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-identifier">code</span>.<span class="ruby-identifier">to_s</span>
207
+ 51: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">read_body</span>)
208
+ 52: <span class="ruby-keyword kw">end</span>
209
+ 53: }
210
+ 54: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPExceptions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
211
+ 55: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
212
+ 56: <span class="ruby-keyword kw">end</span>
213
+ 57: <span class="ruby-keyword kw">end</span>
214
+ </pre>
215
+ </div>
216
+ </div>
217
+ </div>
218
+
219
+ <div id="method-M000007" class="method-detail">
220
+ <a name="M000007"></a>
221
+
222
+ <div class="method-heading">
223
+ <a href="#M000007" class="method-signature">
224
+ <span class="method-name">metamark</span><span class="method-args">(url)</span>
225
+ </a>
226
+ </div>
227
+
228
+ <div class="method-description">
229
+ <p>
230
+ Shorten a URL with metamark.com. Same technique as TinyURL
231
+ </p>
232
+ <p><a class="source-toggle" href="#"
233
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
234
+ <div class="method-source-code" id="M000007-source">
235
+ <pre>
236
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 107</span>
237
+ 107: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">metamark</span>(<span class="ruby-identifier">url</span>)
238
+ 108: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;metamark.net&quot;</span>, <span class="ruby-value">200</span>,
239
+ 109: <span class="ruby-node">&quot;post('/add', 'long_url=#{url}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
240
+ 110: <span class="ruby-identifier">line</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/xrl\.us/</span> }
241
+ 111: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">line</span>)[<span class="ruby-value">0</span>]
242
+ 112: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
243
+ 113: }
244
+ 114: <span class="ruby-keyword kw">end</span>
208
245
  </pre>
209
246
  </div>
210
247
  </div>
@@ -231,14 +268,75 @@ with gsub.
231
268
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
232
269
  <div class="method-source-code" id="M000003-source">
233
270
  <pre>
234
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 62</span>
235
- 62: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">rubyurl</span>(<span class="ruby-identifier">url</span>)
236
- 63: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;rubyurl.com&quot;</span>, <span class="ruby-value">302</span>,
237
- 64: <span class="ruby-node">&quot;get('/rubyurl/create?rubyurl[website_url]=#{CGI.escape(url)}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
238
- 65: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">body</span>)[<span class="ruby-value">0</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;rubyurl/show/&quot;</span>, <span class="ruby-value str">&quot;&quot;</span>)
239
- 66: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
240
- 67: }
241
- 68: <span class="ruby-keyword kw">end</span>
271
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 65</span>
272
+ 65: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">rubyurl</span>(<span class="ruby-identifier">url</span>)
273
+ 66: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;rubyurl.com&quot;</span>, <span class="ruby-value">302</span>,
274
+ 67: <span class="ruby-node">&quot;get('/rubyurl/create?rubyurl[website_url]=#{CGI.escape(url)}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
275
+ 68: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">body</span>)[<span class="ruby-value">0</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;rubyurl/show/&quot;</span>, <span class="ruby-value str">&quot;&quot;</span>)
276
+ 69: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
277
+ 70: }
278
+ 71: <span class="ruby-keyword kw">end</span>
279
+ </pre>
280
+ </div>
281
+ </div>
282
+ </div>
283
+
284
+ <div id="method-M000005" class="method-detail">
285
+ <a name="M000005"></a>
286
+
287
+ <div class="method-heading">
288
+ <a href="#M000005" class="method-signature">
289
+ <span class="method-name">shorl</span><span class="method-args">(url)</span>
290
+ </a>
291
+ </div>
292
+
293
+ <div class="method-description">
294
+ <p>
295
+ Shorten a URL through with shorl.com. Same technique as TinyURL
296
+ </p>
297
+ <p><a class="source-toggle" href="#"
298
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
299
+ <div class="method-source-code" id="M000005-source">
300
+ <pre>
301
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 88</span>
302
+ 88: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">shorl</span>(<span class="ruby-identifier">url</span>)
303
+ 89: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;shorl.com&quot;</span>, <span class="ruby-value">200</span>,
304
+ 90: <span class="ruby-node">&quot;post('/create.php', 'url=#{url}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
305
+ 91: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">body</span>)[<span class="ruby-value">2</span>]
306
+ 92: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
307
+ 93: }
308
+ 94: <span class="ruby-keyword kw">end</span>
309
+ </pre>
310
+ </div>
311
+ </div>
312
+ </div>
313
+
314
+ <div id="method-M000006" class="method-detail">
315
+ <a name="M000006"></a>
316
+
317
+ <div class="method-heading">
318
+ <a href="#M000006" class="method-signature">
319
+ <span class="method-name">snipurl</span><span class="method-args">(url)</span>
320
+ </a>
321
+ </div>
322
+
323
+ <div class="method-description">
324
+ <p>
325
+ Shorten a URL with snipurl.com. Same technique as TinyURL
326
+ </p>
327
+ <p><a class="source-toggle" href="#"
328
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
329
+ <div class="method-source-code" id="M000006-source">
330
+ <pre>
331
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 97</span>
332
+ 97: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">snipurl</span>(<span class="ruby-identifier">url</span>)
333
+ 98: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;snipurl.com&quot;</span>, <span class="ruby-value">200</span>,
334
+ 99: <span class="ruby-node">&quot;post('/index.php', 'link=#{url}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
335
+ 100: <span class="ruby-identifier">line</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">grep</span>(<span class="ruby-regexp re">/txt/</span>)[<span class="ruby-value">0</span>]
336
+ 101: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">line</span>)[<span class="ruby-value">1</span>][<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>] <span class="ruby-comment cmt"># Remove trailing '</span>
337
+ 102: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
338
+ 103: }
339
+ 104: <span class="ruby-keyword kw">end</span>
242
340
  </pre>
243
341
  </div>
244
342
  </div>
@@ -264,15 +362,15 @@ shortened URL and extract it.
264
362
  onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
265
363
  <div class="method-source-code" id="M000004-source">
266
364
  <pre>
267
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 75</span>
268
- 75: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">tinyurl</span>(<span class="ruby-identifier">url</span>)
269
- 76: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;tinyurl.com&quot;</span>, <span class="ruby-value">200</span>,
270
- 77: <span class="ruby-node">&quot;post('/create.php', 'url=#{url}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
271
- 78: <span class="ruby-identifier">line</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/hidden name=tinyurl/</span> }
272
- 79: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">line</span>)[<span class="ruby-value">0</span>]
273
- 80: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
274
- 81: }
275
- 82: <span class="ruby-keyword kw">end</span>
365
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 78</span>
366
+ 78: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">tinyurl</span>(<span class="ruby-identifier">url</span>)
367
+ 79: <span class="ruby-identifier">get_short_url</span>(<span class="ruby-value str">&quot;tinyurl.com&quot;</span>, <span class="ruby-value">200</span>,
368
+ 80: <span class="ruby-node">&quot;post('/create.php', 'url=#{url}')&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span>
369
+ 81: <span class="ruby-identifier">line</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/hidden name=tinyurl/</span> }
370
+ 82: <span class="ruby-identifier">short_url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">line</span>)[<span class="ruby-value">0</span>]
371
+ 83: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">short_url</span>
372
+ 84: }
373
+ 85: <span class="ruby-keyword kw">end</span>
276
374
  </pre>
277
375
  </div>
278
376
  </div>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Thu Jun 02 18:25:20 EDT 2005
1
+ Fri Jun 03 21:04:57 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>Thu Jun 02 17:27:57 EDT 2005</td>
59
+ <td>Fri Jun 03 20:59:42 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,6 +70,12 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
+ 0.2.0:
74
+ </p>
75
+ <pre>
76
+ - Added shorl.com, snipurl.com and metamark.net
77
+ </pre>
78
+ <p>
73
79
  0.1.0:
74
80
  </p>
75
81
  <pre>
@@ -84,7 +90,7 @@
84
90
  0.0.1:
85
91
  </p>
86
92
  <pre>
87
- - Initial Version
93
+ - Initial release
88
94
  </pre>
89
95
 
90
96
  </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>Thu Jun 02 18:25:07 EDT 2005</td>
59
+ <td>Fri Jun 03 21:01:00 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -88,6 +88,26 @@ call-seq:
88
88
  puts ShortURL.shorten(&quot;http://mypage.com&quot;)
89
89
  puts ShortURL.shorten(&quot;http://mypage.com&quot;, :tinyurl)
90
90
  </pre>
91
+ <p>
92
+ The second parameter represents the service you want to use. These are:
93
+ </p>
94
+ <ul>
95
+ <li><tt>:rubyurl</tt>
96
+
97
+ </li>
98
+ <li><tt>:tinyurl</tt>
99
+
100
+ </li>
101
+ <li><tt>:snorl</tt>
102
+
103
+ </li>
104
+ <li><tt>:snipurl</tt>
105
+
106
+ </li>
107
+ <li><tt>:metamark</tt>
108
+
109
+ </li>
110
+ </ul>
91
111
  <h2>Thanks</h2>
92
112
  <ul>
93
113
  <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>Thu Jun 02 18:23:38 EDT 2005</td>
59
+ <td>Fri Jun 03 21:03:56 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -21,8 +21,11 @@
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
23
  <a href="classes/ShortURL.html#M000002">get_short_url (ShortURL)</a><br />
24
+ <a href="classes/ShortURL.html#M000007">metamark (ShortURL)</a><br />
24
25
  <a href="classes/ShortURL.html#M000003">rubyurl (ShortURL)</a><br />
26
+ <a href="classes/ShortURL.html#M000005">shorl (ShortURL)</a><br />
25
27
  <a href="classes/ShortURL.html#M000001">shorten (ShortURL)</a><br />
28
+ <a href="classes/ShortURL.html#M000006">snipurl (ShortURL)</a><br />
26
29
  <a href="classes/ShortURL.html#M000004">tinyurl (ShortURL)</a><br />
27
30
  </div>
28
31
  </div>
data/lib/shorturl.rb CHANGED
@@ -27,6 +27,9 @@ class ShortURL
27
27
  case service
28
28
  when :rubyurl then rubyurl(url)
29
29
  when :tinyurl then tinyurl(url)
30
+ when :shorl then shorl(url)
31
+ when :snipurl then snipurl(url)
32
+ when :metamark then metamark(url)
30
33
  else raise ArgumentError, "Invalid service"
31
34
  end
32
35
  end
@@ -81,5 +84,35 @@ class ShortURL
81
84
  }
82
85
  end
83
86
 
84
- private_class_method :get_short_url, :tinyurl, :rubyurl
87
+ # Shorten a URL through with shorl.com. Same technique as TinyURL
88
+ def self.shorl(url)
89
+ get_short_url("shorl.com", 200,
90
+ "post('/create.php', 'url=#{url}')") { |body|
91
+ short_url = URI.extract(body)[2]
92
+ return short_url
93
+ }
94
+ end
95
+
96
+ # Shorten a URL with snipurl.com. Same technique as TinyURL
97
+ def self.snipurl(url)
98
+ get_short_url("snipurl.com", 200,
99
+ "post('/index.php', 'link=#{url}')") { |body|
100
+ line = body.split("\n").grep(/txt/)[0]
101
+ short_url = URI.extract(line)[1][0..-2] # Remove trailing '
102
+ return short_url
103
+ }
104
+ end
105
+
106
+ # Shorten a URL with metamark.com. Same technique as TinyURL
107
+ def self.metamark(url)
108
+ get_short_url("metamark.net", 200,
109
+ "post('/add', 'long_url=#{url}')") { |body|
110
+ line = body.split("\n").find { |l| l =~ /xrl\.us/ }
111
+ short_url = URI.extract(line)[0]
112
+ return short_url
113
+ }
114
+ end
115
+
116
+ private_class_method(:get_short_url, :tinyurl, :rubyurl, :shorl,
117
+ :snipurl, :metamark)
85
118
  end
data/test/tc_shorturl.rb CHANGED
@@ -24,6 +24,13 @@ class TestShortURL < Test::Unit::TestCase
24
24
  assert ShortURL.shorten(@url) == "http://rubyurl.com/Q9ToW"
25
25
  assert ShortURL.shorten(@url, :rubyurl) == "http://rubyurl.com/Q9ToW"
26
26
  assert ShortURL.shorten(@url, :tinyurl) == "http://tinyurl.com/9mop8"
27
+
28
+ # The short URL for shorl is never the same, so I just check to
29
+ # see if the URL begins with their domain name
30
+ assert ShortURL.shorten(@url, :shorl) =~ /^http:\/\/shorl.com\//
31
+ assert ShortURL.shorten(@url, :snipurl) == "http://snipurl.com/fbkl"
32
+ assert ShortURL.shorten(@url, :metamark) == "http://xrl.us/ga8c"
33
+
27
34
  assert_raise(ArgumentError) { ShortURL.shorten(@url, :foobar) }
28
35
  end
29
36
 
@@ -57,4 +64,16 @@ class TestShortURL < Test::Unit::TestCase
57
64
  def test_tinyurl
58
65
  assert_raise(NoMethodError) { ShortURL.tinyurl(@url) }
59
66
  end
67
+
68
+ def test_shorl
69
+ assert_raise(NoMethodError) { ShortURL.shorl(@url) }
70
+ end
71
+
72
+ def test_snipurl
73
+ assert_raise(NoMethodError) { ShortURL.snipurl(@url) }
74
+ end
75
+
76
+ def test_metamark
77
+ assert_raise(NoMethodError) { ShortURL.metamark(@url) }
78
+ end
60
79
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: shorturl
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2005-06-02
6
+ version: 0.2.0
7
+ date: 2005-06-03
8
8
  summary: Shortens URLs using services such as TinyURL and RubyURL
9
9
  require_paths:
10
10
  - lib