shorturl 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,24 +1,38 @@
1
+ 0.5.0:
2
+ - Added two services: fyad.org and ln-s.net (thanks to Daniel
3
+ Dipaolo)
4
+ - Added an property to the Service class: args. This allows to give
5
+ additional arguments to services using the GET method (this was
6
+ needed by ln-s.net)
7
+ - Added a method to Hash to convert to an HTML arguments style
8
+ - Added a script called "shorturl" (duh) in the bin directory for
9
+ usage from the command line.
10
+
1
11
  0.4.0:
2
- - Added minilink.org
3
- - More tests for the Service class
4
- - Changed the ArgumentError exception for an InvalidService exception in ShortURL.shorten
5
- - Created examples/shorten.rb
6
- - Added a stats task to the Rakefile. Requires code_statistics, provided by Rails.
12
+ - Added minilink.org
13
+ - More tests for the Service class
14
+ - Changed the ArgumentError exception for an InvalidService exception in ShortURL.shorten
15
+ - Created examples/shorten.rb
16
+ - Added a stats task to the Rakefile. Requires code_statistics, provided by Rails.
17
+
7
18
  0.3.0:
8
- - Added linktrim.com and shorterlink.com
9
- - Replaced get_short_url and all the private class methods in favor of a Service class, which makes things clearer
19
+ - Added linktrim.com and shorterlink.com
20
+ - Replaced get_short_url and all the private class methods in favor of a Service class, which makes things clearer
21
+
10
22
  0.2.1:
11
- - Added makeashorterlink.com and skinnylink.com
12
- - Refactored get_short_url
23
+ - Added makeashorterlink.com and skinnylink.com
24
+ - Refactored get_short_url
25
+
13
26
  0.2.0:
14
- - Added shorl.com, snipurl.com and metamark.net
27
+ - Added shorl.com, snipurl.com and metamark.net
28
+
15
29
  0.1.0:
16
- - Refactored the tinyurl and rubyurl methods
17
- - URI.extract to get URLs instead of regular expressions
18
- - Added exception handling to get_short_url to return nil in case
19
- of a network error
20
- - More thorough unit tests
21
- - Made tinyurl, rubyurl and get_short_url private class methods
30
+ - Refactored the tinyurl and rubyurl methods
31
+ - URI.extract to get URLs instead of regular expressions
32
+ - Added exception handling to get_short_url to return nil in case
33
+ of a network error
34
+ - More thorough unit tests
35
+ - Made tinyurl, rubyurl and get_short_url private class methods
22
36
 
23
37
  0.0.1:
24
- - Initial release
38
+ - Initial release
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = ShortURL
1
+ = ShortURL 0.5.0
2
2
 
3
3
  == Summary
4
4
  ShortURL is a very simple library to use URL shortening services such as
@@ -28,8 +28,10 @@ The second parameter represents the service you want to use. These are:
28
28
  - <tt>:linktrim</tt>
29
29
  - <tt>:shorterlink</tt>
30
30
  - <tt>:minilink</tt>
31
+ - <tt>:lns</tt>
32
+ - <tt>:fyad</tt>
31
33
 
32
- Note that you can use <tt>ShortURL.valid_services</tt> to obtain a
34
+ You can use <tt>ShortURL.valid_services</tt> to obtain a
33
35
  list of the valid services (in case I forget to update the
34
36
  documentation)
35
37
 
@@ -37,6 +39,7 @@ documentation)
37
39
  - Marcel Molina Jr., Devin Mullins for some ideas
38
40
  - imperator from #ruby-lang (don't know your real name, sorry) for
39
41
  helping me with creating and uploading a RubyGem
42
+ - Daniel Dipaolo for telling me about ln-s.net and fyad.org
40
43
 
41
44
  == Author
42
45
  Vincent Foley
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
1
  = Todo
2
2
 
3
- * Check out WWW::Mecanize
3
+ * Add more services
4
+ * Get input from people about what I should do
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "shorturl"
5
+
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)
11
+ end
12
+
13
+ def main
14
+ if ARGV.size < 1
15
+ usage
16
+ end
17
+
18
+ url = ARGV[0]
19
+ service = ARGV[1]
20
+
21
+ shorturl = if service.nil?
22
+ ShortURL.shorten(url)
23
+ 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
30
+ end
31
+
32
+ puts shorturl
33
+
34
+ end
35
+
36
+ main
@@ -0,0 +1,155 @@
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>
@@ -86,8 +86,8 @@
86
86
  <h3 class="section-bar">Methods</h3>
87
87
 
88
88
  <div class="name-list">
89
- <a href="#M000004">call</a>&nbsp;&nbsp;
90
- <a href="#M000003">new</a>&nbsp;&nbsp;
89
+ <a href="#M000005">call</a>&nbsp;&nbsp;
90
+ <a href="#M000004">new</a>&nbsp;&nbsp;
91
91
  </div>
92
92
  </div>
93
93
 
@@ -112,6 +112,11 @@
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>
115
120
  <tr class="top-aligned-row context-row">
116
121
  <td class="context-item-name">block</td>
117
122
  <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
@@ -147,11 +152,11 @@
147
152
  <div id="methods">
148
153
  <h3 class="section-bar">Public Class methods</h3>
149
154
 
150
- <div id="method-M000003" class="method-detail">
151
- <a name="M000003"></a>
155
+ <div id="method-M000004" class="method-detail">
156
+ <a name="M000004"></a>
152
157
 
153
158
  <div class="method-heading">
154
- <a href="#M000003" class="method-signature">
159
+ <a href="#M000004" class="method-signature">
155
160
  <span class="method-name">new</span><span class="method-args">(hostname) {|service| ...}</span>
156
161
  </a>
157
162
  </div>
@@ -161,26 +166,28 @@
161
166
  Intialize the service with a hostname (required parameter) and you can
162
167
  override the default values for the HTTP port, expected HTTP return code,
163
168
  the form method to use, the form action, the form field which contains the
164
- long URL and the block of what to do with the HTML code you get.
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.
165
171
  </p>
166
172
  <p><a class="source-toggle" href="#"
167
- onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
168
- <div class="method-source-code" id="M000003-source">
173
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
174
+ <div class="method-source-code" id="M000004-source">
169
175
  <pre>
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>
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>
184
191
  </pre>
185
192
  </div>
186
193
  </div>
@@ -188,11 +195,11 @@ long URL and the block of what to do with the HTML code you get.
188
195
 
189
196
  <h3 class="section-bar">Public Instance methods</h3>
190
197
 
191
- <div id="method-M000004" class="method-detail">
192
- <a name="M000004"></a>
198
+ <div id="method-M000005" class="method-detail">
199
+ <a name="M000005"></a>
193
200
 
194
201
  <div class="method-heading">
195
- <a href="#M000004" class="method-signature">
202
+ <a href="#M000005" class="method-signature">
196
203
  <span class="method-name">call</span><span class="method-args">(url)</span>
197
204
  </a>
198
205
  </div>
@@ -203,21 +210,21 @@ Now that our service is set up, call it with all the parameters to
203
210
  (hopefully) return only the shortened URL.
204
211
  </p>
205
212
  <p><a class="source-toggle" href="#"
206
- onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
207
- <div class="method-source-code" id="M000004-source">
213
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
214
+ <div class="method-source-code" id="M000005-source">
208
215
  <pre>
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>
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>
221
228
  </pre>
222
229
  </div>
223
230
  </div>
@@ -171,14 +171,14 @@ call-seq:
171
171
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
172
172
  <div class="method-source-code" id="M000002-source">
173
173
  <pre>
174
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 148</span>
175
- 148: <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
- 149: <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
- 150: <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
- 151: <span class="ruby-keyword kw">else</span>
179
- 152: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidService</span>
180
- 153: <span class="ruby-keyword kw">end</span>
181
- 154: <span class="ruby-keyword kw">end</span>
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>
182
182
  </pre>
183
183
  </div>
184
184
  </div>
@@ -201,10 +201,10 @@ Returns @@<a href="ShortURL.html#M000001">valid_services</a>
201
201
  onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
202
202
  <div class="method-source-code" id="M000001-source">
203
203
  <pre>
204
- <span class="ruby-comment cmt"># File lib/shorturl.rb, line 123</span>
205
- 123: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">valid_services</span>
206
- 124: <span class="ruby-ivar">@@valid_services</span>
207
- 125: <span class="ruby-keyword kw">end</span>
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>
208
208
  </pre>
209
209
  </div>
210
210
  </div>
@@ -1 +1 @@
1
- Tue Jun 07 15:30:52 EDT 2005
1
+ Wed Jun 29 01:54:03 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>Tue Jun 07 15:30:33 EDT 2005</td>
59
+ <td>Wed Jun 29 01:52:05 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,51 +70,64 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
+ 0.5.0:
74
+ </p>
75
+ <pre>
76
+ - Added two services: fyad.org and ln-s.net (thanks to Daniel
77
+ Dipaolo)
78
+ - Added an property to the Service class: args. This allows to give
79
+ additional arguments to services using the GET method (this was
80
+ needed by ln-s.net)
81
+ - Added a method to Hash to convert to an HTML arguments style
82
+ - Added a script called &quot;shorturl&quot; (duh) in the bin directory for
83
+ usage from the command line.
84
+ </pre>
85
+ <p>
73
86
  0.4.0:
74
87
  </p>
75
88
  <pre>
76
- - Added minilink.org
77
- - More tests for the Service class
78
- - Changed the ArgumentError exception for an InvalidService exception in ShortURL.shorten
79
- - Created examples/shorten.rb
80
- - Added a stats task to the Rakefile. Requires code_statistics, provided by Rails.
89
+ - Added minilink.org
90
+ - More tests for the Service class
91
+ - Changed the ArgumentError exception for an InvalidService exception in ShortURL.shorten
92
+ - Created examples/shorten.rb
93
+ - Added a stats task to the Rakefile. Requires code_statistics, provided by Rails.
81
94
  </pre>
82
95
  <p>
83
96
  0.3.0:
84
97
  </p>
85
98
  <pre>
86
- - Added linktrim.com and shorterlink.com
87
- - Replaced get_short_url and all the private class methods in favor of a Service class, which makes things clearer
99
+ - Added linktrim.com and shorterlink.com
100
+ - Replaced get_short_url and all the private class methods in favor of a Service class, which makes things clearer
88
101
  </pre>
89
102
  <p>
90
103
  0.2.1:
91
104
  </p>
92
105
  <pre>
93
- - Added makeashorterlink.com and skinnylink.com
94
- - Refactored get_short_url
106
+ - Added makeashorterlink.com and skinnylink.com
107
+ - Refactored get_short_url
95
108
  </pre>
96
109
  <p>
97
110
  0.2.0:
98
111
  </p>
99
112
  <pre>
100
- - Added shorl.com, snipurl.com and metamark.net
113
+ - Added shorl.com, snipurl.com and metamark.net
101
114
  </pre>
102
115
  <p>
103
116
  0.1.0:
104
117
  </p>
105
118
  <pre>
106
- - Refactored the tinyurl and rubyurl methods
107
- - URI.extract to get URLs instead of regular expressions
108
- - Added exception handling to get_short_url to return nil in case
109
- of a network error
110
- - More thorough unit tests
111
- - Made tinyurl, rubyurl and get_short_url private class methods
119
+ - Refactored the tinyurl and rubyurl methods
120
+ - URI.extract to get URLs instead of regular expressions
121
+ - Added exception handling to get_short_url to return nil in case
122
+ of a network error
123
+ - More thorough unit tests
124
+ - Made tinyurl, rubyurl and get_short_url private class methods
112
125
  </pre>
113
126
  <p>
114
127
  0.0.1:
115
128
  </p>
116
129
  <pre>
117
- - Initial release
130
+ - Initial release
118
131
  </pre>
119
132
 
120
133
  </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 01 08:34:05 EDT 2005</td>
59
+ <td>Wed Jun 29 00:31:55 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>Tue Jun 07 01:17:24 EDT 2005</td>
59
+ <td>Wed Jun 29 01:53:41 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></h1>
72
+ <h1><a href="../classes/ShortURL.html">ShortURL</a> 0.5.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
@@ -127,10 +127,16 @@ The second parameter represents the service you want to use. These are:
127
127
  </li>
128
128
  <li><tt>:minilink</tt>
129
129
 
130
+ </li>
131
+ <li><tt>:lns</tt>
132
+
133
+ </li>
134
+ <li><tt>:fyad</tt>
135
+
130
136
  </li>
131
137
  </ul>
132
138
  <p>
133
- Note that you can use <tt><a
139
+ You can use <tt><a
134
140
  href="../classes/ShortURL.html#M000001">ShortURL.valid_services</a></tt> to
135
141
  obtain a list of the valid services (in case I forget to update the
136
142
  documentation)
@@ -143,6 +149,9 @@ documentation)
143
149
  <li>imperator from ruby-lang (don&#8217;t know your real name, sorry) for
144
150
  helping me with creating and uploading a RubyGem
145
151
 
152
+ </li>
153
+ <li>Daniel Dipaolo for telling me about ln-s.net and fyad.org
154
+
146
155
  </li>
147
156
  </ul>
148
157
  <h2>Author</h2>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jun 05 23:59:51 EDT 2005</td>
59
+ <td>Wed Jun 29 01:39:21 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -71,7 +71,10 @@
71
71
  <div id="description">
72
72
  <h1>Todo</h1>
73
73
  <ul>
74
- <li>Check out WWW::Mecanize
74
+ <li>Add more services
75
+
76
+ </li>
77
+ <li>Get input from people about what I should do
75
78
 
76
79
  </li>
77
80
  </ul>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jun 07 15:20:28 EDT 2005</td>
59
+ <td>Wed Jun 29 01:03:40 EDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -20,6 +20,7 @@
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 />
23
24
  <a href="classes/InvalidService.html">InvalidService</a><br />
24
25
  <a href="classes/Service.html">Service</a><br />
25
26
  <a href="classes/ShortURL.html">ShortURL</a><br />
@@ -20,9 +20,10 @@
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#M000004">call (Service)</a><br />
24
- <a href="classes/Service.html#M000003">new (Service)</a><br />
23
+ <a href="classes/Service.html#M000005">call (Service)</a><br />
24
+ <a href="classes/Service.html#M000004">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 />
26
27
  <a href="classes/ShortURL.html#M000001">valid_services (ShortURL)</a><br />
27
28
  </div>
28
29
  </div>
@@ -7,17 +7,31 @@ 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
+
10
23
  class InvalidService < Exception
11
24
  end
12
25
 
13
26
  class Service
14
- attr_accessor :port, :code, :method, :action, :field, :block
27
+ attr_accessor :port, :code, :method, :action, :field, :args, :block
15
28
 
16
29
  # Intialize the service with a hostname (required parameter) and you
17
30
  # can override the default values for the HTTP port, expected HTTP
18
31
  # return code, the form method to use, the form action, the form
19
- # field which contains the long URL and the block of what to do with
20
- # the HTML code you get.
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.
21
35
  def initialize(hostname) # :yield: service
22
36
  @hostname = hostname
23
37
  @port = 80
@@ -25,6 +39,7 @@ class Service
25
39
  @method = :post
26
40
  @action = "/"
27
41
  @field = "url"
42
+ @args = {}
28
43
  @block = lambda { |body| }
29
44
 
30
45
  if block_given?
@@ -38,7 +53,7 @@ class Service
38
53
  Net::HTTP.start(@hostname, @port) { |http|
39
54
  response = case @method
40
55
  when :post: http.send(@method, @action, "#@field=#{url}")
41
- when :get: http.send(@method, "#@action?#@field=#{CGI.escape(url)}")
56
+ when :get: http.send(@method, "#@action?#@field=#{CGI.escape(url)}&#{@args.to_html_args}")
42
57
  end
43
58
  if response.code == @code.to_s
44
59
  @block.call(response.read_body)
@@ -113,6 +128,18 @@ class ShortURL
113
128
  :minilink => Service.new("minilink.org") { |s|
114
129
  s.method = :get
115
130
  s.block = lambda { |body| URI.extract(body)[-1] }
131
+ },
132
+
133
+ :lns => Service.new("ln-s.net") { |s|
134
+ 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] }
138
+ },
139
+
140
+ :fyad => Service.new("fyad.org") { |s|
141
+ s.method = :get
142
+ s.block = lambda { |body| URI.extract(body).grep(/fyad.org/)[2] }
116
143
  }
117
144
  }
118
145
  # Array containing symbols representing all the implemented URL
@@ -26,6 +26,8 @@ class TestShortURL < Test::Unit::TestCase
26
26
  assert ShortURL.shorten(@url, :linktrim) =~ /http:\/\/linktrim/ # Never the same URL
27
27
  assert ShortURL.shorten(@url, :shorterlink) == "http://shorterlink.com/?PQD096"
28
28
  assert ShortURL.shorten(@url, :minilink) == "http://lnk.nu/darkhost.mine.nu:81/2zr.html"
29
+ assert ShortURL.shorten(@url, :lns) == "http://ln-s.net/5UL"
30
+ assert ShortURL.shorten(@url, :fyad) == "http://fyad.org/15zu"
29
31
 
30
32
  assert_raise(InvalidService) { ShortURL.shorten(@url, :foobar) }
31
33
  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.4.0
7
- date: 2005-06-07
6
+ version: 0.5.0
7
+ date: 2005-06-29
8
8
  summary: Shortens URLs using services such as TinyURL and RubyURL
9
9
  require_paths:
10
10
  - lib
@@ -13,7 +13,7 @@ homepage: http://shorturl.rubyforge.org
13
13
  rubyforge_project:
14
14
  description:
15
15
  autorequire: shorturl
16
- default_executable:
16
+ default_executable: shorturl
17
17
  bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
@@ -27,24 +27,26 @@ platform: ruby
27
27
  authors:
28
28
  - Vincent Foley
29
29
  files:
30
+ - bin/shorturl
30
31
  - lib/shorturl.rb
31
- - doc/classes
32
32
  - doc/created.rid
33
+ - doc/rdoc-style.css
33
34
  - doc/files
34
- - doc/fr_class_index.html
35
+ - doc/classes
35
36
  - doc/fr_file_index.html
37
+ - doc/fr_class_index.html
36
38
  - doc/fr_method_index.html
37
39
  - doc/index.html
38
- - doc/rdoc-style.css
39
- - doc/classes/InvalidService.html
40
- - doc/classes/Service.html
41
- - doc/classes/ShortURL.html
42
- - doc/files/ChangeLog.html
43
- - doc/files/lib
44
- - doc/files/MIT-LICENSE.html
45
40
  - doc/files/README.html
46
41
  - doc/files/TODO.html
42
+ - doc/files/MIT-LICENSE.html
43
+ - doc/files/ChangeLog.html
44
+ - doc/files/lib
47
45
  - doc/files/lib/shorturl_rb.html
46
+ - doc/classes/ShortURL.html
47
+ - doc/classes/InvalidService.html
48
+ - doc/classes/Hash.html
49
+ - doc/classes/Service.html
48
50
  - test/tc_service.rb
49
51
  - test/tc_shorturl.rb
50
52
  - test/ts_all.rb
@@ -68,7 +70,8 @@ extra_rdoc_files:
68
70
  - TODO
69
71
  - MIT-LICENSE
70
72
  - ChangeLog
71
- executables: []
73
+ executables:
74
+ - shorturl
72
75
  extensions: []
73
76
  requirements: []
74
77
  dependencies: []