oos4ruby 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,3 +27,7 @@
27
27
 
28
28
  *1 bugs fixed:
29
29
  * see this thread: http://tinyurl.com/253a2d (thanks to Luismi Cavallé)
30
+
31
+ == 0.1.5 2008-01-14
32
+
33
+ *1 save bugs fixed
@@ -20,7 +20,7 @@ module Oos4ruby
20
20
 
21
21
  AtomEntryContentType = 'application/atom+xml;type=entry'
22
22
 
23
- OOS_URL = 'http://11870.com'
23
+ OOS_URL = 'http://localhost'
24
24
  API_URL = OOS_URL + '/api/v1'
25
25
 
26
26
  SITES_URL = Oos4ruby::API_URL + '/sites'
@@ -88,45 +88,6 @@ module Bean #:nodoc:
88
88
  end
89
89
  end
90
90
 
91
- def make_id
92
- id = ''
93
- 5.times { id += rand(1000000).to_s }
94
- "Oos4ruby:11870.com,2007:#{id}"
95
- end
96
-
97
- def add_element(base, new_el, text, attrs = {})
98
- el = base.add_element new_el.to_s, attrs
99
- el.text = text
100
- base
101
- end
102
-
103
- def add_category(xml, term, scheme)
104
- xml.add_category(term.to_s, scheme)
105
- end
106
-
107
- def remove_category(xml, term = nil, scheme = nil)
108
- if xml.is_a?Entry
109
- hash = {}
110
- hash[:term] = term if term
111
- hash[:scheme] = scheme if scheme
112
- cat = xml.category( hash )
113
- xml.delete_category( cat ) if cat
114
- elsif xml.is_a?REXML::Element
115
- xml.delete_element c
116
- end
117
- end
118
-
119
- def create_entry
120
- entry = REXML::Element.new('entry')
121
- entry.add_namespace AtomNamespace
122
- XmlNamespaces.each_pair { |prefix, namespace|
123
- unless prefix == 'atom' || prefix == 'gml'
124
- entry.add_namespace prefix, namespace
125
- end
126
- }
127
- entry
128
- end
129
-
130
91
  class BeanClass
131
92
  def author
132
93
  @entry.child('author/name').text
@@ -140,6 +101,13 @@ module Bean #:nodoc:
140
101
  @xml.to_s
141
102
  end
142
103
 
104
+ def contains?(elem, value)
105
+ xpath = @xml.first(elem)
106
+ return true if xpath && xpath.text == value
107
+
108
+ return false
109
+ end
110
+
143
111
  def update!
144
112
  edit_link = @xml.link('edit')
145
113
 
@@ -183,6 +151,51 @@ module Bean #:nodoc:
183
151
  Bean.remove_category(@xml, term, scheme)
184
152
  end
185
153
 
154
+ def self.make_id
155
+ id = ''
156
+ 5.times { id += rand(1000000).to_s }
157
+ "Oos4ruby:11870.com,2007:#{id}"
158
+ end
159
+
160
+ def self.add_element(base, new_el, text, attrs = {})
161
+ elements = new_el.to_s.split("/")
162
+ last = elements[elements.size - 1]
163
+ elements.pop
164
+ root_el = base
165
+ elements.each do |path|
166
+ root_el = base.add_element(path)
167
+ end
168
+ el = root_el.add_element last.to_s, attrs
169
+ el.text = text
170
+ end
171
+
172
+ def self.add_category(xml, term, scheme)
173
+ xml.add_category(term.to_s, scheme)
174
+ end
175
+
176
+ def self.remove_category(xml, term = nil, scheme = nil)
177
+ if xml.is_a?Entry
178
+ hash = {}
179
+ hash[:term] = term if term
180
+ hash[:scheme] = scheme if scheme
181
+ cat = xml.category( hash )
182
+ xml.delete_category( cat ) if cat
183
+ elsif xml.is_a?REXML::Element
184
+ xml.delete_element c
185
+ end
186
+ end
187
+
188
+ def self.create_entry
189
+ entry = REXML::Element.new('entry')
190
+ entry.add_namespace AtomNamespace
191
+ XmlNamespaces.each_pair { |prefix, namespace|
192
+ unless prefix == 'atom' || prefix == 'gml'
193
+ entry.add_namespace prefix, namespace
194
+ end
195
+ }
196
+ entry
197
+ end
198
+
186
199
  end
187
200
  end
188
201
  end
@@ -12,7 +12,7 @@ class Collection < Array
12
12
  @auth = auth
13
13
  @slug = slug
14
14
  evalued_class = eval(self.class.name.gsub(/s$/, ''))
15
- feed.entries.each {|entry| self << evalued_class.new(entry, @auth, @slug) }
15
+ @feed.entries.each {|entry| self << evalued_class.new(entry, @auth, @slug) }
16
16
  end
17
17
 
18
18
  =begin rdoc
@@ -114,9 +114,7 @@ class Collection < Array
114
114
  :content_length => file size
115
115
  :content_type => file content type
116
116
  =end
117
- def create!(opts = {})
118
- opts[:author] = REXML::XPath.first(@feed.xml, 'author', XmlNamespaces)
119
-
117
+ def create!(opts = {})
120
118
  evalued_class = eval(self.class.name.gsub(/s$/, ''))
121
119
  body = evalued_class.dump! opts, @slug
122
120
  unless self.instance_of?Medias
@@ -134,6 +132,21 @@ class Collection < Array
134
132
  raise RuntimeError.new unless worked
135
133
  return evalued_class.new(poster.entry, @auth, @slug)
136
134
  end
135
+ =begin rdoc
136
+ return true if the text of the element is equals to the given value
137
+
138
+ i.e:
139
+ user.contacts.contains? 'oos:slug', 'calavera'
140
+ user.sites.contains? 'oos:locality', 'Madrid'
141
+ =end
142
+ def contains?(elem, value)
143
+ self.each do |obj|
144
+ if obj.contains?(elem, value)
145
+ return true
146
+ end
147
+ end
148
+ return false
149
+ end
137
150
 
138
151
  private
139
152
  def get_page(link)
@@ -44,9 +44,11 @@ class Contact < Bean::BeanClass
44
44
  end
45
45
 
46
46
  def Contact.dump!(opts, slug)
47
+ include Bean
48
+
47
49
  entry = create_entry
48
50
 
49
- entry.add_element opts[:author]
51
+ add_element entry, 'author/name', slug
50
52
 
51
53
  updated = DateTime::now.strftime("%Y-%m-%dT%H:%M:%S%z").sub(/(..)$/, ':\1')
52
54
 
@@ -53,9 +53,8 @@ class Site < Bean::BeanClass
53
53
  def Site.dump!(opts, slug)
54
54
  require 'date'
55
55
 
56
- entry = create_entry
57
-
58
- entry.add_element opts[:author]
56
+ entry = create_entry
57
+ add_element(entry, 'author/name', slug)
59
58
 
60
59
  updated = DateTime::now.strftime("%Y-%m-%dT%H:%M:%S%z").sub(/(..)$/, ':\1')
61
60
 
@@ -2,7 +2,7 @@ module Oos4ruby #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -42,7 +42,7 @@ puts sites.entries.to_s
42
42
  sites = user.sites.entries
43
43
 
44
44
 
45
- new_site = user.sites.create! :title => 'asdfasdf', :user_address => 'asdfasdf',
45
+ new_site = user.sites.create! :title => 'asdfw4rwqwasf', :user_address => 'asdfw4rwqwasf',
46
46
  :country => {:name => 'España', :slug => '/es'}, :locality => {:name => 'Madrid', :slug => '/es/madrid'},
47
47
  :summary => 'nueva opinion desde la API', :review_content => 'asdfasdf',
48
48
  :tags => ['tapas', 'tipical spanish'], :lists => ['food']
@@ -86,7 +86,7 @@ class TestOos4ruby < Test::Unit::TestCase
86
86
 
87
87
  def setup
88
88
  @oos = Oos4ruby::Oos.new
89
- @oos.auth_user('david.calavera@11870.com', 'deadbeeff00')
89
+ @oos.auth_user('david.calavera@11870.com', '3beedf801db0d373919f6462345d6f76')
90
90
  end
91
91
 
92
92
  def assert_user_not_nil(user)
@@ -104,7 +104,7 @@ class TestOos4ruby < Test::Unit::TestCase
104
104
  end
105
105
 
106
106
  def test_user_with_uri
107
- user = @oos.user('http://11870.com/api/v1/users/peralta')
107
+ user = @oos.user("#{Oos4ruby::API_URL}/users/peralta")
108
108
  assert_user_not_nil(user)
109
109
  end
110
110
 
@@ -131,7 +131,21 @@ class TestOos4ruby < Test::Unit::TestCase
131
131
  def test_all_sites
132
132
  user = @oos.user
133
133
  assert_not_nil user.sites.all, ''
134
- assert (user.sites.total_size == user.sites.all.size)
134
+ assert_equal user.sites.total_size, user.sites.all.size
135
+ end
136
+
137
+ def test_create_site
138
+ site = @oos.user.sites.create! :title => 'asdfwdss4rwqwasf', :user_address => 'asdfw4rwqwasf',
139
+ :country => {:name => 'España', :slug => '/es'},
140
+ :locality => {:name => 'Madrid', :slug => '/es/madrid'},
141
+ :summary => 'nueva opinion desde la API', :review_content => 'asdfasdf',
142
+ :tags => ['tapas', 'tipical spanish'], :lists => ['food'], :telephone => '913545471'
143
+
144
+ assert_not_nil site
145
+ end
146
+
147
+ def test_contains?
148
+ assert_equal(true, @oos.user.sites.contains?('oos:locality', 'Madrid'))
135
149
  end
136
150
 
137
151
  end
@@ -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.4</a>
36
+ <a href="http://rubyforge.org/projects/oos4ruby" class="numbers">0.1.5</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;oos4ruby&#8217;</h1>
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oos4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ""
6
6
  authors:
7
7
  - David Calavera
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-10 00:00:00 +01:00
12
+ date: 2008-01-14 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency