exempla-atomic 0.0.3 → 0.0.4
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.rb +1 -0
- data/lib/atomic/entry.rb +25 -33
- data/lib/atomic/feed.rb +43 -0
- data/spec/atomic/feed_spec.rb +12 -0
- data/spec/fixtures/valid_atom_feed.xml +45 -0
- metadata +3 -1
data/VERSION.yml
CHANGED
data/lib/atomic.rb
CHANGED
data/lib/atomic/entry.rb
CHANGED
@@ -8,44 +8,36 @@ module Atomic
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
def parse(
|
12
|
-
|
13
|
-
doc = Nokogiri.XML(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if (content_xml['type'] == 'application/xml')
|
32
|
-
attributes[:content] = {}
|
33
|
-
|
34
|
-
announcement_xml = content_xml.xpath('cirrus:announcement', NAMESPACES).first
|
35
|
-
unless announcement_xml.nil?
|
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
|
11
|
+
def parse(data)
|
12
|
+
entry = new
|
13
|
+
doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
14
|
+
|
15
|
+
entry_node = doc.xpath('//atom:entry', NAMESPACES).first
|
16
|
+
|
17
|
+
entry.id = entry_node.xpath('atom:id', NAMESPACES).first.text
|
18
|
+
entry.title = entry_node.xpath('atom:title', NAMESPACES).first.text
|
19
|
+
entry.created_at = entry_node.xpath('atom:published', NAMESPACES).first.text
|
20
|
+
entry.updated_at = entry_node.xpath('atom:updated', NAMESPACES).first.text
|
21
|
+
|
22
|
+
content_node = entry_node.xpath('atom:content', NAMESPACES).first
|
23
|
+
|
24
|
+
if (content_node['type'] == 'application/xml')
|
25
|
+
entry.content = {}
|
26
|
+
announcement_node = content_node.xpath('cirrus:announcement', NAMESPACES).first
|
27
|
+
unless announcement_node.nil?
|
28
|
+
entry.content[:message] = announcement_node.xpath('cirrus:message', NAMESPACES).first.text
|
29
|
+
entry.content[:starts_at] = announcement_node.xpath('cirrus:starts-at', NAMESPACES).first.text
|
30
|
+
entry.content[:ends_at] = announcement_node.xpath('cirrus:ends-at', NAMESPACES).first.text
|
39
31
|
end
|
40
32
|
else
|
41
|
-
|
33
|
+
entry.content = content_node.inner_html
|
42
34
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
entry.categories = []
|
36
|
+
entry_node.xpath('atom:category', NAMESPACES).each do |category_node|
|
37
|
+
entry.categories << {:term => category_node['term'], :scheme => category_node['scheme']}
|
46
38
|
end
|
47
39
|
|
48
|
-
|
40
|
+
entry
|
49
41
|
end
|
50
42
|
|
51
43
|
end
|
data/lib/atomic/feed.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Atomic
|
6
|
+
|
7
|
+
class Feed
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def parse(data)
|
12
|
+
feed = new
|
13
|
+
doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data)
|
14
|
+
feed_node = doc.xpath('//atom:feed', NAMESPACES).first
|
15
|
+
feed.title = feed_node.xpath('atom:title', NAMESPACES).first.text
|
16
|
+
feed.id = feed_node.xpath('atom:id', NAMESPACES).first.text
|
17
|
+
feed_node.xpath('atom:entry', NAMESPACES).each do |entry_node|
|
18
|
+
feed.entries << Entry.parse(entry_node)
|
19
|
+
end
|
20
|
+
feed
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :title, :id, :entries
|
26
|
+
|
27
|
+
def initialize(params = {})
|
28
|
+
@title = params[:title]
|
29
|
+
@id = params[:id]
|
30
|
+
@entries = params[:entries] || []
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
{
|
35
|
+
:title => @title,
|
36
|
+
:id => @id,
|
37
|
+
:entries => @entries.collect { |entry| entry.to_hash }
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Atomic::Feed do
|
4
|
+
before(:each) do
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should work" do
|
8
|
+
xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_feed.xml'))
|
9
|
+
@feed = Atomic::Feed.parse(xml)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
|
+
<title type="text">dive into mark</title>
|
4
|
+
<subtitle type="html">
|
5
|
+
A <em>lot</em> of effort
|
6
|
+
went into making this effortless
|
7
|
+
</subtitle>
|
8
|
+
<updated>2005-07-31T12:29:29Z</updated>
|
9
|
+
<id>tag:example.org,2003:3</id>
|
10
|
+
<link rel="alternate" type="text/html"
|
11
|
+
hreflang="en" href="http://example.org/"/>
|
12
|
+
<link rel="self" type="application/atom+xml"
|
13
|
+
href="http://example.org/feed.atom"/>
|
14
|
+
<rights>Copyright (c) 2003, Mark Pilgrim</rights>
|
15
|
+
<generator uri="http://www.example.com/" version="1.0">
|
16
|
+
Example Toolkit
|
17
|
+
</generator>
|
18
|
+
<entry>
|
19
|
+
<title>Atom draft-07 snapshot</title>
|
20
|
+
<link rel="alternate" type="text/html"
|
21
|
+
href="http://example.org/2005/04/02/atom"/>
|
22
|
+
<link rel="enclosure" type="audio/mpeg" length="1337"
|
23
|
+
href="http://example.org/audio/ph34r_my_podcast.mp3"/>
|
24
|
+
<id>tag:example.org,2003:3.2397</id>
|
25
|
+
<updated>2005-07-31T12:29:29Z</updated>
|
26
|
+
<published>2003-12-13T08:29:29-04:00</published>
|
27
|
+
<author>
|
28
|
+
<name>Mark Pilgrim</name>
|
29
|
+
<uri>http://example.org/</uri>
|
30
|
+
<email>f8dy@example.com</email>
|
31
|
+
</author>
|
32
|
+
<contributor>
|
33
|
+
<name>Sam Ruby</name>
|
34
|
+
</contributor>
|
35
|
+
<contributor>
|
36
|
+
<name>Joe Gregorio</name>
|
37
|
+
</contributor>
|
38
|
+
<content type="xhtml" xml:lang="en"
|
39
|
+
xml:base="http://diveintomark.org/">
|
40
|
+
<div xmlns="http://www.w3.org/1999/xhtml">
|
41
|
+
<p><i>[Update: The Atom draft is finished.]</i></p>
|
42
|
+
</div>
|
43
|
+
</content>
|
44
|
+
</entry>
|
45
|
+
</feed>
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darrin Wortlehock
|
@@ -33,9 +33,11 @@ files:
|
|
33
33
|
- spec/fixtures
|
34
34
|
- spec/fixtures/valid_atom_entry.xml
|
35
35
|
- spec/fixtures/valid_atom_service.xml
|
36
|
+
- spec/fixtures/valid_atom_feed.xml
|
36
37
|
- spec/spec_helper.rb
|
37
38
|
- spec/atomic
|
38
39
|
- spec/atomic/entry_spec.rb
|
40
|
+
- spec/atomic/feed_spec.rb
|
39
41
|
- spec/atomic/service_spec.rb
|
40
42
|
has_rdoc: true
|
41
43
|
homepage: http://github.com/exempla/atomic
|