oos4ruby 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,3 +15,10 @@
15
15
  * some bugs fixed
16
16
  * README.txt completed
17
17
  * more rdoc
18
+
19
+ == 0.1.3 2007-11-02
20
+
21
+ * 1 major enhancement:
22
+ * collection goes to array (deprecated sintax "entries")
23
+ * contacts bugs fixed
24
+ * collections total size bug fixed
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.entries
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.entries
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.entries[0].multimedia
54
+ media_collection = user.sites[0].multimedia
@@ -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 builder).each { |f| require f }
35
+ %w(rubygems).each { |f| require f }
34
36
 
35
37
  require 'oos4ruby/http_invoker.rb'
36
38
  require 'oos4ruby/auth.rb'
@@ -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
- @entries = feed.entries.map {|entry| evalued_class.new(entry, @auth, @slug) }
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 = @entries
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.entries.each {|entry| all << entry}
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
- @entries = convert(getter.body).entries
151
+ convert(getter.body)
161
152
  return self
162
153
  end
163
154
  end
@@ -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
@@ -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
- begin
29
- uri = URI.parse(slug)
30
- rescue
31
- uri = nil
32
- end
33
-
34
- unless uri
35
- uri = USERS_URL
36
- uri = uri + "/#{slug}" if slug
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 if !@no_mails.nil?
115
- @xml.child('nonewsletter', OosNamespace).text = @no_newsletter.to_s if !@no_newsletter.nil?
116
- @xml.child('onlycontacts', OosNamespace).text = @only_contacts.to_s if !@only_contacts.nil?
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
@@ -2,7 +2,7 @@ module Oos4ruby #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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
@@ -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
- oos = Oos4ruby::Oos.new
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 => [:asdfd, :dfgfg], :lists => [:comida]
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 test_truth
93
- assert true
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
 
@@ -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.2</a>
36
+ <a href="http://rubyforge.org/projects/oos4ruby" class="numbers">0.1.3</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;oos4ruby&#8217;</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><span class="punct">.</span><span class="ident">entries</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><span class="punct">.</span><span class="ident">entries</span></pre></p>
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">.</span><span class="ident">entries</span><span class="punct">[</span><span class="number">0</span><span class="punct">].</span><span class="ident">multimedia</span></pre></p>
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>, 16th October 2007<br>
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>
@@ -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.entries
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.entries</pre>
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.entries[0].multimedia</pre>
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.2
7
- date: 2007-10-16 00:00:00 +02:00
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