exempla-atomic 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/atomic/entry.rb +11 -15
- data/lib/atomic/service.rb +85 -0
- data/lib/atomic.rb +6 -1
- data/spec/atomic/service_spec.rb +14 -0
- data/spec/fixtures/valid_atom_service.xml +36 -0
- metadata +6 -1
data/VERSION.yml
CHANGED
data/lib/atomic/entry.rb
CHANGED
@@ -10,10 +10,6 @@ module Atomic
|
|
10
10
|
|
11
11
|
def parse(xml)
|
12
12
|
|
13
|
-
namespaces = { "xmlns:atom" => "http://www.w3.org/2005/Atom",
|
14
|
-
"xmlns:app" => "http://www.w3.org/2007/app",
|
15
|
-
"xmlns:cirrus" => "http://www.glam.ac.uk/2009/cirrus" }
|
16
|
-
|
17
13
|
doc = Nokogiri.XML(xml)
|
18
14
|
|
19
15
|
# puts("================================================================")
|
@@ -22,30 +18,30 @@ module Atomic
|
|
22
18
|
# puts(doc)
|
23
19
|
# puts("================================================================")
|
24
20
|
|
25
|
-
entry_xml = doc.xpath('//atom:entry',
|
21
|
+
entry_xml = doc.xpath('//atom:entry', NAMESPACES).first
|
26
22
|
|
27
23
|
attributes = {}
|
28
|
-
attributes[:id] = entry_xml.xpath('atom:id',
|
29
|
-
attributes[:title] = entry_xml.xpath('atom:title',
|
30
|
-
attributes[:created_at] = entry_xml.xpath('atom:published',
|
31
|
-
attributes[:updated_at] = entry_xml.xpath('atom:updated',
|
24
|
+
attributes[:id] = entry_xml.xpath('atom:id', NAMESPACES).first.text
|
25
|
+
attributes[:title] = entry_xml.xpath('atom:title', NAMESPACES).first.text
|
26
|
+
attributes[:created_at] = entry_xml.xpath('atom:published', NAMESPACES).first.text
|
27
|
+
attributes[:updated_at] = entry_xml.xpath('atom:updated', NAMESPACES).first.text
|
32
28
|
|
33
|
-
content_xml = entry_xml.xpath('atom:content',
|
29
|
+
content_xml = entry_xml.xpath('atom:content', NAMESPACES).first
|
34
30
|
|
35
31
|
if (content_xml['type'] == 'application/xml')
|
36
32
|
attributes[:content] = {}
|
37
33
|
|
38
|
-
announcement_xml = content_xml.xpath('cirrus:announcement',
|
34
|
+
announcement_xml = content_xml.xpath('cirrus:announcement', NAMESPACES).first
|
39
35
|
unless announcement_xml.nil?
|
40
|
-
attributes[:content][:message] = announcement_xml.xpath('cirrus:message',
|
41
|
-
attributes[:content][:starts_at] = announcement_xml.xpath('cirrus:starts-at',
|
42
|
-
attributes[:content][:ends_at] = announcement_xml.xpath('cirrus:ends-at',
|
36
|
+
attributes[:content][:message] = announcement_xml.xpath('cirrus:message', NAMESPACES).first.text
|
37
|
+
attributes[:content][:starts_at] = announcement_xml.xpath('cirrus:starts-at', NAMESPACES).first.text
|
38
|
+
attributes[:content][:ends_at] = announcement_xml.xpath('cirrus:ends-at', NAMESPACES).first.text
|
43
39
|
end
|
44
40
|
else
|
45
41
|
attributes[:content] = content_xml.inner_html
|
46
42
|
end
|
47
43
|
attributes[:categories] = []
|
48
|
-
entry_xml.xpath('atom:category',
|
44
|
+
entry_xml.xpath('atom:category', NAMESPACES).each do |category_node|
|
49
45
|
attributes[:categories] << {:term => category_node['term'], :scheme => category_node['scheme']}
|
50
46
|
end
|
51
47
|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Atomic
|
6
|
+
|
7
|
+
class Workspace
|
8
|
+
class << self
|
9
|
+
def parse(data)
|
10
|
+
workspace = new
|
11
|
+
doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
12
|
+
workspace_node = doc.xpath('//app:workspace', NAMESPACES).first
|
13
|
+
workspace.title = workspace_node.xpath('atom:title', NAMESPACES).first.text
|
14
|
+
workspace_node.xpath('app:collection', NAMESPACES).each do |collection_node|
|
15
|
+
workspace.collections << Collection.parse(collection_node)
|
16
|
+
end
|
17
|
+
workspace
|
18
|
+
end
|
19
|
+
end
|
20
|
+
attr_accessor :title, :collections
|
21
|
+
def initialize(params = {})
|
22
|
+
@title = params[:title]
|
23
|
+
@collections = params[:collections] || []
|
24
|
+
end
|
25
|
+
def to_hash
|
26
|
+
{
|
27
|
+
:title => @title,
|
28
|
+
:collections => @collections.collect{ |collection| collection.to_hash }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Collection
|
34
|
+
class << self
|
35
|
+
def parse(data)
|
36
|
+
collection = new
|
37
|
+
doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
38
|
+
collection_node = doc.xpath('//app:collection', NAMESPACES).first
|
39
|
+
collection.href = collection_node['href']
|
40
|
+
collection.title = collection_node.xpath('atom:title', NAMESPACES).first.text
|
41
|
+
collection
|
42
|
+
end
|
43
|
+
end
|
44
|
+
attr_accessor :href, :title
|
45
|
+
def initialize(params = {})
|
46
|
+
@href = params[:href]
|
47
|
+
@title = params[:title]
|
48
|
+
end
|
49
|
+
def to_hash
|
50
|
+
{
|
51
|
+
:href => @href,
|
52
|
+
:title => @title
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Service
|
58
|
+
|
59
|
+
class << self
|
60
|
+
|
61
|
+
def parse(data)
|
62
|
+
service = new
|
63
|
+
doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
64
|
+
service_node = doc.xpath('//app:service', NAMESPACES).first
|
65
|
+
service_node.xpath('app:workspace', NAMESPACES).each do |workspace_node|
|
66
|
+
service.workspaces << Workspace.parse(workspace_node)
|
67
|
+
end
|
68
|
+
service
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_accessor :workspaces
|
74
|
+
|
75
|
+
def initialize(params = {})
|
76
|
+
@workspaces = params[:workspaces] || []
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_hash
|
80
|
+
{ :workspaces => @workspaces.collect { |workspace| workspace.to_hash } }
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/lib/atomic.rb
CHANGED
@@ -1 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/atomic/
|
1
|
+
require File.dirname(__FILE__) + '/atomic/service'
|
2
|
+
require File.dirname(__FILE__) + '/atomic/entry'
|
3
|
+
|
4
|
+
Atomic::NAMESPACES = { "xmlns:atom" => "http://www.w3.org/2005/Atom",
|
5
|
+
"xmlns:app" => "http://www.w3.org/2007/app",
|
6
|
+
"xmlns:cirrus" => "http://www.glam.ac.uk/2009/cirrus" }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Atomic::Service do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should work" do
|
9
|
+
xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_service.xml'))
|
10
|
+
@service = Atomic::Service.parse(xml)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<service xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/2007/app">
|
3
|
+
<workspace>
|
4
|
+
<atom:title>Workspace Title</atom:title>
|
5
|
+
<collection href="http://localhost:4000/collections/announcements/entries">
|
6
|
+
<atom:title>Announcements</atom:title>
|
7
|
+
<accept>application/atom+xml;type=entry</accept>
|
8
|
+
<categories>
|
9
|
+
|
10
|
+
<category term="treforest" scheme="http://localhost:4000/schemes/locations"/>
|
11
|
+
<category term="glyntaff" scheme="http://localhost:4000/schemes/locations"/>
|
12
|
+
<category term="atrium" scheme="http://localhost:4000/schemes/locations"/>
|
13
|
+
<category term="bus" scheme="http://localhost:4000/schemes/faculties"/>
|
14
|
+
<category term="cell" scheme="http://localhost:4000/schemes/faculties"/>
|
15
|
+
<category term="hass" scheme="http://localhost:4000/schemes/faculties"/>
|
16
|
+
<category term="hesas" scheme="http://localhost:4000/schemes/faculties"/>
|
17
|
+
<category term="fat" scheme="http://localhost:4000/schemes/faculties"/>
|
18
|
+
<category term="cci" scheme="http://localhost:4000/schemes/faculties"/>
|
19
|
+
|
20
|
+
</categories>
|
21
|
+
</collection>
|
22
|
+
<collection href="http://localhost:4000/collections/news/entries">
|
23
|
+
<atom:title>News</atom:title>
|
24
|
+
<accept>application/atom+xml;type=entry</accept>
|
25
|
+
<categories>
|
26
|
+
</categories>
|
27
|
+
</collection>
|
28
|
+
|
29
|
+
<collection href="http://localhost:4000/collections/events/entries">
|
30
|
+
<atom:title>Events</atom:title>
|
31
|
+
<accept>application/atom+xml;type=entry</accept>
|
32
|
+
<categories>
|
33
|
+
</categories>
|
34
|
+
</collection>
|
35
|
+
</workspace>
|
36
|
+
</service>
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darrin Wortlehock
|
@@ -25,13 +25,18 @@ files:
|
|
25
25
|
- VERSION.yml
|
26
26
|
- lib/atomic.rb
|
27
27
|
- lib/atomic
|
28
|
+
- lib/atomic/service.rb
|
28
29
|
- lib/atomic/entry.rb
|
30
|
+
- lib/atomic/category.rb
|
31
|
+
- lib/atomic/feed.rb
|
29
32
|
- spec/spec.opts
|
30
33
|
- spec/fixtures
|
31
34
|
- spec/fixtures/valid_atom_entry.xml
|
35
|
+
- spec/fixtures/valid_atom_service.xml
|
32
36
|
- spec/spec_helper.rb
|
33
37
|
- spec/atomic
|
34
38
|
- spec/atomic/entry_spec.rb
|
39
|
+
- spec/atomic/service_spec.rb
|
35
40
|
has_rdoc: true
|
36
41
|
homepage: http://github.com/exempla/atomic
|
37
42
|
post_install_message:
|