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 +5 -0
- data/README +6 -2
- data/doc/classes/Service.html +2 -2
- data/doc/classes/ShortURL.html +18 -12
- data/doc/created.rid +1 -1
- data/doc/files/ChangeLog.html +8 -1
- data/doc/files/MIT-LICENSE.html +1 -1
- data/doc/files/README.html +17 -5
- data/doc/files/TODO.html +1 -1
- data/doc/files/lib/shorturl_rb.html +1 -1
- data/lib/shorturl.rb +18 -6
- data/test/tc_shorturl.rb +13 -20
- metadata +14 -12
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= ShortURL 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
|
|
data/doc/classes/Service.html
CHANGED
@@ -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">
|
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">
|
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">"#{@field}=#{url}"</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">"#{@action}?#{@field}=#{CGI.escape(url)}"</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>)
|
data/doc/classes/ShortURL.html
CHANGED
@@ -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
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
1
|
+
Mon Sep 26 19:17:22 EDT 2005
|
data/doc/files/ChangeLog.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>
|
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>
|
data/doc/files/MIT-LICENSE.html
CHANGED
data/doc/files/README.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>
|
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.
|
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>:
|
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>:
|
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’t know your real name, sorry) for
|
228
|
+
<li>imperator from ruby-lang (I don’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
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.
|
41
|
-
when :get: http.
|
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
|
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://
|
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)
|
24
|
+
assert ShortURL.shorten(@url).url?
|
20
25
|
|
21
|
-
# All the services (
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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.
|
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.
|
7
|
-
date: 2005-
|
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/
|
41
|
-
- doc/
|
42
|
-
- doc/
|
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
|