From 937de70c03b3af6f78338755794385c6f74f7df1 Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 23 Jan 2014 17:37:50 -0200 Subject: [PATCH] added Extension to channel --- channel.go | 1 + feed_test.go | 30 ++++++++++++++++++++++++++++++ rss.go | 9 +++++++++ testdata/extension.rss | 9 ++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/channel.go b/channel.go index fe3318b..dc3104f 100644 --- a/channel.go +++ b/channel.go @@ -21,6 +21,7 @@ type Channel struct { Items []*Item Cloud Cloud TextInput Input + Extensions map[string]map[string][]Extension // Atom fields Id string diff --git a/feed_test.go b/feed_test.go index cdd39cf..8566533 100644 --- a/feed_test.go +++ b/feed_test.go @@ -101,6 +101,36 @@ func Test_ItemExtensions(t *testing.T) { } } +func Test_ChannelExtensions(t *testing.T) { + content, _ := ioutil.ReadFile("testdata/extension.rss") + feed := New(1, true, chanHandler, itemHandler) + feed.FetchBytes("http://example.com", content, nil) + + channel := feed.Channels[0] + itunesExtentions := channel.Extensions["http://www.itunes.com/dtds/podcast-1.0.dtd"] + + authorExptected := "The Author" + ownerEmailExpected := "test@rss.com" + categoryExpected := "Politics" + imageExptected := "http://golang.org/doc/gopher/project.png" + + if itunesExtentions["author"][0].Value != authorExptected { + t.Errorf("Expected author to be %s but found %s", authorExptected, itunesExtentions["author"][0].Value) + } + + if itunesExtentions["owner"][0].Childrens["email"][0].Value != ownerEmailExpected { + t.Errorf("Expected owner email to be %s but found %s", ownerEmailExpected, itunesExtentions["owner"][0].Childrens["email"][0].Value) + } + + if itunesExtentions["category"][0].Attrs["text"] != categoryExpected { + t.Errorf("Expected category text to be %s but found %s", categoryExpected, itunesExtentions["category"][0].Attrs["text"]) + } + + if itunesExtentions["image"][0].Attrs["href"] != imageExptected { + t.Errorf("Expected image href to be %s but found %s", imageExptected, itunesExtentions["image"][0].Attrs["href"]) + } +} + func Test_CData(t *testing.T) { content, _ := ioutil.ReadFile("testdata/iosBoardGameGeek.rss") feed := New(1, true, chanHandler, itemHandler) diff --git a/rss.go b/rss.go index 484a8c7..f990e59 100644 --- a/rss.go +++ b/rss.go @@ -189,6 +189,15 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) { ch.Items = append(ch.Items, i) } + + x := node.SelectNodes(ns, ns) + ch.Extensions = make(map[string]map[string][]Extension) + for _, v := range x { + if v.Name.Space != "" { + getExtensions(&ch.Extensions, v) + } + } + } this.Channels = foundChannels return diff --git a/testdata/extension.rss b/testdata/extension.rss index 8619389..3d7c255 100644 --- a/testdata/extension.rss +++ b/testdata/extension.rss @@ -1,5 +1,5 @@ - + Extensions Test http://test.extensions.net @@ -11,6 +11,13 @@ http://test.extensions.net/test.jpg Extensions Test + The Author + + + test@rss.com + + + Cellular Biomedicine Group, Inc. (0001378624) (Filer) http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/0001354488-13-006749-index.htm