shorturl 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 0.6.0:
2
+ - Changed the method for getting the URL for ln-s.net to use their
3
+ API. So basically, this means the new additional argument attribute
4
+ in the Service class is now useless, because no service uses it. I've
5
+ removed it along with the Hash#to_html_args method.
6
+ - Added d62.net, shiturl.com, littlink.com and clipurl.com
7
+
1
8
  0.5.0:
2
9
  - Added two services: fyad.org and ln-s.net (thanks to Daniel
3
10
  Dipaolo)
data/README CHANGED
@@ -11,6 +11,25 @@ ShortURL is available as a gem, installation is just like any other gem:
11
11
  You can also download the tar.bz2 archive at
12
12
  http://rubyforge.org/frs/?group_id=732 if you do not want to use the gem.
13
13
 
14
+ == Supported services
15
+ Here is the list of the services supported by ShortURL:
16
+ * http://rubyurl.com
17
+ * http://tinyurl.com
18
+ * http://shorl.com
19
+ * http://snipurl.com
20
+ * http://metamark.net
21
+ * http://makeashorterlink.com
22
+ * http://skinnylink.com
23
+ * http://linktrim.com
24
+ * http://shorterlink.com
25
+ * http://minilink.org
26
+ * http://ln-s.net
27
+ * http://fyad.org
28
+ * http://d62.net
29
+ * http://shiturl.com
30
+ * http://littlink.com
31
+ * http://clipurl.com
32
+
14
33
  == Usage:
15
34
  call-seq:
16
35
  require "shorturl"
@@ -18,18 +37,23 @@ call-seq:
18
37
  puts ShortURL.shorten("http://mypage.com", :tinyurl)
19
38
 
20
39
  The second parameter represents the service you want to use. These are:
21
- - <tt>:rubyurl</tt>
22
- - <tt>:tinyurl</tt>
23
- - <tt>:snorl</tt>
24
- - <tt>:snipurl</tt>
25
- - <tt>:metamark</tt>
26
- - <tt>:makeashorterlink</tt>
27
- - <tt>:skinnylink</tt>
28
- - <tt>:linktrim</tt>
29
- - <tt>:shorterlink</tt>
30
- - <tt>:minilink</tt>
31
- - <tt>:lns</tt>
32
- - <tt>:fyad</tt>
40
+ * <tt>:rubyurl</tt>
41
+ * <tt>:tinyurl</tt>
42
+ * <tt>:shorl</tt>
43
+ * <tt>:snipurl</tt>
44
+ * <tt>:metamark</tt>
45
+ * <tt>:makeashorterlink</tt>
46
+ * <tt>:skinnylink</tt>
47
+ * <tt>:linktrim</tt>
48
+ * <tt>:shorterlink</tt>
49
+ * <tt>:minlink</tt>
50
+ * <tt>:lns</tt>
51
+ * <tt>:fyad</tt>
52
+ * <tt>:d62</tt>
53
+ * <tt>:shiturl</tt>
54
+ * <tt>:littlink</tt>
55
+ * <tt>:clipurl</tt>
56
+
33
57
 
34
58
  You can use <tt>ShortURL.valid_services</tt> to obtain a
35
59
  list of the valid services (in case I forget to update the
@@ -86,8 +86,8 @@
86
86
  <h3 class="section-bar">Methods</h3>
87
87
 
88
88
  <div class="name-list">
89
- <a href="#M000005">call</a>&nbsp;&nbsp;
90
- <a href="#M000004">new</a>&nbsp;&nbsp;
89
+ <a href="#M000004">call</a>&nbsp;&nbsp;
90
+ <a href="#M000003">new</a>&nbsp;&nbsp;
91
91
  </div>
92
92
  </div>
93
93
 
@@ -112,11 +112,6 @@
112
112
  <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
113
113
  <td class="context-item-desc"></td>
114
114
  </tr>
115
- <tr class="top-aligned-row context-row">
116
- <td class="context-item-name">args</td>
117
- <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
118
- <td class="context-item-desc"></td>
119
- </tr>
120
115
  <tr class="top-aligned-row context-row">
121
116
  <td class="context-item-name">block</td>
122
117
  <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
@@ -152,11 +147,11 @@
152
147
  <div id="methods">
153
148
  <h3 class="section-bar">Public Class methods</h3>
154
149
 
155
- <div id="method-M000004" class="method-detail">
156
- <a name="M000004"></a>
150
+ <div id="method-M000003" class="method-detail">
151
+ <a name="M000003"></a>
157
152
 
158
153
  <div class="method-heading">
159
- <a href="#M000004" class="method-signature">
154
+ <a href="#M000003" class="method-signature">
160
155
  <span class="method-name">new</span><span class="method-args">(hostname) {|service| ...}</span>
161
156
  </a>
162
157
  </div>
@@ -166,28 +161,26 @@
166
161
  Intialize the service with a hostname (required parameter) and you can
167
162
  override the default values for the HTTP port, expected HTTP return code,
168
163
  the form method to use, the form action, the form field which contains the
169
- long URL, optional additional arguments to send to a GET method and the
170
- block of what to do with the HTML code you get.
164
+ long URL, and the block of what to do with the HTML code you get.
171
165
  </p>
172
166
  <p><a class="source-toggle" href="#"
173
- onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
174
- <div class="method-source-code" id="M000004-source">
167
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
168
+ <div class="method-source-code" id="M000003-source">
175
169
  <pre>
176
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 35</span>
177
- 35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-comment cmt"># :yield: service</span>
178
- 36: <span class="ruby-ivar">@hostname</span> = <span class="ruby-identifier">hostname</span>
179
- 37: <span class="ruby-ivar">@port</span> = <span class="ruby-value">80</span>
180
- 38: <span class="ruby-ivar">@code</span> = <span class="ruby-value">200</span>
181
- 39: <span class="ruby-ivar">@method</span> = <span class="ruby-identifier">:post</span>
182
- 40: <span class="ruby-ivar">@action</span> = <span class="ruby-value str">&quot;/&quot;</span>
183
- 41: <span class="ruby-ivar">@field</span> = <span class="ruby-value str">&quot;url&quot;</span>
184
- 42: <span class="ruby-ivar">@args</span> = {}
185
- 43: <span class="ruby-ivar">@block</span> = <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span> }
186
- 44:
187
- 45: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
188
- 46: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
189
- 47: <span class="ruby-keyword kw">end</span>
190
- 48: <span class="ruby-keyword kw">end</span>
170
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 21</span>
171
+ 21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-comment cmt"># :yield: service</span>
172
+ 22: <span class="ruby-ivar">@hostname</span> = <span class="ruby-identifier">hostname</span>
173
+ 23: <span class="ruby-ivar">@port</span> = <span class="ruby-value">80</span>
174
+ 24: <span class="ruby-ivar">@code</span> = <span class="ruby-value">200</span>
175
+ 25: <span class="ruby-ivar">@method</span> = <span class="ruby-identifier">:post</span>
176
+ 26: <span class="ruby-ivar">@action</span> = <span class="ruby-value str">&quot;/&quot;</span>
177
+ 27: <span class="ruby-ivar">@field</span> = <span class="ruby-value str">&quot;url&quot;</span>
178
+ 28: <span class="ruby-ivar">@block</span> = <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">body</span><span class="ruby-operator">|</span> }
179
+ 29:
180
+ 30: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
181
+ 31: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
182
+ 32: <span class="ruby-keyword kw">end</span>
183
+ 33: <span class="ruby-keyword kw">end</span>
191
184
  </pre>
192
185
  </div>
193
186
  </div>
@@ -195,11 +188,11 @@ block of what to do with the HTML code you get.
195
188
 
196
189
  <h3 class="section-bar">Public Instance methods</h3>
197
190
 
198
- <div id="method-M000005" class="method-detail">
199
- <a name="M000005"></a>
191
+ <div id="method-M000004" class="method-detail">
192
+ <a name="M000004"></a>
200
193
 
201
194
  <div class="method-heading">
202
- <a href="#M000005" class="method-signature">
195
+ <a href="#M000004" class="method-signature">
203
196
  <span class="method-name">call</span><span class="method-args">(url)</span>
204
197
  </a>
205
198
  </div>
@@ -210,21 +203,21 @@ Now that our service is set up, call it with all the parameters to
210
203
  (hopefully) return only the shortened URL.
211
204
  </p>
212
205
  <p><a class="source-toggle" href="#"
213
- onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
214
- <div class="method-source-code" id="M000005-source">
206
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
207
+ <div class="method-source-code" id="M000004-source">
215
208
  <pre>
216
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 52</span>
217
- 52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
218
- 53: <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>
219
- 54: <span class="ruby-identifier">response</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@method</span>
220
- 55: <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>)
221
- 56: <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)}&amp;#{@args.to_html_args}&quot;</span>)
222
- 57: <span class="ruby-keyword kw">end</span>
223
- 58: <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>
224
- 59: <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>)
225
- 60: <span class="ruby-keyword kw">end</span>
226
- 61: }
227
- 62: <span class="ruby-keyword kw">end</span>
209
+ <span class="ruby-comment cmt"># File lib/shorturl.rb, line 37</span>
210
+ 37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
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
+ 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>)
215
+ 42: <span class="ruby-keyword kw">end</span>
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>
228
221
  </pre>
229
222
  </div>
230
223
  </div>
@@ -158,6 +158,24 @@ Valid <tt>service</tt> values:
158
158
  </li>
159
159
  <li><tt>:minlink</tt>
160
160
 
161
+ </li>
162
+ <li><tt>:lns</tt>
163
+
164
+ </li>
165
+ <li><tt>:fyad</tt>
166
+
167
+ </li>
168
+ <li><tt>:d62</tt>
169
+
170
+ </li>
171
+ <li><tt>:shiturl</tt>
172
+
173
+ </li>
174
+ <li><tt>:littlink</tt>
175
+
176
+ </li>
177
+ <li><tt>:clipurl</tt>
178
+
161
179
  </li>
162
180
  </ul>
163
181
  <p>
@@ -171,14 +189,14 @@ call-seq:
171
189
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
172
190
  <div class="method-source-code" id="M000002-source">
173
191
  <pre>
174
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 175</span>
175
- 175: <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>)
176
- 176: <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>
177
- 177: <span class="ruby-ivar">@@services</span>[<span class="ruby-identifier">service</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">url</span>)
178
- 178: <span class="ruby-keyword kw">else</span>
179
- 179: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidService</span>
180
- 180: <span class="ruby-keyword kw">end</span>
181
- 181: <span class="ruby-keyword kw">end</span>
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>
182
200
  </pre>
183
201
  </div>
184
202
  </div>
@@ -201,10 +219,10 @@ Returns @@<a href="ShortURL.html#M000001">valid_services</a>
201
219
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
202
220
  <div class="method-source-code" id="M000001-source">
203
221
  <pre>
204
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 150</span>
205
- 150: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">valid_services</span>
206
- 151: <span class="ruby-ivar">@@valid_services</span>
207
- 152: <span class="ruby-keyword kw">end</span>
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>
208
226
  </pre>
209
227
  </div>
210
228
  </div>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Wed Jun 29 01:54:03 EDT 2005
1
+ Wed Jun 29 21:33:29 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 01:52:05 EDT 2005</td>
59
+ <td>Wed Jun 29 21:28:47 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,6 +70,16 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
+ 0.6.0:
74
+ </p>
75
+ <pre>
76
+ - Changed the method for getting the URL for ln-s.net to use their
77
+ API. So basically, this means the new additional argument attribute
78
+ in the Service class is now useless, because no service uses it. I've
79
+ removed it along with the Hash#to_html_args method.
80
+ - Added d62.net, shiturl.com, littlink.com and clipurl.com
81
+ </pre>
82
+ <p>
73
83
  0.5.0:
74
84
  </p>
75
85
  <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 01:53:41 EDT 2005</td>
59
+ <td>Wed Jun 29 21:33:23 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -85,6 +85,61 @@ You can also download the tar.bz2 archive at <a
85
85
  href="http://rubyforge.org/frs/?group_id=732">rubyforge.org/frs/?group_id=732</a>
86
86
  if you do not want to use the gem.
87
87
  </p>
88
+ <h2>Supported services</h2>
89
+ <p>
90
+ Here is the list of the services supported by <a
91
+ href="../classes/ShortURL.html">ShortURL</a>:
92
+ </p>
93
+ <ul>
94
+ <li><a href="http://rubyurl.com">rubyurl.com</a>
95
+
96
+ </li>
97
+ <li><a href="http://tinyurl.com">tinyurl.com</a>
98
+
99
+ </li>
100
+ <li><a href="http://shorl.com">shorl.com</a>
101
+
102
+ </li>
103
+ <li><a href="http://snipurl.com">snipurl.com</a>
104
+
105
+ </li>
106
+ <li><a href="http://metamark.net">metamark.net</a>
107
+
108
+ </li>
109
+ <li><a href="http://makeashorterlink.com">makeashorterlink.com</a>
110
+
111
+ </li>
112
+ <li><a href="http://skinnylink.com">skinnylink.com</a>
113
+
114
+ </li>
115
+ <li><a href="http://linktrim.com">linktrim.com</a>
116
+
117
+ </li>
118
+ <li><a href="http://shorterlink.com">shorterlink.com</a>
119
+
120
+ </li>
121
+ <li><a href="http://minilink.org">minilink.org</a>
122
+
123
+ </li>
124
+ <li><a href="http://ln-s.net">ln-s.net</a>
125
+
126
+ </li>
127
+ <li><a href="http://fyad.org">fyad.org</a>
128
+
129
+ </li>
130
+ <li><a href="http://d62.net">d62.net</a>
131
+
132
+ </li>
133
+ <li><a href="http://shiturl.com">shiturl.com</a>
134
+
135
+ </li>
136
+ <li><a href="http://littlink.com">littlink.com</a>
137
+
138
+ </li>
139
+ <li><a href="http://clipurl.com">clipurl.com</a>
140
+
141
+ </li>
142
+ </ul>
88
143
  <h2>Usage:</h2>
89
144
  <p>
90
145
  call-seq:
@@ -133,6 +188,18 @@ The second parameter represents the service you want to use. These are:
133
188
  </li>
134
189
  <li><tt>:fyad</tt>
135
190
 
191
+ </li>
192
+ <li><tt>:d62</tt>
193
+
194
+ </li>
195
+ <li><tt>:shiturl</tt>
196
+
197
+ </li>
198
+ <li><tt>:littlink</tt>
199
+
200
+ </li>
201
+ <li><tt>:clipurl</tt>
202
+
136
203
  </li>
137
204
  </ul>
138
205
  <p>
@@ -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:03:40 EDT 2005</td>
59
+ <td>Wed Jun 29 21:27:27 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -20,7 +20,6 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Classes</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Hash.html">Hash</a><br />
24
23
  <a href="classes/InvalidService.html">InvalidService</a><br />
25
24
  <a href="classes/Service.html">Service</a><br />
26
25
  <a href="classes/ShortURL.html">ShortURL</a><br />
@@ -20,10 +20,9 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Service.html#M000005">call (Service)</a><br />
24
- <a href="classes/Service.html#M000004">new (Service)</a><br />
23
+ <a href="classes/Service.html#M000004">call (Service)</a><br />
24
+ <a href="classes/Service.html#M000003">new (Service)</a><br />
25
25
  <a href="classes/ShortURL.html#M000002">shorten (ShortURL)</a><br />
26
- <a href="classes/Hash.html#M000003">to_html_args (Hash)</a><br />
27
26
  <a href="classes/ShortURL.html#M000001">valid_services (ShortURL)</a><br />
28
27
  </div>
29
28
  </div>
data/lib/shorturl.rb CHANGED
@@ -7,31 +7,17 @@ require "net/http"
7
7
  require "cgi"
8
8
  require "uri"
9
9
 
10
- class Hash
11
- # Returns a string with the format key1=value1&key2=value2 for
12
- # usage in HTTP requests
13
- def to_html_args
14
- if self.empty?
15
- ""
16
- else
17
- args = self.collect { |k, v| "#{k}=#{CGI.escape(v)}" }
18
- args.join("&")
19
- end
20
- end
21
- end
22
-
23
10
  class InvalidService < Exception
24
11
  end
25
12
 
26
13
  class Service
27
- attr_accessor :port, :code, :method, :action, :field, :args, :block
14
+ attr_accessor :port, :code, :method, :action, :field, :block
28
15
 
29
16
  # Intialize the service with a hostname (required parameter) and you
30
17
  # can override the default values for the HTTP port, expected HTTP
31
18
  # return code, the form method to use, the form action, the form
32
- # field which contains the long URL, optional additional arguments
33
- # to send to a GET method and the block of what to do with the HTML
34
- # code you get.
19
+ # field which contains the long URL, and the block of what to do
20
+ # with the HTML code you get.
35
21
  def initialize(hostname) # :yield: service
36
22
  @hostname = hostname
37
23
  @port = 80
@@ -39,7 +25,6 @@ class Service
39
25
  @method = :post
40
26
  @action = "/"
41
27
  @field = "url"
42
- @args = {}
43
28
  @block = lambda { |body| }
44
29
 
45
30
  if block_given?
@@ -53,7 +38,7 @@ class Service
53
38
  Net::HTTP.start(@hostname, @port) { |http|
54
39
  response = case @method
55
40
  when :post: http.send(@method, @action, "#@field=#{url}")
56
- when :get: http.send(@method, "#@action?#@field=#{CGI.escape(url)}&#{@args.to_html_args}")
41
+ when :get: http.send(@method, "#@action?#@field=#{CGI.escape(url)}")
57
42
  end
58
43
  if response.code == @code.to_s
59
44
  @block.call(response.read_body)
@@ -132,14 +117,33 @@ class ShortURL
132
117
 
133
118
  :lns => Service.new("ln-s.net") { |s|
134
119
  s.method = :get
135
- s.action = "/home/index.jsp"
136
- s.args = { "submitted" => "true" }
137
- s.block = lambda { |body| URI.extract(body).grep(/ln-s/)[0] }
120
+ s.action = "/home/api.jsp"
121
+ s.block = lambda { |body| URI.extract(body)[0] }
138
122
  },
139
123
 
140
124
  :fyad => Service.new("fyad.org") { |s|
141
125
  s.method = :get
142
126
  s.block = lambda { |body| URI.extract(body).grep(/fyad.org/)[2] }
127
+ },
128
+
129
+ :d62 => Service.new("d62.net") { |s|
130
+ s.method = :get
131
+ s.block = lambda { |body| URI.extract(body)[0] }
132
+ },
133
+
134
+ :shiturl => Service.new("shiturl.com") { |s|
135
+ s.method = :get
136
+ s.action = "/make.php"
137
+ s.block = lambda { |body| URI.extract(body).grep(/shiturl/)[0] }
138
+ },
139
+
140
+ :littlink => Service.new("littlink.com") { |s|
141
+ s.block = lambda { |body| URI.extract(body).grep(/littlink/)[0] }
142
+ },
143
+
144
+ :clipurl => Service.new("clipurl.com") { |s|
145
+ s.action = "/create.asp"
146
+ s.block = lambda { |body| URI.extract(body).grep(/clipurl/)[0] }
143
147
  }
144
148
  }
145
149
  # Array containing symbols representing all the implemented URL
@@ -168,6 +172,12 @@ class ShortURL
168
172
  # * <tt>:linktrim</tt>
169
173
  # * <tt>:shorterlink</tt>
170
174
  # * <tt>:minlink</tt>
175
+ # * <tt>:lns</tt>
176
+ # * <tt>:fyad</tt>
177
+ # * <tt>:d62</tt>
178
+ # * <tt>:shiturl</tt>
179
+ # * <tt>:littlink</tt>
180
+ # * <tt>:clipurl</tt>
171
181
  #
172
182
  # call-seq:
173
183
  # ShortURL.shorten("http://mypage.com") => Uses RubyURL
data/test/tc_shorturl.rb CHANGED
@@ -15,7 +15,10 @@ class TestShortURL < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_shorten
18
+ # Default service (RubyURL)
18
19
  assert ShortURL.shorten(@url) == "http://rubyurl.com/Q9ToW"
20
+
21
+ # All the services (in the order in which they were added)
19
22
  assert ShortURL.shorten(@url, :rubyurl) == "http://rubyurl.com/Q9ToW"
20
23
  assert ShortURL.shorten(@url, :tinyurl) == "http://tinyurl.com/9mop8"
21
24
  assert ShortURL.shorten(@url, :shorl) =~ /^http:\/\/shorl.com/ # Never the same URL
@@ -28,7 +31,12 @@ class TestShortURL < Test::Unit::TestCase
28
31
  assert ShortURL.shorten(@url, :minilink) == "http://lnk.nu/darkhost.mine.nu:81/2zr.html"
29
32
  assert ShortURL.shorten(@url, :lns) == "http://ln-s.net/5UL"
30
33
  assert ShortURL.shorten(@url, :fyad) == "http://fyad.org/15zu"
31
-
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
+
39
+
32
40
  assert_raise(InvalidService) { ShortURL.shorten(@url, :foobar) }
33
41
  end
34
42
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: shorturl
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
6
+ version: 0.6.0
7
7
  date: 2005-06-29
8
8
  summary: Shortens URLs using services such as TinyURL and RubyURL
9
9
  require_paths:
@@ -45,7 +45,6 @@ files:
45
45
  - doc/files/lib/shorturl_rb.html
46
46
  - doc/classes/ShortURL.html
47
47
  - doc/classes/InvalidService.html
48
- - doc/classes/Hash.html
49
48
  - doc/classes/Service.html
50
49
  - test/tc_service.rb
51
50
  - test/tc_shorturl.rb
@@ -1,155 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: Hash</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">Hash</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/shorturl_rb.html">
59
- lib/shorturl.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Object
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
-
82
-
83
- </div>
84
-
85
- <div id="method-list">
86
- <h3 class="section-bar">Methods</h3>
87
-
88
- <div class="name-list">
89
- <a href="#M000003">to_html_args</a>&nbsp;&nbsp;
90
- </div>
91
- </div>
92
-
93
- </div>
94
-
95
-
96
- <!-- if includes -->
97
-
98
- <div id="section">
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
- <!-- if method_list -->
108
- <div id="methods">
109
- <h3 class="section-bar">Public Instance methods</h3>
110
-
111
- <div id="method-M000003" class="method-detail">
112
- <a name="M000003"></a>
113
-
114
- <div class="method-heading">
115
- <a href="#M000003" class="method-signature">
116
- <span class="method-name">to_html_args</span><span class="method-args">()</span>
117
- </a>
118
- </div>
119
-
120
- <div class="method-description">
121
- <p>
122
- Returns a string with the format key1=value1&amp;key2=value2 for usage in
123
- HTTP requests
124
- </p>
125
- <p><a class="source-toggle" href="#"
126
- onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
127
- <div class="method-source-code" id="M000003-source">
128
- <pre>
129
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 13</span>
130
- 13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_html_args</span>
131
- 14: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">empty?</span>
132
- 15: <span class="ruby-value str">&quot;&quot;</span>
133
- 16: <span class="ruby-keyword kw">else</span>
134
- 17: <span class="ruby-identifier">args</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{k}=#{CGI.escape(v)}&quot;</span> }
135
- 18: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;&amp;&quot;</span>)
136
- 19: <span class="ruby-keyword kw">end</span>
137
- 20: <span class="ruby-keyword kw">end</span>
138
- </pre>
139
- </div>
140
- </div>
141
- </div>
142
-
143
-
144
- </div>
145
-
146
-
147
- </div>
148
-
149
-
150
- <div id="validator-badges">
151
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
152
- </div>
153
-
154
- </body>
155
- </html>