added Extension to channel
This commit is contained in:
		
							parent
							
								
									bd84124886
								
							
						
					
					
						commit
						937de70c03
					
				
					 4 changed files with 48 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -21,6 +21,7 @@ type Channel struct {
 | 
			
		|||
	Items          []*Item
 | 
			
		||||
	Cloud          Cloud
 | 
			
		||||
	TextInput      Input
 | 
			
		||||
	Extensions     map[string]map[string][]Extension
 | 
			
		||||
 | 
			
		||||
	// Atom fields
 | 
			
		||||
	Id       string
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								feed_test.go
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								rss.go
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								testdata/extension.rss
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								testdata/extension.rss
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<rss version="2.0">
 | 
			
		||||
<rss version="2.0"  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
 | 
			
		||||
  <channel>
 | 
			
		||||
    <title>Extensions Test</title>
 | 
			
		||||
    <link>http://test.extensions.net</link>
 | 
			
		||||
| 
						 | 
				
			
			@ -11,6 +11,13 @@
 | 
			
		|||
      <url>http://test.extensions.net/test.jpg</url>
 | 
			
		||||
      <title>Extensions Test</title>
 | 
			
		||||
    </image>
 | 
			
		||||
    <itunes:author>The Author</itunes:author>
 | 
			
		||||
    <itunes:owner>
 | 
			
		||||
      <itunes:name></itunes:name>
 | 
			
		||||
      <itunes:email>test@rss.com</itunes:email>
 | 
			
		||||
    </itunes:owner>
 | 
			
		||||
    <itunes:category text="Politics"></itunes:category>
 | 
			
		||||
    <itunes:image href="http://golang.org/doc/gopher/project.png" />
 | 
			
		||||
    <item>
 | 
			
		||||
      <title>Cellular Biomedicine Group, Inc. (0001378624) (Filer)</title>
 | 
			
		||||
      <link>http://www.sec.gov/Archives/edgar/data/1378624/000135448813006749/0001354488-13-006749-index.htm</link>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue