oos4ruby 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/README.txt +3 -3
- data/lib/oos4ruby.rb +4 -2
- data/lib/oos4ruby/collection.rb +7 -16
- data/lib/oos4ruby/contact.rb +6 -0
- data/lib/oos4ruby/user.rb +14 -12
- data/lib/oos4ruby/version.rb +1 -1
- data/tasks/deployment.rake +6 -0
- data/test/test_oos4ruby.rb +47 -7
- data/website/index.html +5 -5
- data/website/index.txt +3 -3
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -29,7 +29,7 @@ How to obtain the services or places saved by a user:
|
|
29
29
|
#if your app is authenticated to expore contents
|
30
30
|
user = oos.user 'user slug in 11870'
|
31
31
|
|
32
|
-
sites = user.sites
|
32
|
+
sites = user.sites
|
33
33
|
|
34
34
|
How to add a review from a site that doesn't exist in 11870:
|
35
35
|
|
@@ -47,8 +47,8 @@ How to add a review from a site that exists in 11870:
|
|
47
47
|
|
48
48
|
How to obtain all user contacts in 11870:
|
49
49
|
|
50
|
-
contacts = user.contacts
|
50
|
+
contacts = user.contacts
|
51
51
|
|
52
52
|
How to obtain the multimedia feed associated with a review:
|
53
53
|
|
54
|
-
media_collection = user.sites
|
54
|
+
media_collection = user.sites[0].multimedia
|
data/lib/oos4ruby.rb
CHANGED
@@ -7,13 +7,15 @@ module Oos4ruby
|
|
7
7
|
XhtmlNamespace = 'http://www.w3.org/1999/xhtml'
|
8
8
|
GeoRSSNamespace = 'http://www.georss.org/georss/10'
|
9
9
|
GmlNamespace = 'http://www.opengis.net/gml'
|
10
|
+
OsNamespace = 'http://a9.com/-/spec/opensearch/1.1/'
|
10
11
|
XmlNamespaces = {
|
11
12
|
'app' => AppNamespace,
|
12
13
|
'atom' => AtomNamespace,
|
13
14
|
'xhtml' => XhtmlNamespace,
|
14
15
|
'oos' => OosNamespace,
|
15
16
|
'georss' => GeoRSSNamespace,
|
16
|
-
'gml' => GmlNamespace
|
17
|
+
'gml' => GmlNamespace,
|
18
|
+
'os' => OsNamespace
|
17
19
|
}
|
18
20
|
|
19
21
|
AtomEntryContentType = 'application/atom+xml;type=entry'
|
@@ -30,7 +32,7 @@ module Oos4ruby
|
|
30
32
|
TRUSTED_URL = API_URL + '/trusted'
|
31
33
|
SEARCH_URL = API_URL + '/search'
|
32
34
|
end
|
33
|
-
%w(rubygems
|
35
|
+
%w(rubygems).each { |f| require f }
|
34
36
|
|
35
37
|
require 'oos4ruby/http_invoker.rb'
|
36
38
|
require 'oos4ruby/auth.rb'
|
data/lib/oos4ruby/collection.rb
CHANGED
@@ -5,16 +5,14 @@ module Oos4ruby
|
|
5
5
|
|
6
6
|
API feed response is paginated, so, this class provides some methods to explore the feed.
|
7
7
|
=end
|
8
|
-
class Collection
|
9
|
-
|
10
|
-
attr_reader :entries
|
8
|
+
class Collection < Array
|
11
9
|
|
12
10
|
def initialize(feed, auth, slug = nil)
|
13
11
|
@feed = feed
|
14
12
|
@auth = auth
|
15
13
|
@slug = slug
|
16
14
|
evalued_class = eval(self.class.name.gsub(/s$/, ''))
|
17
|
-
|
15
|
+
feed.entries.each {|entry| self << evalued_class.new(entry, @auth, @slug) }
|
18
16
|
end
|
19
17
|
|
20
18
|
=begin rdoc
|
@@ -58,30 +56,23 @@ class Collection
|
|
58
56
|
def previous!
|
59
57
|
return get_page!(@feed.previous)
|
60
58
|
end
|
61
|
-
|
62
|
-
=begin rdoc
|
63
|
-
returns the size of the current collection.
|
64
|
-
=end
|
65
|
-
def size
|
66
|
-
@feed.size
|
67
|
-
end
|
68
|
-
|
59
|
+
|
69
60
|
=begin rdoc
|
70
61
|
returns the total size of the feed.
|
71
62
|
=end
|
72
63
|
def total_size
|
73
|
-
@feed.total_size
|
64
|
+
return @feed.total_size
|
74
65
|
end
|
75
66
|
|
76
67
|
=begin rdoc
|
77
68
|
return all entries into the feed.
|
78
69
|
=end
|
79
70
|
def all
|
80
|
-
all =
|
71
|
+
all = self.to_a
|
81
72
|
aux = self
|
82
73
|
while aux.next_page?
|
83
74
|
next_page = aux.next_page
|
84
|
-
next_page.
|
75
|
+
next_page.each {|entry| all << entry}
|
85
76
|
aux = next_page
|
86
77
|
end
|
87
78
|
return all
|
@@ -157,7 +148,7 @@ class Collection
|
|
157
148
|
worked = getter.get
|
158
149
|
if worked
|
159
150
|
@feed = Feed.read(getter.body)
|
160
|
-
|
151
|
+
convert(getter.body)
|
161
152
|
return self
|
162
153
|
end
|
163
154
|
end
|
data/lib/oos4ruby/contact.rb
CHANGED
@@ -16,6 +16,9 @@ class Contact < BeanClass
|
|
16
16
|
@slug = slug
|
17
17
|
end
|
18
18
|
|
19
|
+
=begin rdoc
|
20
|
+
find all user contacts
|
21
|
+
=end
|
19
22
|
def Contact.find_by_user( auth, slug, opts = {} )
|
20
23
|
raise Oos4ruby::UnknownUser if slug.nil?
|
21
24
|
|
@@ -28,6 +31,9 @@ class Contact < BeanClass
|
|
28
31
|
Contacts.new(Feed.read(getter.body), auth, slug) if worked
|
29
32
|
end
|
30
33
|
|
34
|
+
=begin rdoc
|
35
|
+
returns the user associated with this contact
|
36
|
+
=end
|
31
37
|
def data
|
32
38
|
@data = User.find @auth, @xml.link('userInfo') unless @data
|
33
39
|
@data
|
data/lib/oos4ruby/user.rb
CHANGED
@@ -14,6 +14,8 @@ class User < Bean::BeanClass
|
|
14
14
|
alias :nick :title
|
15
15
|
alias :about_me :content
|
16
16
|
|
17
|
+
attr_reader :slug
|
18
|
+
|
17
19
|
attr_writer :nick, :about_me, :name, :surname, :no_mails, :only_contacts, :no_newsletter
|
18
20
|
|
19
21
|
def initialize(entry, auth, slug = nil)
|
@@ -25,15 +27,15 @@ class User < Bean::BeanClass
|
|
25
27
|
def User.find( auth, slug = nil )
|
26
28
|
raise Oos4ruby::UnknownUser if auth.method?(:app) && slug.nil?
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
uri = USERS_URL
|
31
|
+
if slug
|
32
|
+
if slug.is_a?URI
|
33
|
+
uri = slug
|
34
|
+
elsif slug.is_a?String and slug =~ /^http/
|
35
|
+
uri = URI.parse(slug)
|
36
|
+
else
|
37
|
+
uri += "/#{slug}"
|
38
|
+
end
|
37
39
|
end
|
38
40
|
|
39
41
|
getter = HTTPInvoker.new uri.to_s, auth
|
@@ -111,9 +113,9 @@ class User < Bean::BeanClass
|
|
111
113
|
|
112
114
|
@xml.child('name', OosNamespace).text = @name if @name
|
113
115
|
@xml.child('surname', OosNamespace).text = @surname if @surname
|
114
|
-
@xml.child('nomails', OosNamespace).text = @no_mails.to_s
|
115
|
-
@xml.child('nonewsletter', OosNamespace).text = @no_newsletter.to_s
|
116
|
-
@xml.child('onlycontacts', OosNamespace).text = @only_contacts.to_s
|
116
|
+
@xml.child('nomails', OosNamespace).text = @no_mails.to_s unless @no_mails.nil?
|
117
|
+
@xml.child('nonewsletter', OosNamespace).text = @no_newsletter.to_s unless @no_newsletter.nil?
|
118
|
+
@xml.child('onlycontacts', OosNamespace).text = @only_contacts.to_s unless @only_contacts.nil?
|
117
119
|
end
|
118
120
|
end
|
119
121
|
end
|
data/lib/oos4ruby/version.rb
CHANGED
data/tasks/deployment.rake
CHANGED
@@ -25,3 +25,9 @@ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
|
25
25
|
task :install_gem_no_doc => [:clean, :package] do
|
26
26
|
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
27
|
end
|
28
|
+
|
29
|
+
desc 'Tag the latest release'
|
30
|
+
task :tag_version do
|
31
|
+
sh "svn copy https://api-11870.googlecode.com/svn/trunk/oos4ruby " +
|
32
|
+
"https://api-11870.googlecode.com/svn/tags/oos4ruby/REL-#{VERS} --username david.calavera"
|
33
|
+
end
|
data/test/test_oos4ruby.rb
CHANGED
@@ -3,10 +3,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
3
3
|
require 'rubygems'
|
4
4
|
require File.dirname(__FILE__) + '/../lib/oos4ruby.rb'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
oos.auth_user('david.calavera@11870.com', 'asdf')
|
9
|
-
|
6
|
+
=begin
|
10
7
|
puts user.name
|
11
8
|
puts user.surname
|
12
9
|
puts user.no_mails
|
@@ -48,7 +45,7 @@ sites = user.sites.entries
|
|
48
45
|
new_site = user.sites.create! :title => 'asdfasdf', :user_address => 'asdfasdf',
|
49
46
|
:country => {:name => 'España', :slug => '/es'}, :locality => {:name => 'Madrid', :slug => '/es/madrid'},
|
50
47
|
:summary => 'nueva opinion desde la API', :review_content => 'asdfasdf',
|
51
|
-
:tags => [
|
48
|
+
:tags => ['tapas', 'tipical spanish'], :lists => ['food']
|
52
49
|
|
53
50
|
puts new_site.to_xml || 'NOOOOOO'
|
54
51
|
|
@@ -83,16 +80,59 @@ puts media.to_s
|
|
83
80
|
site.multimedia.refresh!
|
84
81
|
|
85
82
|
puts site.multimedia.entries.to_s
|
83
|
+
=end
|
86
84
|
|
87
85
|
class TestOos4ruby < Test::Unit::TestCase
|
88
86
|
|
89
87
|
def setup
|
88
|
+
@oos = Oos4ruby::Oos.new
|
89
|
+
@oos.auth_user('david.calavera@11870.com', 'deadbeeff00')
|
90
|
+
end
|
91
|
+
|
92
|
+
def assert_user_not_nil(user)
|
93
|
+
assert_not_nil user, ''
|
90
94
|
end
|
91
95
|
|
92
|
-
def
|
93
|
-
|
96
|
+
def test_user_without_slug
|
97
|
+
user = @oos.user
|
98
|
+
assert_user_not_nil(user)
|
94
99
|
end
|
95
100
|
|
101
|
+
def test_user_with_slug
|
102
|
+
user = @oos.user('mamuso')
|
103
|
+
assert_user_not_nil(user)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_user_with_uri
|
107
|
+
user = @oos.user('http://11870.com/api/v1/users/peralta')
|
108
|
+
assert_user_not_nil(user)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_contacts
|
112
|
+
user = @oos.user
|
113
|
+
assert_not_nil user.contacts, ''
|
114
|
+
assert (not user.contacts.empty?), ''
|
115
|
+
|
116
|
+
contact = user.contacts[0]
|
117
|
+
assert_not_nil contact, ''
|
118
|
+
assert_not_nil contact.data, ''
|
119
|
+
assert_not_nil contact.data.nick, ''
|
120
|
+
assert_not_nil contact.data.slug, ''
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_sites
|
124
|
+
user = @oos.user
|
125
|
+
assert_not_nil user.sites, ''
|
126
|
+
assert_not_nil user.sites.size, ''
|
127
|
+
assert_not_nil user.sites.total_size, ''
|
128
|
+
assert_not_nil user.sites[0], ''
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_all_sites
|
132
|
+
user = @oos.user
|
133
|
+
assert_not_nil user.sites.all, ''
|
134
|
+
assert (user.sites.total_size == user.sites.all.size)
|
135
|
+
end
|
96
136
|
|
97
137
|
end
|
98
138
|
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>oos4ruby</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/oos4ruby"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/oos4ruby" class="numbers">0.1.
|
36
|
+
<a href="http://rubyforge.org/projects/oos4ruby" class="numbers">0.1.3</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘oos4ruby’</h1>
|
39
39
|
|
@@ -86,7 +86,7 @@
|
|
86
86
|
<span class="comment">#if your app is authenticated to expore contents</span>
|
87
87
|
<span class="ident">user</span> <span class="punct">=</span> <span class="ident">oos</span><span class="punct">.</span><span class="ident">user</span> <span class="punct">'</span><span class="string">user slug in 11870</span><span class="punct">'</span>
|
88
88
|
|
89
|
-
<span class="ident">sites</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">sites</span
|
89
|
+
<span class="ident">sites</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">sites</span>
|
90
90
|
</pre></p>
|
91
91
|
|
92
92
|
|
@@ -115,13 +115,13 @@
|
|
115
115
|
<p>How to obtain all user contacts in 11870:</p>
|
116
116
|
|
117
117
|
|
118
|
-
<p><pre class='syntax'><span class="ident">contacts</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">contacts</span
|
118
|
+
<p><pre class='syntax'><span class="ident">contacts</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">contacts</span></pre></p>
|
119
119
|
|
120
120
|
|
121
121
|
<p>How to obtain the multimedia feed associated with a review:</p>
|
122
122
|
|
123
123
|
|
124
|
-
<p><pre class='syntax'><span class="ident">media_collection</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">sites</span><span class="punct"
|
124
|
+
<p><pre class='syntax'><span class="ident">media_collection</span> <span class="punct">=</span> <span class="ident">user</span><span class="punct">.</span><span class="ident">sites</span><span class="punct">[</span><span class="number">0</span><span class="punct">].</span><span class="ident">multimedia</span></pre></p>
|
125
125
|
|
126
126
|
|
127
127
|
<h2>Forum</h2>
|
@@ -150,7 +150,7 @@
|
|
150
150
|
|
151
151
|
<p>Comments are welcome. Send an email to <a href="mailto:david.calavera@gmail.com">David Calavera</a> email via the <a href="http://groups.google.com/group/api-11870">forum</a></p>
|
152
152
|
<p class="coda">
|
153
|
-
<a href="FIXME email">David Calavera</a>,
|
153
|
+
<a href="FIXME email">David Calavera</a>, 2nd November 2007<br>
|
154
154
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
155
155
|
</p>
|
156
156
|
</div>
|
data/website/index.txt
CHANGED
@@ -37,7 +37,7 @@ user = oos.user
|
|
37
37
|
#if your app is authenticated to expore contents
|
38
38
|
user = oos.user 'user slug in 11870'
|
39
39
|
|
40
|
-
sites = user.sites
|
40
|
+
sites = user.sites
|
41
41
|
</pre>
|
42
42
|
|
43
43
|
How to add a review from a site that doesn't exist in 11870:
|
@@ -60,11 +60,11 @@ oos.user.sites.create! {:id => '11870 site id',
|
|
60
60
|
|
61
61
|
How to obtain all user contacts in 11870:
|
62
62
|
|
63
|
-
<pre syntax="ruby">contacts = user.contacts
|
63
|
+
<pre syntax="ruby">contacts = user.contacts</pre>
|
64
64
|
|
65
65
|
How to obtain the multimedia feed associated with a review:
|
66
66
|
|
67
|
-
<pre syntax="ruby">media_collection = user.sites
|
67
|
+
<pre syntax="ruby">media_collection = user.sites[0].multimedia</pre>
|
68
68
|
|
69
69
|
h2. Forum
|
70
70
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: oos4ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.3
|
7
|
+
date: 2007-11-02 00:00:00 +01:00
|
8
8
|
summary: oos4ruby is a ruby binding for the 11870 API
|
9
9
|
require_paths:
|
10
10
|
- lib
|