Ridiculous 0.3
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/index.html +82 -0
- data/ridiculous.gemspec +23 -0
- data/ridiculous.rb +213 -0
- data/tests.rb +59 -0
- metadata +49 -0
data/index.html
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Ridiculous</title>
|
|
5
|
+
|
|
6
|
+
<style type="text/css">
|
|
7
|
+
body {
|
|
8
|
+
margin: 5px 5px 5px 5px;
|
|
9
|
+
font-family: 'Trebuchet MS', 'Lucida Grande', 'Bitstream Vera Sans', Tahoma, Sans-Serif;
|
|
10
|
+
}
|
|
11
|
+
h1 {
|
|
12
|
+
font-size: 12px;
|
|
13
|
+
text-transform: uppercase;
|
|
14
|
+
}
|
|
15
|
+
h2, h4 {
|
|
16
|
+
margin: 0px 0px 8px 0px;
|
|
17
|
+
}
|
|
18
|
+
h3 { margin: 10px 0px 8px 0px; }
|
|
19
|
+
pre { margin: 3px 0px 0px 0px; }
|
|
20
|
+
li { margin: 0px 0px 3px 0px; }
|
|
21
|
+
a, a:link, a:hover, a:visited, a:active { color: #000000 }
|
|
22
|
+
</style>
|
|
23
|
+
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
|
|
27
|
+
<h1>Ridiculous</h1>
|
|
28
|
+
<h2>Ridiculous is a simple wrapper for del.icio.us API writing in Ruby.</h2>
|
|
29
|
+
<br clear="all" />
|
|
30
|
+
|
|
31
|
+
<h3>try the latest stable version (0.3)</h3>
|
|
32
|
+
<ul>
|
|
33
|
+
<li><a href="http://rubyforge.org/frs/download.php/9464/ridiculous-0.3.tar.bz2">get the source code</a></li>
|
|
34
|
+
<li>install using RubyGems
|
|
35
|
+
<pre>$ gem install ridiculous</pre></li>
|
|
36
|
+
<li>get the latest development version (0.5) from subversion
|
|
37
|
+
<pre>$ svn co svn://rubyforge.org//var/svn/ridiculous</pre>
|
|
38
|
+
</li>
|
|
39
|
+
</ul>
|
|
40
|
+
<br clear="all" />
|
|
41
|
+
|
|
42
|
+
<h3>usage</h3>
|
|
43
|
+
|
|
44
|
+
<h4>Read the <a href="./doc">API documentation</a></h4>
|
|
45
|
+
|
|
46
|
+
<!--
|
|
47
|
+
<h4>posts</h4>
|
|
48
|
+
<pre>xx</pre>
|
|
49
|
+
|
|
50
|
+
<h4>tags</h4>
|
|
51
|
+
<pre>xx</pre>
|
|
52
|
+
-->
|
|
53
|
+
<br clear="all" />
|
|
54
|
+
|
|
55
|
+
<h3>license</h3>
|
|
56
|
+
<p><a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a></p>
|
|
57
|
+
<br clear="all" />
|
|
58
|
+
|
|
59
|
+
<h3>feedback</h3>
|
|
60
|
+
<p>Please, send your feedbacks to lupeke [ at ] gmail.com</p>
|
|
61
|
+
|
|
62
|
+
<br clear="all" />
|
|
63
|
+
|
|
64
|
+
<script type="text/javascript"><!--
|
|
65
|
+
google_ad_client = "pub-6740369207822774";
|
|
66
|
+
google_ad_width = 728;
|
|
67
|
+
google_ad_height = 90;
|
|
68
|
+
google_ad_format = "728x90_as";
|
|
69
|
+
google_ad_type = "text";
|
|
70
|
+
google_ad_channel ="";
|
|
71
|
+
google_color_border = "336699";
|
|
72
|
+
google_color_bg = "FFFFFF";
|
|
73
|
+
google_color_link = "0000FF";
|
|
74
|
+
google_color_url = "008000";
|
|
75
|
+
google_color_text = "000000";
|
|
76
|
+
//--></script>
|
|
77
|
+
<script type="text/javascript"
|
|
78
|
+
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
</body>
|
|
82
|
+
</html>
|
data/ridiculous.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
gemspec = Gem::Specification.new { |spec|
|
|
4
|
+
|
|
5
|
+
spec.name = 'Ridiculous'
|
|
6
|
+
spec.summary = 'Ridiculous is a simple wrapper for del.icio.us API writing in Ruby'
|
|
7
|
+
spec.version = '0.3'
|
|
8
|
+
|
|
9
|
+
spec.required_ruby_version = '>= 1.8'
|
|
10
|
+
spec.rubyforge_project = 'ridiculous'
|
|
11
|
+
|
|
12
|
+
spec.files = Dir.glob('*')
|
|
13
|
+
spec.files.reject! { |fn| fn.include? "doc" }
|
|
14
|
+
|
|
15
|
+
spec.test_file = 'tests.rb'
|
|
16
|
+
|
|
17
|
+
spec.has_rdoc = true
|
|
18
|
+
spec.homepage = 'http://ridiculous.rubyforge.org'
|
|
19
|
+
|
|
20
|
+
spec.author = 'Daniel Dias'
|
|
21
|
+
spec.email = 'lupeke@gmail.com'
|
|
22
|
+
|
|
23
|
+
}
|
data/ridiculous.rb
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Ridiculous is a simple wrapper for del.icio.us API writing in Ruby.
|
|
2
|
+
#
|
|
3
|
+
# Please, send your feedback to lupeke [[ at ]] gmail.com
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2006 Daniel Dias All rights reserved.
|
|
6
|
+
#
|
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
|
8
|
+
# modification, are permitted provided that the following conditions
|
|
9
|
+
# are met:
|
|
10
|
+
#
|
|
11
|
+
# 1. Redistributions of source code must retain the above copyright
|
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
|
13
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
|
16
|
+
# 3. The name of the author may not be used to endorse or promote products
|
|
17
|
+
# derived from this software without specific prior written permission.
|
|
18
|
+
#
|
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
20
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
21
|
+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
22
|
+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
23
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
24
|
+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
26
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
28
|
+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
require 'open-uri'
|
|
32
|
+
require 'rexml/document'
|
|
33
|
+
|
|
34
|
+
include REXML
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
#The Ridiculous module
|
|
38
|
+
#
|
|
39
|
+
#Usage:
|
|
40
|
+
#
|
|
41
|
+
#require "ridiculous"
|
|
42
|
+
#include "Ridiculous"
|
|
43
|
+
#
|
|
44
|
+
#Ridiculous::USERNAME = "YourDeliciousUsername"
|
|
45
|
+
#Ridiculous::PASSWORD = "YourDeliciousPassword"
|
|
46
|
+
#...
|
|
47
|
+
#
|
|
48
|
+
module Ridiculous
|
|
49
|
+
|
|
50
|
+
BASE_URI = "http://del.icio.us/api/"
|
|
51
|
+
VERSION = "0.3"
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Handle HTTP requests
|
|
55
|
+
#
|
|
56
|
+
def request(resource)
|
|
57
|
+
uri = BASE_URI + resource
|
|
58
|
+
|
|
59
|
+
begin
|
|
60
|
+
recource = open(URI.parse(uri),
|
|
61
|
+
:http_basic_authentication => [USERNAME,PASSWORD]).read
|
|
62
|
+
rescue OpenURI::HTTPError
|
|
63
|
+
raise "Can't connect to the server, please check the username/password.\nError: #{$!} \n"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def format_args(misc)
|
|
68
|
+
nil if misc.empty?
|
|
69
|
+
args = []
|
|
70
|
+
misc.each { |k,v| args.push("#{k}=#{v}") }
|
|
71
|
+
(args * "&")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
# Handle Post behaivor
|
|
76
|
+
#
|
|
77
|
+
class Post
|
|
78
|
+
def get(*args)
|
|
79
|
+
nil if args.empty?
|
|
80
|
+
return find("get",args.shift)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
#
|
|
84
|
+
#Returns an Array with user's recent posts, each post is a Hash object.
|
|
85
|
+
#
|
|
86
|
+
#Post.recent(:tag => 'ruby').each { |post| puts "#{post['description']}\n"}
|
|
87
|
+
#...
|
|
88
|
+
#
|
|
89
|
+
def recent(*args)
|
|
90
|
+
return (!args.empty?) ? find("recent", args.shift) : find("recent")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
#Returns an Array with all user's posts, each post is a Hash object
|
|
95
|
+
#
|
|
96
|
+
#Post.all.each { |post| puts "#{post['description']}\n"}
|
|
97
|
+
#...
|
|
98
|
+
#
|
|
99
|
+
def all(*args)
|
|
100
|
+
return (!args.empty?) ? find("recent", args.shift) : find("recent")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
# Calls the delicious service and parse the returned XML into an Array of hashes
|
|
105
|
+
# This method is private.
|
|
106
|
+
#
|
|
107
|
+
def find(method,args = nil)
|
|
108
|
+
@resource = case method
|
|
109
|
+
when "get" then "posts/get?"
|
|
110
|
+
when "recent" then "posts/recent?"
|
|
111
|
+
when "all" then "posts/all?"
|
|
112
|
+
end
|
|
113
|
+
@resource << format_args(args) if args != nil
|
|
114
|
+
@request = request(@resource)
|
|
115
|
+
|
|
116
|
+
begin
|
|
117
|
+
@doc = (Document.new @request).root
|
|
118
|
+
@posts = Array.new
|
|
119
|
+
if !@doc.nil?
|
|
120
|
+
@doc.elements.each("//post") do |item|
|
|
121
|
+
@posts.push( { "hash" => item.attributes["hash"],
|
|
122
|
+
"href" => item.attributes["href"],
|
|
123
|
+
"description" => item.attributes["description"],
|
|
124
|
+
"tags" => item.attributes["tag"],
|
|
125
|
+
"time" => item.attributes["time"] } )
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
@posts
|
|
129
|
+
rescue RuntimeError, NoMethodError
|
|
130
|
+
raise "\nPosts#find failed!\nError: #{$!}\n"
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
#
|
|
135
|
+
#Add a new post
|
|
136
|
+
#
|
|
137
|
+
#Post.add( :url => "http://laboratorio.us/",
|
|
138
|
+
# :description => "laboratorio.us",
|
|
139
|
+
# :extended => "Great tech news...",
|
|
140
|
+
# :tags => "ruby python software etc",
|
|
141
|
+
# :dt => "CCYY-MM-DDThh:mm:ssZ",
|
|
142
|
+
# :replace => "no" )
|
|
143
|
+
#...
|
|
144
|
+
#
|
|
145
|
+
#:url and :description are required arguments.
|
|
146
|
+
#
|
|
147
|
+
def add(*args)
|
|
148
|
+
nil if args.empty? || (!args[0].has_key?(:url) && !args[0].has_key?(:description))
|
|
149
|
+
@resource = "post/add?" << format_args(args.shift)
|
|
150
|
+
@request = request(URI.escape(@resource))
|
|
151
|
+
@doc = (Document.new @request).root
|
|
152
|
+
|
|
153
|
+
if @doc.attributes["code"] == "done"
|
|
154
|
+
true
|
|
155
|
+
else
|
|
156
|
+
nil
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
private :find
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#
|
|
165
|
+
#Handle Tag behaivor
|
|
166
|
+
#
|
|
167
|
+
class Tag
|
|
168
|
+
#
|
|
169
|
+
#Returns an Array with user's tags, each tag is a Hash object
|
|
170
|
+
#
|
|
171
|
+
#Tag.tags.each { |tag| puts "You have #{tag['count']} posts tagged as #{tag['tag']} \n"}
|
|
172
|
+
#...
|
|
173
|
+
#
|
|
174
|
+
def tags
|
|
175
|
+
return find
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
#
|
|
179
|
+
#Rename an existing tag
|
|
180
|
+
#
|
|
181
|
+
def rename(old,new)
|
|
182
|
+
nil if (old.empty? || new.empty?)
|
|
183
|
+
@resource = "tags/rename?old=#{old}&new=#{new}"
|
|
184
|
+
@request = request(URI.escape(@resource))
|
|
185
|
+
@doc = (Document.new @request).root
|
|
186
|
+
|
|
187
|
+
true if @doc.text == "done"
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
#
|
|
191
|
+
# Calls the delicious service and parse the returned XML into an Array of hashes
|
|
192
|
+
#
|
|
193
|
+
def find
|
|
194
|
+
@resource = "tags/get"
|
|
195
|
+
@request = request(@resource)
|
|
196
|
+
|
|
197
|
+
begin
|
|
198
|
+
@doc = (Document.new @request).root
|
|
199
|
+
@tags = Array.new
|
|
200
|
+
|
|
201
|
+
@doc.elements.each("//tag") do |item|
|
|
202
|
+
@tags.push( { "count" => item.attributes["count"],"tag" => item.attributes["tag"] } )
|
|
203
|
+
end
|
|
204
|
+
@tags
|
|
205
|
+
|
|
206
|
+
rescue RuntimeError, NoMethodError
|
|
207
|
+
raise "\nTags#find failed!\nError: #{$!}\n"
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
private :find
|
|
211
|
+
|
|
212
|
+
end
|
|
213
|
+
end
|
data/tests.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# 1,2,3 Testing
|
|
2
|
+
|
|
3
|
+
require "ridiculous"
|
|
4
|
+
|
|
5
|
+
include Ridiculous
|
|
6
|
+
|
|
7
|
+
# define username and password (it must change in the next version)
|
|
8
|
+
Ridiculous::USERNAME = "YOUR_USER"
|
|
9
|
+
Ridiculous::PASSWORD = "YOUR_PASS"
|
|
10
|
+
|
|
11
|
+
# testing posts
|
|
12
|
+
puts "\nTESTING POSTS...\n\n"
|
|
13
|
+
|
|
14
|
+
@post = Post.new
|
|
15
|
+
|
|
16
|
+
puts "\nRETRIEVING THE LAST 5 POSTS TAGGED AS `ruby`\n"
|
|
17
|
+
|
|
18
|
+
@post.recent(:tag => 'ruby', :count => '5').each { |p|
|
|
19
|
+
puts "#{p['description']}\n"
|
|
20
|
+
puts "#{p['href']}\n"
|
|
21
|
+
puts "#{p['tags']}\n\n"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
puts "." * 60
|
|
25
|
+
|
|
26
|
+
puts "\nTRYING TO GET AN ESPECIFIC POST\n"
|
|
27
|
+
|
|
28
|
+
p = @post.get(:url => 'http://rhg.rubyforge.org/')
|
|
29
|
+
|
|
30
|
+
if p.empty?
|
|
31
|
+
puts "Post not found"
|
|
32
|
+
else
|
|
33
|
+
p = p.shift
|
|
34
|
+
puts "#{p['description']}\n"
|
|
35
|
+
puts "#{p['href']}\n"
|
|
36
|
+
puts "#{p['tags']}\n\n"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
puts "." * 60
|
|
40
|
+
|
|
41
|
+
puts "\nTAGs..."
|
|
42
|
+
|
|
43
|
+
tag = Tag.new
|
|
44
|
+
tag.tags.each { |t| puts "#{t['tag']} (#{t['count']})" }
|
|
45
|
+
|
|
46
|
+
puts "." * 60
|
|
47
|
+
|
|
48
|
+
puts "\nTRYING TO RENAME A TAG"
|
|
49
|
+
|
|
50
|
+
old_name = "texto"
|
|
51
|
+
new_name = "textos"
|
|
52
|
+
|
|
53
|
+
if (tag.rename(old_name,new_name)) then
|
|
54
|
+
puts "Tag #{old_name} renamed to #{new_name}\n"
|
|
55
|
+
else
|
|
56
|
+
puts "Oh... failed!\n"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
puts "." * 60
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
rubygems_version: 0.8.11
|
|
3
|
+
specification_version: 1
|
|
4
|
+
name: Ridiculous
|
|
5
|
+
version: !ruby/object:Gem::Version
|
|
6
|
+
version: "0.3"
|
|
7
|
+
date: 2006-04-03 00:00:00 -03:00
|
|
8
|
+
summary: Ridiculous is a simple wrapper for del.icio.us API writing in Ruby
|
|
9
|
+
require_paths:
|
|
10
|
+
- lib
|
|
11
|
+
email: lupeke@gmail.com
|
|
12
|
+
homepage: http://ridiculous.rubyforge.org
|
|
13
|
+
rubyforge_project: ridiculous
|
|
14
|
+
description:
|
|
15
|
+
autorequire:
|
|
16
|
+
default_executable:
|
|
17
|
+
bindir: bin
|
|
18
|
+
has_rdoc: true
|
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "1.8"
|
|
24
|
+
version:
|
|
25
|
+
platform: ruby
|
|
26
|
+
signing_key:
|
|
27
|
+
cert_chain:
|
|
28
|
+
authors:
|
|
29
|
+
- Daniel Dias
|
|
30
|
+
files:
|
|
31
|
+
- ridiculous.rb
|
|
32
|
+
- index.html
|
|
33
|
+
- ridiculous.gemspec
|
|
34
|
+
- tests.rb
|
|
35
|
+
- doc
|
|
36
|
+
test_files:
|
|
37
|
+
- tests.rb
|
|
38
|
+
rdoc_options: []
|
|
39
|
+
|
|
40
|
+
extra_rdoc_files: []
|
|
41
|
+
|
|
42
|
+
executables: []
|
|
43
|
+
|
|
44
|
+
extensions: []
|
|
45
|
+
|
|
46
|
+
requirements: []
|
|
47
|
+
|
|
48
|
+
dependencies: []
|
|
49
|
+
|