exempla-atomic 0.0.11 → 0.0.12
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/VERSION.yml +1 -1
- data/lib/atomic/atom.rb +312 -0
- data/lib/atomic/atompub.rb +206 -0
- data/lib/atomic/parser.rb +1 -5
- data/lib/atomic.rb +2 -4
- data/spec/atomic/atomic_spec_helper.rb +54 -0
- data/spec/atomic/entry_spec.rb +31 -29
- data/spec/atomic/feed_spec.rb +30 -5
- data/spec/atomic/service_spec.rb +26 -5
- metadata +6 -6
- data/lib/atomic/entry.rb +0 -102
- data/lib/atomic/feed.rb +0 -91
- data/lib/atomic/person.rb +0 -48
- data/lib/atomic/service.rb +0 -145
data/VERSION.yml
CHANGED
data/lib/atomic/atom.rb
ADDED
@@ -0,0 +1,312 @@
|
|
1
|
+
begin
|
2
|
+
require 'builder'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'builder'
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'activesupport'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
require 'activesupport'
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'time'
|
16
|
+
|
17
|
+
module Atomic
|
18
|
+
module Atom
|
19
|
+
class Person
|
20
|
+
|
21
|
+
include Parser
|
22
|
+
|
23
|
+
attr_accessor :type, :name, :uri, :email
|
24
|
+
|
25
|
+
def initialize(params = {})
|
26
|
+
params.symbolize_keys!
|
27
|
+
params.assert_valid_keys(:type, :name, :uri, :email)
|
28
|
+
self.type = params[:type]
|
29
|
+
self.name = params[:name]
|
30
|
+
self.uri = params[:uri]
|
31
|
+
self.email = params[:email]
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_open_element(node, reader)
|
35
|
+
progressed = false
|
36
|
+
case [node.depth, node.uri, node.name]
|
37
|
+
when [0, NS_ATOM, 'author']
|
38
|
+
when [0, NS_ATOM, 'contributor']
|
39
|
+
when [1, NS_ATOM, 'name']
|
40
|
+
when [1, NS_ATOM, 'uri']
|
41
|
+
when [1, NS_ATOM, 'email']
|
42
|
+
else
|
43
|
+
puts("Person ==> Unexpected Open Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect}")
|
44
|
+
end
|
45
|
+
return progressed
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_close_element(node)
|
49
|
+
case [node.depth, node.uri, node.name]
|
50
|
+
when [0, NS_ATOM, 'author']
|
51
|
+
self.type = 'author'
|
52
|
+
when [0, NS_ATOM, 'contributor']
|
53
|
+
self.type = 'contributor'
|
54
|
+
when [1, NS_ATOM, 'name']
|
55
|
+
self.name = node.text
|
56
|
+
when [1, NS_ATOM, 'uri']
|
57
|
+
self.uri = node.text
|
58
|
+
when [1, NS_ATOM, 'email']
|
59
|
+
self.email = node.text
|
60
|
+
else
|
61
|
+
puts("Person ==> Unexpected Close Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect} #{node.text}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_hash
|
66
|
+
{
|
67
|
+
:type => self.type,
|
68
|
+
:name => self.name,
|
69
|
+
:uri => self.uri,
|
70
|
+
:email => self.email
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_xml(as_document=true, target=nil)
|
75
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM} : {}
|
76
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
77
|
+
xml.instruct! if as_document
|
78
|
+
xml.atom(type.to_sym, nsdec) do
|
79
|
+
xml.atom(:name, self.name)
|
80
|
+
xml.atom(:uri, self.uri)
|
81
|
+
xml.atom(:email, self.email)
|
82
|
+
end
|
83
|
+
xml.target!
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
class Entry
|
90
|
+
|
91
|
+
include Parser
|
92
|
+
|
93
|
+
attr_accessor :id, :title, :categories, :created_at, :updated_at, :content, :links, :author, :contributors
|
94
|
+
|
95
|
+
def initialize(params = {})
|
96
|
+
params.symbolize_keys!
|
97
|
+
params.assert_valid_keys(:id, :title, :categories, :created_at, :updated_at, :content, :links, :author, :contributors)
|
98
|
+
self.title = params[:title]
|
99
|
+
self.id = params[:id]
|
100
|
+
self.categories = params[:categories] || []
|
101
|
+
self.created_at = params[:created_at].nil? ? Time.now : Time.parse(params[:created_at])
|
102
|
+
self.updated_at = params[:updated_at].nil? ? self.created_at : Time.parse(params[:updated_at])
|
103
|
+
self.content = params[:content] || {}
|
104
|
+
self.links = params[:links] || []
|
105
|
+
self.author = params[:author]
|
106
|
+
self.contributors = params[:contributors] || []
|
107
|
+
end
|
108
|
+
|
109
|
+
def handle_open_element(node, reader)
|
110
|
+
progressed = false
|
111
|
+
case [node.depth, node.uri, node.name]
|
112
|
+
when [0, NS_ATOM, 'entry']
|
113
|
+
when [1, NS_ATOM, 'title']
|
114
|
+
when [1, NS_ATOM, 'id']
|
115
|
+
when [1, NS_ATOM, 'published']
|
116
|
+
when [1, NS_ATOM, 'updated']
|
117
|
+
when [1, NS_ATOM, 'category']
|
118
|
+
when [1, NS_ATOM, 'author']
|
119
|
+
self.author = Person.new.deserialize(reader)
|
120
|
+
progressed = true
|
121
|
+
when [1, NS_ATOM, 'contributor']
|
122
|
+
self.contributors << Person.new.deserialize(reader)
|
123
|
+
progressed = true
|
124
|
+
when [1, NS_ATOM, 'content']
|
125
|
+
if node.attributes['type'] == 'application/xml'
|
126
|
+
@processing_xml_content = true
|
127
|
+
end
|
128
|
+
when [1, NS_ATOM, 'link']
|
129
|
+
else
|
130
|
+
if @processing_xml_content
|
131
|
+
extension_class = Extensions::MAP[[node.uri, node.name]]
|
132
|
+
unless extension_class.nil?
|
133
|
+
extension_class.new(self).deserialize(reader)
|
134
|
+
progressed = true
|
135
|
+
end
|
136
|
+
else
|
137
|
+
puts("Entry ==> Unexpected Open Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect}")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
return progressed
|
141
|
+
end
|
142
|
+
|
143
|
+
def handle_close_element(node)
|
144
|
+
case [node.depth, node.uri, node.name]
|
145
|
+
when [0, NS_ATOM, 'entry']
|
146
|
+
when [1, NS_ATOM, 'title']
|
147
|
+
self.title = node.text
|
148
|
+
when [1, NS_ATOM, 'id']
|
149
|
+
self.id = node.text
|
150
|
+
when [1, NS_ATOM, 'published']
|
151
|
+
self.created_at = Time.parse(node.text)
|
152
|
+
when [1, NS_ATOM, 'updated']
|
153
|
+
self.updated_at = Time.parse(node.text)
|
154
|
+
when [1, NS_ATOM, 'category']
|
155
|
+
self.categories << {:scheme => node.attributes['scheme'], :term => node.attributes['term']}
|
156
|
+
when [1, NS_ATOM, 'author']
|
157
|
+
when [1, NS_ATOM, 'content']
|
158
|
+
@processing_xml_content = false
|
159
|
+
when [1, NS_ATOM, 'link']
|
160
|
+
self.links << {:href => node.attributes['href'], :rel => node.attributes['rel'], :type => node.attributes['type']}
|
161
|
+
else
|
162
|
+
puts("Entry ==> Unexpected Close Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect} #{node.text}") unless @processing_xml_content
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def to_hash
|
167
|
+
{
|
168
|
+
:id => self.id,
|
169
|
+
:title => self.title,
|
170
|
+
:categories => self.categories,
|
171
|
+
:created_at => self.created_at,
|
172
|
+
:updated_at => self.updated_at,
|
173
|
+
:content => self.content,
|
174
|
+
:links => self.links,
|
175
|
+
:author => self.author,
|
176
|
+
:contributors => self.contributors.collect { |contributor| contributor.to_hash }
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
def to_xml(as_document=true, target=nil)
|
181
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM} : {}
|
182
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
183
|
+
xml.instruct! if as_document
|
184
|
+
xml.atom(:entry, nsdec) do
|
185
|
+
xml.atom(:id, self.id)
|
186
|
+
xml.atom(:title, self.title)
|
187
|
+
xml.atom(:categories) do
|
188
|
+
self.categories.each do |category|
|
189
|
+
xml.atom(:category, category)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
xml.atom(:published, self.created_at.iso8601)
|
193
|
+
xml.atom(:updated, self.updated_at.iso8601)
|
194
|
+
xml.atom(:content, self.content) if self.content
|
195
|
+
self.links.each do |link|
|
196
|
+
xml.atom(:link, link)
|
197
|
+
end
|
198
|
+
self.author.to_xml(false, xml) if self.author
|
199
|
+
self.contributors.each do |contributor|
|
200
|
+
contributor.to_xml(false, xml)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
xml.target!
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
class Feed
|
209
|
+
|
210
|
+
include Parser
|
211
|
+
|
212
|
+
attr_accessor :id, :title, :subtitle, :updated_at, :links, :rights, :generator, :entries
|
213
|
+
|
214
|
+
def initialize(params = {})
|
215
|
+
params.symbolize_keys!
|
216
|
+
params.assert_valid_keys(:id, :title, :subtitle, :updated_at, :links, :rights, :generator, :entries)
|
217
|
+
self.id = params[:id]
|
218
|
+
self.title = params[:title]
|
219
|
+
self.subtitle = params[:subtitle]
|
220
|
+
self.updated_at = params[:updated_at]
|
221
|
+
self.links = params[:links] || []
|
222
|
+
self.rights = params[:rights]
|
223
|
+
self.generator = params[:generator]
|
224
|
+
self.entries = params[:entries] || []
|
225
|
+
end
|
226
|
+
|
227
|
+
def updated_at
|
228
|
+
updated_times = self.entries.collect{ |entry| entry.updated_at }
|
229
|
+
updated_times << @updated_at if @updated_at
|
230
|
+
updated_times.max || Time.now
|
231
|
+
end
|
232
|
+
|
233
|
+
def handle_open_element(node, reader)
|
234
|
+
progressed = false
|
235
|
+
case [node.depth, node.uri, node.name]
|
236
|
+
when [0, NS_ATOM, 'feed']
|
237
|
+
when [1, NS_ATOM, 'title']
|
238
|
+
when [1, NS_ATOM, 'subtitle']
|
239
|
+
when [1, NS_ATOM, 'updated']
|
240
|
+
when [1, NS_ATOM, 'id']
|
241
|
+
when [1, NS_ATOM, 'link']
|
242
|
+
when [1, NS_ATOM, 'rights']
|
243
|
+
when [1, NS_ATOM, 'generator']
|
244
|
+
when [1, NS_ATOM, 'entry']
|
245
|
+
self.entries << Entry.new.deserialize(reader)
|
246
|
+
progressed = true
|
247
|
+
else
|
248
|
+
puts("Feed ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
249
|
+
end
|
250
|
+
return progressed
|
251
|
+
end
|
252
|
+
|
253
|
+
def handle_close_element(node)
|
254
|
+
case [node.depth, node.uri, node.name]
|
255
|
+
when [0, NS_ATOM, 'feed']
|
256
|
+
when [1, NS_ATOM, 'title']
|
257
|
+
self.title = node.text
|
258
|
+
when [1, NS_ATOM, 'subtitle']
|
259
|
+
self.subtitle = node.text
|
260
|
+
when [1, NS_ATOM, 'updated']
|
261
|
+
self.updated_at = Time.parse(node.text)
|
262
|
+
when [1, NS_ATOM, 'id']
|
263
|
+
self.id = node.text
|
264
|
+
when [1, NS_ATOM, 'link']
|
265
|
+
self.links << {:href => node.attributes['href'], :rel => node.attributes['rel'], :type => node.attributes['type']}
|
266
|
+
when [1, NS_ATOM, 'rights']
|
267
|
+
self.rights = node.text
|
268
|
+
when [1, NS_ATOM, 'generator']
|
269
|
+
self.generator = node.text
|
270
|
+
when [1, NS_ATOM, 'entry']
|
271
|
+
else
|
272
|
+
puts("Feed ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def to_hash
|
277
|
+
{
|
278
|
+
:id => self.id,
|
279
|
+
:title => self.title,
|
280
|
+
:subtitle => self.subtitle,
|
281
|
+
:updated_at => self.updated_at,
|
282
|
+
:links => self.links,
|
283
|
+
:rights => self.rights,
|
284
|
+
:generator => self.generator,
|
285
|
+
:entries => self.entries.collect { |entry| entry.to_hash }
|
286
|
+
}
|
287
|
+
end
|
288
|
+
|
289
|
+
def to_xml(as_document=true, target=nil)
|
290
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM} : {}
|
291
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
292
|
+
xml.instruct! if as_document
|
293
|
+
xml.atom(:feed, nsdec) do
|
294
|
+
xml.atom(:id, self.id)
|
295
|
+
xml.atom(:title, self.title)
|
296
|
+
xml.atom(:updated, self.updated_at.iso8601)
|
297
|
+
xml.atom(:subtitle, self.subtitle) if self.subtitle
|
298
|
+
self.links.each do |link|
|
299
|
+
xml.atom(:link, link)
|
300
|
+
end
|
301
|
+
xml.atom(:rights, self.rights) if self.rights
|
302
|
+
xml.atom(:generator, self.generator) if self.generator
|
303
|
+
self.entries.each do |entry|
|
304
|
+
entry.to_xml(false, xml)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
xml.target!
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
begin
|
2
|
+
require 'builder'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'builder'
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'activesupport'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
require 'activesupport'
|
13
|
+
end
|
14
|
+
|
15
|
+
module Atomic
|
16
|
+
module Atompub
|
17
|
+
class Collection
|
18
|
+
|
19
|
+
include Parser
|
20
|
+
|
21
|
+
attr_accessor :href, :title, :accepts, :categories
|
22
|
+
|
23
|
+
def initialize(params = {})
|
24
|
+
params.symbolize_keys!
|
25
|
+
params.assert_valid_keys(:href, :title, :accepts, :categories)
|
26
|
+
self.href = params[:href]
|
27
|
+
self.title = params[:title]
|
28
|
+
self.accepts = params[:accepts] || []
|
29
|
+
self.categories = params[:categories] || []
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_open_element(node, reader)
|
33
|
+
progressed = false
|
34
|
+
case [node.depth, node.uri, node.name]
|
35
|
+
when [0, NS_APP, 'collection']
|
36
|
+
when [1, NS_ATOM, 'title']
|
37
|
+
when [1, NS_APP, 'accept']
|
38
|
+
when [1, NS_APP, 'categories']
|
39
|
+
@processing_categories = true
|
40
|
+
when [2, NS_APP, 'category']
|
41
|
+
else
|
42
|
+
puts("Collection ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
43
|
+
end
|
44
|
+
return progressed
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_close_element(node)
|
48
|
+
case [node.depth, node.uri, node.name]
|
49
|
+
when [0, NS_APP, 'collection']
|
50
|
+
self.href = node.attributes['href']
|
51
|
+
when [1, NS_ATOM, 'title']
|
52
|
+
self.title = node.text
|
53
|
+
when [1, NS_APP, 'accept']
|
54
|
+
self.accepts << node.text
|
55
|
+
when [1, NS_APP, 'categories']
|
56
|
+
@processing_categories = false
|
57
|
+
when [2, NS_APP, 'category']
|
58
|
+
self.categories << {:scheme => node.attributes['scheme'], :term => node.attributes['term']} if @processing_categories
|
59
|
+
else
|
60
|
+
puts("Collection ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_hash
|
65
|
+
{
|
66
|
+
:href => self.href,
|
67
|
+
:title => self.title,
|
68
|
+
:accepts => self.accepts,
|
69
|
+
:categories => self.categories
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_xml(as_document=true, target=nil)
|
74
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM, :"xmlns:app" => NS_APP} : {}
|
75
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
76
|
+
xml.instruct! if as_document
|
77
|
+
xml.app(:collection, nsdec.merge({:href => self.href})) do
|
78
|
+
xml.atom(:title, self.title)
|
79
|
+
self.accepts.each do |accept|
|
80
|
+
xml.app(:accept, accept)
|
81
|
+
end
|
82
|
+
xml.app(:categories) do
|
83
|
+
self.categories.each do |category|
|
84
|
+
xml.app(:category, category)
|
85
|
+
end
|
86
|
+
end unless categories.empty?
|
87
|
+
end
|
88
|
+
xml.target!
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
class Workspace
|
94
|
+
|
95
|
+
include Parser
|
96
|
+
attr_accessor :title, :collections
|
97
|
+
|
98
|
+
def initialize(params = {})
|
99
|
+
params.symbolize_keys!
|
100
|
+
params.assert_valid_keys(:title, :collections)
|
101
|
+
self.title = params[:title]
|
102
|
+
self.collections = params[:collections] || []
|
103
|
+
end
|
104
|
+
|
105
|
+
def handle_open_element(node, reader)
|
106
|
+
progressed = false
|
107
|
+
case [node.depth, node.uri, node.name]
|
108
|
+
when [0, NS_APP, 'workspace']
|
109
|
+
when [1, NS_ATOM, 'title']
|
110
|
+
when [1, NS_APP, 'collection']
|
111
|
+
self.collections << Collection.new.deserialize(reader)
|
112
|
+
progressed = true
|
113
|
+
else
|
114
|
+
puts("Workspace ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
115
|
+
end
|
116
|
+
return progressed
|
117
|
+
end
|
118
|
+
|
119
|
+
def handle_close_element(node)
|
120
|
+
case [node.depth, node.uri, node.name]
|
121
|
+
when [0, NS_APP, 'workspace']
|
122
|
+
when [1, NS_ATOM, 'title']
|
123
|
+
self.title = node.text
|
124
|
+
when [1, NS_APP, 'collection']
|
125
|
+
else
|
126
|
+
puts("Workspace ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def to_hash
|
131
|
+
{
|
132
|
+
:title => self.title,
|
133
|
+
:collections => self.collections.collect{ |collection| collection.to_hash }
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_xml(as_document=true, target=nil)
|
138
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM, :"xmlns:app" => NS_APP} : {}
|
139
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
140
|
+
xml.instruct! if as_document
|
141
|
+
xml.app(:workspace, nsdec) do
|
142
|
+
xml.atom(:title, self.title)
|
143
|
+
self.collections.each do |collection|
|
144
|
+
collection.to_xml(false, xml)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
xml.target!
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
class Service
|
154
|
+
|
155
|
+
include Parser
|
156
|
+
attr_accessor :workspaces
|
157
|
+
|
158
|
+
def initialize(params = {})
|
159
|
+
params.symbolize_keys!
|
160
|
+
params.assert_valid_keys(:workspaces)
|
161
|
+
self.workspaces = params[:workspaces] || []
|
162
|
+
end
|
163
|
+
|
164
|
+
def handle_open_element(node, reader)
|
165
|
+
progressed = false
|
166
|
+
case [node.depth, node.uri, node.name]
|
167
|
+
when [0, NS_APP, 'service']
|
168
|
+
when [1, NS_APP, 'workspace']
|
169
|
+
self.workspaces << Workspace.new.deserialize(reader)
|
170
|
+
progressed = true
|
171
|
+
else
|
172
|
+
puts("Service ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
173
|
+
end
|
174
|
+
return progressed
|
175
|
+
end
|
176
|
+
|
177
|
+
def handle_close_element(node)
|
178
|
+
case [node.depth, node.uri, node.name]
|
179
|
+
when [0, NS_APP, 'service']
|
180
|
+
when [1, NS_APP, 'workspace']
|
181
|
+
else
|
182
|
+
puts("Service ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def to_hash
|
187
|
+
{
|
188
|
+
:workspaces => self.workspaces.collect { |workspace| workspace.to_hash }
|
189
|
+
}
|
190
|
+
end
|
191
|
+
|
192
|
+
def to_xml(as_document=true, target=nil)
|
193
|
+
nsdec = as_document ? {:"xmlns:atom" => NS_ATOM, :"xmlns:app" => NS_APP} : {}
|
194
|
+
xml = Builder::XmlMarkup.new(:target => target)
|
195
|
+
xml.instruct! if as_document
|
196
|
+
xml.app(:service, nsdec) do
|
197
|
+
self.workspaces.each do |workspace|
|
198
|
+
workspace.to_xml(false, xml)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
xml.target!
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
data/lib/atomic/parser.rb
CHANGED
@@ -25,7 +25,6 @@ module Atomic
|
|
25
25
|
stack = []
|
26
26
|
start_depth = reader.depth
|
27
27
|
loop do
|
28
|
-
# puts "#{self.class} STACK: #{stack.inspect}"
|
29
28
|
node = Node.new(reader.depth - start_depth, reader.local_name, reader.namespace_uri, reader.attributes)
|
30
29
|
if (stack.empty? || node.depth > stack.last.depth)
|
31
30
|
# child
|
@@ -33,22 +32,18 @@ module Atomic
|
|
33
32
|
stack.last.text = reader.value unless stack.empty?
|
34
33
|
reader.read
|
35
34
|
else
|
36
|
-
# puts "#{self.class} OPEN ELEMENT: #{node.inspect}"
|
37
35
|
redo if handle_open_element(node,reader)
|
38
36
|
stack.push(node)
|
39
37
|
end
|
40
38
|
elsif(node.depth < stack.last.depth)
|
41
39
|
# parent
|
42
|
-
# puts "#{self.class} CLOSE ELEMENT: #{stack.last}"
|
43
40
|
handle_close_element(stack.last)
|
44
41
|
stack.pop
|
45
42
|
else
|
46
43
|
# sibling
|
47
|
-
# puts "#{self.class} SIB CLOSE ELEMENT: #{stack.last}"
|
48
44
|
handle_close_element(stack.last)
|
49
45
|
stack.pop
|
50
46
|
unless stack.empty?
|
51
|
-
# puts "#{self.class} SIB OPEN ELEMENT: #{node.inspect}"
|
52
47
|
redo if handle_open_element(node,reader)
|
53
48
|
stack.push(node)
|
54
49
|
end
|
@@ -56,6 +51,7 @@ module Atomic
|
|
56
51
|
break if stack.empty?
|
57
52
|
reader.read
|
58
53
|
end
|
54
|
+
return self
|
59
55
|
end
|
60
56
|
|
61
57
|
def handle_open_element(node, reader)
|
data/lib/atomic.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/atomic/parser'
|
2
|
-
require File.dirname(__FILE__) + '/atomic/
|
3
|
-
require File.dirname(__FILE__) + '/atomic/
|
4
|
-
require File.dirname(__FILE__) + '/atomic/feed'
|
5
|
-
require File.dirname(__FILE__) + '/atomic/entry'
|
2
|
+
require File.dirname(__FILE__) + '/atomic/atom'
|
3
|
+
require File.dirname(__FILE__) + '/atomic/atompub'
|
6
4
|
require File.dirname(__FILE__) + '/atomic/extensions'
|
7
5
|
|
8
6
|
Atomic::NS_ATOM = "http://www.w3.org/2005/Atom"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AtomicSpecHelper
|
2
|
+
|
3
|
+
def valid_entry_attributes
|
4
|
+
{
|
5
|
+
:id => "entry_id",
|
6
|
+
:title => "Atom Entry Title",
|
7
|
+
:categories => [
|
8
|
+
{:term => 'treforest', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/locations'},
|
9
|
+
{:term => 'hesas', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/categories'}
|
10
|
+
],
|
11
|
+
:content => {
|
12
|
+
:message=>"Test Announcement Message",
|
13
|
+
:starts_at=>"2009-02-10T08:00:00Z",
|
14
|
+
:ends_at=>"2009-02-10T17:00:00Z"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_feed_attributes
|
20
|
+
{
|
21
|
+
:id => 'feed_id',
|
22
|
+
:title => 'Feed Title',
|
23
|
+
:entries => [
|
24
|
+
Atomic::Atom::Entry.new(valid_entry_attributes)
|
25
|
+
]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_collection_attributes
|
30
|
+
{
|
31
|
+
:href => 'http://example.org/collection',
|
32
|
+
:title => 'Collection Title',
|
33
|
+
:accepts => ['application/atom+xml;type=entry'],
|
34
|
+
:categories => [
|
35
|
+
{:scheme => 'http://example.org/scheme', :term => 'category1'},
|
36
|
+
{:scheme => 'http://example.org/scheme', :term => 'category2'}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_workspace_attributes
|
42
|
+
{
|
43
|
+
:title => 'Workspace Title',
|
44
|
+
:collections => [Atomic::Atompub::Collection.new(valid_collection_attributes)]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid_service_attributes
|
49
|
+
{
|
50
|
+
:workspaces => [Atomic::Atompub::Workspace.new(valid_workspace_attributes)]
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/atomic/entry_spec.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/atomic_spec_helper'
|
2
3
|
#require 'time'
|
3
4
|
|
4
|
-
describe Atomic::Entry do
|
5
|
-
|
6
|
-
|
7
|
-
{
|
8
|
-
:id => "123abc",
|
9
|
-
:title => "Atom Entry Title",
|
10
|
-
:categories => [
|
11
|
-
{:term => 'treforest', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/locations'},
|
12
|
-
{:term => 'hesas', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/categories'}
|
13
|
-
],
|
14
|
-
:content => {
|
15
|
-
:message=>"Test Announcement Message",
|
16
|
-
:starts_at=>"2009-02-10T08:00:00Z",
|
17
|
-
:ends_at=>"2009-02-10T17:00:00Z"
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
5
|
+
describe Atomic::Atom::Entry do
|
6
|
+
|
7
|
+
include AtomicSpecHelper
|
21
8
|
|
22
9
|
before :each do
|
23
10
|
@xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_entry.xml'))
|
@@ -28,11 +15,11 @@ describe Atomic::Entry do
|
|
28
15
|
describe "#parse" do
|
29
16
|
|
30
17
|
before :each do
|
31
|
-
@entry = Atomic::Entry.parse(@xml)
|
18
|
+
@entry = Atomic::Atom::Entry.parse(@xml)
|
32
19
|
end
|
33
20
|
|
34
21
|
it "should return a new Atomic::Entry" do
|
35
|
-
@entry.should be_an(Atomic::Entry)
|
22
|
+
@entry.should be_an(Atomic::Atom::Entry)
|
36
23
|
end
|
37
24
|
|
38
25
|
it "should decode a valid Atom Entry xml document" do
|
@@ -57,14 +44,14 @@ describe Atomic::Entry do
|
|
57
44
|
describe "#new" do
|
58
45
|
|
59
46
|
it "should return a new Atomic::Entry" do
|
60
|
-
entry = Atomic::Entry.new(
|
61
|
-
entry.should be_an(Atomic::Entry)
|
47
|
+
entry = Atomic::Atom::Entry.new(valid_entry_attributes)
|
48
|
+
entry.should be_an(Atomic::Atom::Entry)
|
62
49
|
end
|
63
50
|
|
64
51
|
it "should set created_at and updated_at to current time if not supplied" do
|
65
52
|
now = Time.now
|
66
53
|
Time.stub!(:now).and_return(now)
|
67
|
-
entry = Atomic::Entry.new(
|
54
|
+
entry = Atomic::Atom::Entry.new(valid_entry_attributes)
|
68
55
|
entry.created_at.should be_a(Time)
|
69
56
|
entry.created_at.should == now
|
70
57
|
entry.updated_at.should be_a(Time)
|
@@ -74,7 +61,7 @@ describe Atomic::Entry do
|
|
74
61
|
it "should set created_at to supplied time" do
|
75
62
|
now = Time.now
|
76
63
|
Time.stub!(:now).and_return(now)
|
77
|
-
entry = Atomic::Entry.new(
|
64
|
+
entry = Atomic::Atom::Entry.new(valid_entry_attributes.merge(:created_at => '2009-02-10T08:00:00Z'))
|
78
65
|
entry.created_at.should == Time.parse('2009-02-10T08:00:00Z')
|
79
66
|
entry.created_at.should be_a(Time)
|
80
67
|
end
|
@@ -82,7 +69,7 @@ describe Atomic::Entry do
|
|
82
69
|
it "should set updated_at to supplied time" do
|
83
70
|
now = Time.now
|
84
71
|
Time.stub!(:now).and_return(now)
|
85
|
-
entry = Atomic::Entry.new(
|
72
|
+
entry = Atomic::Atom::Entry.new(valid_entry_attributes.merge(:updated_at => '2009-02-10T08:00:00Z'))
|
86
73
|
entry.updated_at.should == Time.parse('2009-02-10T08:00:00Z')
|
87
74
|
entry.updated_at.should be_a(Time)
|
88
75
|
end
|
@@ -96,7 +83,7 @@ describe Atomic::Entry do
|
|
96
83
|
before :each do
|
97
84
|
@now = Time.now
|
98
85
|
Time.stub!(:now).and_return(@now)
|
99
|
-
@entry = Atomic::Entry.new(
|
86
|
+
@entry = Atomic::Atom::Entry.new(valid_entry_attributes)
|
100
87
|
end
|
101
88
|
|
102
89
|
it "should return a hash" do
|
@@ -105,22 +92,22 @@ describe Atomic::Entry do
|
|
105
92
|
|
106
93
|
it "should include the id" do
|
107
94
|
@entry.to_hash.should have_key(:id)
|
108
|
-
@entry.to_hash[:id].should ==
|
95
|
+
@entry.to_hash[:id].should == valid_entry_attributes[:id]
|
109
96
|
end
|
110
97
|
|
111
98
|
it "should include the title" do
|
112
99
|
@entry.to_hash.should have_key(:title)
|
113
|
-
@entry.to_hash[:title].should ==
|
100
|
+
@entry.to_hash[:title].should == valid_entry_attributes[:title]
|
114
101
|
end
|
115
102
|
|
116
103
|
it "should include the categories" do
|
117
104
|
@entry.to_hash.should have_key(:categories)
|
118
|
-
@entry.to_hash[:categories].should ==
|
105
|
+
@entry.to_hash[:categories].should == valid_entry_attributes[:categories]
|
119
106
|
end
|
120
107
|
|
121
108
|
it "should include the content" do
|
122
109
|
@entry.to_hash.should have_key(:content)
|
123
|
-
@entry.to_hash[:content].should ==
|
110
|
+
@entry.to_hash[:content].should == valid_entry_attributes[:content]
|
124
111
|
end
|
125
112
|
|
126
113
|
it "should include the created_at time" do
|
@@ -134,6 +121,21 @@ describe Atomic::Entry do
|
|
134
121
|
end
|
135
122
|
|
136
123
|
end
|
124
|
+
|
125
|
+
describe "#to_xml" do
|
126
|
+
|
127
|
+
before :each do
|
128
|
+
@now = Time.now
|
129
|
+
Time.stub!(:now).and_return(@now)
|
130
|
+
@entry = Atomic::Atom::Entry.new(valid_entry_attributes)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should work" do
|
134
|
+
puts @entry.to_xml(true)
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
137
139
|
|
138
140
|
end
|
139
141
|
|
data/spec/atomic/feed_spec.rb
CHANGED
@@ -1,12 +1,37 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/atomic_spec_helper'
|
3
|
+
|
4
|
+
describe Atomic::Atom::Feed do
|
5
|
+
|
6
|
+
include AtomicSpecHelper
|
7
|
+
|
8
|
+
describe "#new" do
|
2
9
|
|
3
|
-
describe Atomic::Feed do
|
4
|
-
before(:each) do
|
5
10
|
end
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
describe "#parse" do
|
13
|
+
before(:each) do
|
14
|
+
@xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_feed.xml'))
|
15
|
+
@feed = Atomic::Atom::Feed.parse(@xml)
|
16
|
+
end
|
17
|
+
it "should work" do
|
18
|
+
|
19
|
+
end
|
10
20
|
end
|
21
|
+
|
22
|
+
describe "#to_hash" do
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#to_xml" do
|
27
|
+
before(:each) do
|
28
|
+
@feed = Atomic::Atom::Feed.new(valid_feed_attributes)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should work" do
|
32
|
+
puts @feed.to_xml(true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
11
36
|
end
|
12
37
|
|
data/spec/atomic/service_spec.rb
CHANGED
@@ -1,14 +1,35 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/atomic_spec_helper'
|
2
3
|
|
3
|
-
describe Atomic::Service do
|
4
|
+
describe Atomic::Atompub::Service do
|
5
|
+
|
6
|
+
include AtomicSpecHelper
|
7
|
+
|
8
|
+
describe "#new" do
|
4
9
|
|
5
|
-
before(:each) do
|
6
10
|
end
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
describe "#parse" do
|
13
|
+
it "should work" do
|
14
|
+
xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_service.xml'))
|
15
|
+
@service = Atomic::Atompub::Service.parse(xml)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#to_hash" do
|
20
|
+
|
11
21
|
end
|
22
|
+
|
23
|
+
describe "#to_xml" do
|
24
|
+
before(:each) do
|
25
|
+
@service = Atomic::Atompub::Service.new(valid_service_attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should work" do
|
29
|
+
puts @service.to_xml(true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
12
33
|
|
13
34
|
end
|
14
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exempla-atomic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darrin Wortlehock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-25 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,7 +25,7 @@ files:
|
|
25
25
|
- VERSION.yml
|
26
26
|
- lib/atomic.rb
|
27
27
|
- lib/atomic
|
28
|
-
- lib/atomic/
|
28
|
+
- lib/atomic/atompub.rb
|
29
29
|
- lib/atomic/extensions
|
30
30
|
- lib/atomic/extensions/cirrus.rb
|
31
31
|
- lib/atomic/extensions/cirrus
|
@@ -33,20 +33,20 @@ files:
|
|
33
33
|
- lib/atomic/extensions/cirrus/base.rb
|
34
34
|
- lib/atomic/extensions/cirrus/news.rb
|
35
35
|
- lib/atomic/extensions/cirrus/event.rb
|
36
|
-
- lib/atomic/entry.rb
|
37
36
|
- lib/atomic/parser.rb
|
38
|
-
- lib/atomic/person.rb
|
39
37
|
- lib/atomic/extensions.rb
|
40
|
-
- lib/atomic/
|
38
|
+
- lib/atomic/atom.rb
|
41
39
|
- spec/spec.opts
|
42
40
|
- spec/fixtures
|
43
41
|
- spec/fixtures/valid_atom_entry.xml
|
44
42
|
- spec/fixtures/valid_atom_service.xml
|
45
43
|
- spec/fixtures/valid_atom_feed.xml
|
44
|
+
- spec/fixtures/cirrus_feed.xml
|
46
45
|
- spec/spec_helper.rb
|
47
46
|
- spec/atomic
|
48
47
|
- spec/atomic/entry_spec.rb
|
49
48
|
- spec/atomic/feed_spec.rb
|
49
|
+
- spec/atomic/atomic_spec_helper.rb
|
50
50
|
- spec/atomic/parser_spec.rb
|
51
51
|
- spec/atomic/service_spec.rb
|
52
52
|
has_rdoc: true
|
data/lib/atomic/entry.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'activesupport'
|
3
|
-
|
4
|
-
module Atomic
|
5
|
-
|
6
|
-
class Entry
|
7
|
-
|
8
|
-
include Parser
|
9
|
-
|
10
|
-
attr_accessor :id, :title, :categories, :created_at, :updated_at, :content, :links, :author, :contributors
|
11
|
-
|
12
|
-
def initialize(params = {})
|
13
|
-
params.symbolize_keys!
|
14
|
-
params.assert_valid_keys(:title, :id, :categories, :created_at, :updated_at, :content)
|
15
|
-
@title = params[:title]
|
16
|
-
@id = params[:id]
|
17
|
-
@categories = params[:categories] || []
|
18
|
-
@created_at = params[:created_at].nil? ? Time.now : Time.parse(params[:created_at])
|
19
|
-
@updated_at = params[:updated_at].nil? ? @created_at : Time.parse(params[:updated_at])
|
20
|
-
@content = params[:content] || {}
|
21
|
-
@links = params[:links] || []
|
22
|
-
@author = params[:author]
|
23
|
-
@contributors = params[:contributors] || []
|
24
|
-
end
|
25
|
-
|
26
|
-
def handle_open_element(node, reader)
|
27
|
-
progressed = false
|
28
|
-
case [node.depth, node.uri, node.name]
|
29
|
-
when [0, NS_ATOM, 'entry']
|
30
|
-
when [1, NS_ATOM, 'title']
|
31
|
-
when [1, NS_ATOM, 'id']
|
32
|
-
when [1, NS_ATOM, 'published']
|
33
|
-
when [1, NS_ATOM, 'updated']
|
34
|
-
when [1, NS_ATOM, 'category']
|
35
|
-
when [1, NS_ATOM, 'author']
|
36
|
-
author = Person.new
|
37
|
-
author.deserialize(reader)
|
38
|
-
self.author = author
|
39
|
-
progressed = true
|
40
|
-
when [1, NS_ATOM, 'contributor']
|
41
|
-
contributor = Person.new
|
42
|
-
contributor.deserialize(reader)
|
43
|
-
self.contributors << contributor
|
44
|
-
progressed = true
|
45
|
-
when [1, NS_ATOM, 'content']
|
46
|
-
if node.attributes['type'] == 'application/xml'
|
47
|
-
@processing_xml_content = true
|
48
|
-
end
|
49
|
-
when [1, NS_ATOM, 'link']
|
50
|
-
else
|
51
|
-
if @processing_xml_content
|
52
|
-
extension_class = Extensions::MAP[[node.uri, node.name]]
|
53
|
-
unless extension_class.nil?
|
54
|
-
extension_class.new(self).deserialize(reader)
|
55
|
-
progressed = true
|
56
|
-
end
|
57
|
-
else
|
58
|
-
puts("Entry ==> Unexpected Open Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect}")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
return progressed
|
62
|
-
end
|
63
|
-
|
64
|
-
def handle_close_element(node)
|
65
|
-
case [node.depth, node.uri, node.name]
|
66
|
-
when [0, NS_ATOM, 'entry']
|
67
|
-
when [1, NS_ATOM, 'title']
|
68
|
-
@title = node.text
|
69
|
-
when [1, NS_ATOM, 'id']
|
70
|
-
@id = node.text
|
71
|
-
when [1, NS_ATOM, 'published']
|
72
|
-
@created_at = Time.parse(node.text)
|
73
|
-
when [1, NS_ATOM, 'updated']
|
74
|
-
@updated_at = Time.parse(node.text)
|
75
|
-
when [1, NS_ATOM, 'category']
|
76
|
-
@categories << {:scheme => node.attributes['scheme'], :term => node.attributes['term']}
|
77
|
-
when [1, NS_ATOM, 'author']
|
78
|
-
when [1, NS_ATOM, 'content']
|
79
|
-
@processing_xml_content = false
|
80
|
-
when [1, NS_ATOM, 'link']
|
81
|
-
@links << {:href => node.attributes['href'], :rel => node.attributes['rel'], :type => node.attributes['type']}
|
82
|
-
else
|
83
|
-
puts("Entry ==> Unexpected Close Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect} #{node.text}") unless @processing_xml_content
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def to_hash
|
88
|
-
{
|
89
|
-
:id => @id,
|
90
|
-
:title => @title,
|
91
|
-
:categories => @categories,
|
92
|
-
:created_at => @created_at,
|
93
|
-
:updated_at => @updated_at,
|
94
|
-
:content => @content,
|
95
|
-
:links => @links,
|
96
|
-
:author => @author
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
data/lib/atomic/feed.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Atomic
|
6
|
-
|
7
|
-
class Feed
|
8
|
-
|
9
|
-
include Parser
|
10
|
-
|
11
|
-
# class << self
|
12
|
-
#
|
13
|
-
# def parse(data)
|
14
|
-
# feed = new
|
15
|
-
# doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
16
|
-
# feed_node = doc.xpath('//atom:feed', NAMESPACES).first
|
17
|
-
# feed.title = feed_node.xpath('atom:title', NAMESPACES).first.text
|
18
|
-
# feed.id = feed_node.xpath('atom:id', NAMESPACES).first.text
|
19
|
-
# feed_node.xpath('atom:entry', NAMESPACES).each do |entry_node|
|
20
|
-
# feed.entries << Entry.parse(entry_node)
|
21
|
-
# end
|
22
|
-
# feed
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# end
|
26
|
-
|
27
|
-
attr_accessor :id, :title, :subtitle, :updated_at, :links, :rights, :generator, :entries
|
28
|
-
|
29
|
-
def initialize(params = {})
|
30
|
-
@title = params[:title]
|
31
|
-
@id = params[:id]
|
32
|
-
@entries = params[:entries] || []
|
33
|
-
@links = params[:links] || []
|
34
|
-
end
|
35
|
-
|
36
|
-
def handle_open_element(node, reader)
|
37
|
-
progressed = false
|
38
|
-
case [node.depth, node.uri, node.name]
|
39
|
-
when [0, 'http://www.w3.org/2005/Atom', 'feed']
|
40
|
-
when [1, NS_ATOM, 'title']
|
41
|
-
when [1, NS_ATOM, 'subtitle']
|
42
|
-
when [1, NS_ATOM, 'updated']
|
43
|
-
when [1, NS_ATOM, 'id']
|
44
|
-
when [1, NS_ATOM, 'link']
|
45
|
-
when [1, NS_ATOM, 'rights']
|
46
|
-
when [1, NS_ATOM, 'generator']
|
47
|
-
when [1, NS_ATOM, 'entry']
|
48
|
-
entry = Entry.new
|
49
|
-
entry.deserialize(reader)
|
50
|
-
@entries << entry
|
51
|
-
progressed = true
|
52
|
-
else
|
53
|
-
puts("Feed ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
54
|
-
end
|
55
|
-
return progressed
|
56
|
-
end
|
57
|
-
|
58
|
-
def handle_close_element(node)
|
59
|
-
case [node.depth, node.uri, node.name]
|
60
|
-
when [0, 'http://www.w3.org/2005/Atom', 'feed']
|
61
|
-
when [1, NS_ATOM, 'title']
|
62
|
-
@title = node.text
|
63
|
-
when [1, NS_ATOM, 'subtitle']
|
64
|
-
@subtitle = node.text
|
65
|
-
when [1, NS_ATOM, 'updated']
|
66
|
-
@updated_at = Time.parse(node.text)
|
67
|
-
when [1, NS_ATOM, 'id']
|
68
|
-
@id = node.text
|
69
|
-
when [1, NS_ATOM, 'link']
|
70
|
-
@links << {:href => node.attributes['href'], :rel => node.attributes['rel'], :type => node.attributes['type']}
|
71
|
-
when [1, NS_ATOM, 'rights']
|
72
|
-
@rights = node.text
|
73
|
-
when [1, NS_ATOM, 'generator']
|
74
|
-
@generator = node.text
|
75
|
-
when [1, NS_ATOM, 'entry']
|
76
|
-
else
|
77
|
-
puts("Feed ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def to_hash
|
82
|
-
{
|
83
|
-
:title => @title,
|
84
|
-
:id => @id,
|
85
|
-
:entries => @entries.collect { |entry| entry.to_hash }
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
data/lib/atomic/person.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'activesupport'
|
2
|
-
|
3
|
-
module Atomic
|
4
|
-
class Person
|
5
|
-
|
6
|
-
include Parser
|
7
|
-
|
8
|
-
attr_accessor :name, :uri, :email
|
9
|
-
|
10
|
-
def initialize(params = {})
|
11
|
-
params.symbolize_keys!
|
12
|
-
params.assert_valid_keys(:name, :uri, :email)
|
13
|
-
@name = params[:name]
|
14
|
-
@uri = params[:uri]
|
15
|
-
@email = params[:email]
|
16
|
-
end
|
17
|
-
|
18
|
-
def handle_open_element(node, reader)
|
19
|
-
progressed = false
|
20
|
-
case [node.depth, node.uri, node.name]
|
21
|
-
when [0, NS_ATOM, 'author']
|
22
|
-
when [0, NS_ATOM, 'contributor']
|
23
|
-
when [1, NS_ATOM, 'name']
|
24
|
-
when [1, NS_ATOM, 'uri']
|
25
|
-
when [1, NS_ATOM, 'email']
|
26
|
-
else
|
27
|
-
puts("Person ==> Unexpected Open Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect}")
|
28
|
-
end
|
29
|
-
return progressed
|
30
|
-
end
|
31
|
-
|
32
|
-
def handle_close_element(node)
|
33
|
-
case [node.depth, node.uri, node.name]
|
34
|
-
when [0, NS_ATOM, 'author']
|
35
|
-
when [0, NS_ATOM, 'contributor']
|
36
|
-
when [1, NS_ATOM, 'name']
|
37
|
-
@name = node.text
|
38
|
-
when [1, NS_ATOM, 'uri']
|
39
|
-
@uri = node.text
|
40
|
-
when [1, NS_ATOM, 'email']
|
41
|
-
@email = node.text
|
42
|
-
else
|
43
|
-
puts("Person ==> Unexpected Close Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect} #{node.text}")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
data/lib/atomic/service.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Atomic
|
6
|
-
|
7
|
-
class Collection
|
8
|
-
|
9
|
-
include Parser
|
10
|
-
attr_accessor :href, :title, :content_types, :categories
|
11
|
-
|
12
|
-
def initialize(params = {})
|
13
|
-
@href = params[:href]
|
14
|
-
@title = params[:title]
|
15
|
-
@content_types = params[:content_types] || []
|
16
|
-
@categories = params[:categories] || []
|
17
|
-
end
|
18
|
-
|
19
|
-
def handle_open_element(node, reader)
|
20
|
-
progressed = false
|
21
|
-
case [node.depth, node.uri, node.name]
|
22
|
-
when [0, NS_APP, 'collection']
|
23
|
-
when [1, NS_ATOM, 'title']
|
24
|
-
when [1, NS_APP, 'accept']
|
25
|
-
when [1, NS_APP, 'categories']
|
26
|
-
@processing_categories = true
|
27
|
-
when [2, NS_APP, 'category']
|
28
|
-
else
|
29
|
-
puts("Collection ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
30
|
-
end
|
31
|
-
return progressed
|
32
|
-
end
|
33
|
-
|
34
|
-
def handle_close_element(node)
|
35
|
-
case [node.depth, node.uri, node.name]
|
36
|
-
when [0, NS_APP, 'collection']
|
37
|
-
self.href = node.attributes['href']
|
38
|
-
when [1, NS_ATOM, 'title']
|
39
|
-
self.title = node.text
|
40
|
-
when [1, NS_APP, 'accept']
|
41
|
-
self.content_types << node.text
|
42
|
-
when [1, NS_APP, 'categories']
|
43
|
-
@processing_categories = false
|
44
|
-
when [2, NS_APP, 'category']
|
45
|
-
self.categories << {:scheme => node.attributes['scheme'], :term => node.attributes['term']} if @processing_categories
|
46
|
-
else
|
47
|
-
puts("Collection ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_hash
|
52
|
-
{
|
53
|
-
:href => @href,
|
54
|
-
:title => @title
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
class Workspace
|
61
|
-
|
62
|
-
include Parser
|
63
|
-
attr_accessor :title, :collections
|
64
|
-
|
65
|
-
def initialize(params = {})
|
66
|
-
@title = params[:title]
|
67
|
-
@collections = params[:collections] || []
|
68
|
-
end
|
69
|
-
|
70
|
-
def handle_open_element(node, reader)
|
71
|
-
progressed = false
|
72
|
-
case [node.depth, node.uri, node.name]
|
73
|
-
when [0, NS_APP, 'workspace']
|
74
|
-
when [1, NS_ATOM, 'title']
|
75
|
-
when [1, NS_APP, 'collection']
|
76
|
-
collection = Collection.new
|
77
|
-
collection.deserialize(reader)
|
78
|
-
self.collections << collection
|
79
|
-
progressed = true
|
80
|
-
else
|
81
|
-
puts("Workspace ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
82
|
-
end
|
83
|
-
return progressed
|
84
|
-
end
|
85
|
-
|
86
|
-
def handle_close_element(node)
|
87
|
-
case [node.depth, node.uri, node.name]
|
88
|
-
when [0, NS_APP, 'workspace']
|
89
|
-
when [1, NS_ATOM, 'title']
|
90
|
-
self.title = node.text
|
91
|
-
when [1, NS_APP, 'collection']
|
92
|
-
else
|
93
|
-
puts("Workspace ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def to_hash
|
98
|
-
{
|
99
|
-
:title => @title,
|
100
|
-
:collections => @collections.collect{ |collection| collection.to_hash }
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
class Service
|
107
|
-
|
108
|
-
include Parser
|
109
|
-
attr_accessor :workspaces
|
110
|
-
|
111
|
-
def initialize(params = {})
|
112
|
-
@workspaces = params[:workspaces] || []
|
113
|
-
end
|
114
|
-
|
115
|
-
def handle_open_element(node, reader)
|
116
|
-
progressed = false
|
117
|
-
case [node.depth, node.uri, node.name]
|
118
|
-
when [0, NS_APP, 'service']
|
119
|
-
when [1, NS_APP, 'workspace']
|
120
|
-
workspace = Workspace.new
|
121
|
-
workspace.deserialize(reader)
|
122
|
-
self.workspaces << workspace
|
123
|
-
progressed = true
|
124
|
-
else
|
125
|
-
puts("Service ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}")
|
126
|
-
end
|
127
|
-
return progressed
|
128
|
-
end
|
129
|
-
|
130
|
-
def handle_close_element(node)
|
131
|
-
case [node.depth, node.uri, node.name]
|
132
|
-
when [0, NS_APP, 'service']
|
133
|
-
when [1, NS_APP, 'workspace']
|
134
|
-
else
|
135
|
-
puts("Service ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}")
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def to_hash
|
140
|
-
{ :workspaces => @workspaces.collect { |workspace| workspace.to_hash } }
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|