| @@ -1,4 +1,5 @@ | |||||
| import 'package:webfeedclient/domain/rss_category.dart'; | import 'package:webfeedclient/domain/rss_category.dart'; | ||||
| import 'package:webfeedclient/domain/rss_source.dart'; | |||||
| import 'package:webfeedclient/util/helpers.dart'; | import 'package:webfeedclient/util/helpers.dart'; | ||||
| import 'package:xml/xml.dart'; | import 'package:xml/xml.dart'; | ||||
| @@ -10,8 +11,12 @@ class RssItem { | |||||
| final List<RssCategory> categories; | final List<RssCategory> categories; | ||||
| final String guid; | final String guid; | ||||
| final String pubDate; | final String pubDate; | ||||
| final String author; | |||||
| final String comments; | |||||
| final RssSource source; | |||||
| RssItem(this.title, this.description, this.link, {this.categories, this.guid, this.pubDate}); | |||||
| RssItem(this.title, this.description, this.link, | |||||
| {this.categories, this.guid, this.pubDate, this.author, this.comments, this.source}); | |||||
| factory RssItem.parse(XmlElement element) { | factory RssItem.parse(XmlElement element) { | ||||
| var title = xmlGetString(element, "title"); | var title = xmlGetString(element, "title"); | ||||
| @@ -24,8 +29,16 @@ class RssItem { | |||||
| var guid = xmlGetString(element, "guid", strict: false); | var guid = xmlGetString(element, "guid", strict: false); | ||||
| var pubDate = xmlGetString(element, "pubDate", strict: false); | var pubDate = xmlGetString(element, "pubDate", strict: false); | ||||
| var author = xmlGetString(element, "author", strict: false); | |||||
| var comments = xmlGetString(element, "comments", strict: false); | |||||
| return new RssItem(title, description, link, categories: categories, guid: guid, pubDate: pubDate); | |||||
| RssSource source; | |||||
| try { | |||||
| source = new RssSource.parse(element.findElements("source").first); | |||||
| } on StateError {} | |||||
| return new RssItem(title, description, link, | |||||
| categories: categories, guid: guid, pubDate: pubDate, author: author, comments: comments, source: source); | |||||
| } | } | ||||
| @override | @override | ||||
| @@ -34,7 +47,11 @@ class RssItem { | |||||
| title: $title | title: $title | ||||
| description: $description | description: $description | ||||
| link: $link | link: $link | ||||
| guid: $guid | |||||
| pubDate: $pubDate | pubDate: $pubDate | ||||
| author: $author | |||||
| comments: $comments | |||||
| source: $source | |||||
| '''; | '''; | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,23 @@ | |||||
| import 'package:xml/xml/nodes/element.dart'; | |||||
| class RssSource { | |||||
| String url; | |||||
| String value; | |||||
| RssSource(this.url, this.value); | |||||
| factory RssSource.parse(XmlElement node) { | |||||
| var url = node.getAttribute("url"); | |||||
| var value = node.text; | |||||
| return new RssSource(url, value); | |||||
| } | |||||
| @override | |||||
| String toString() { | |||||
| return ''' | |||||
| url: $url | |||||
| value: $value | |||||
| '''; | |||||
| } | |||||
| } | |||||
| @@ -68,5 +68,9 @@ void main() { | |||||
| expect(feed.items.first.pubDate, "Mon, 26 Mar 2018 14:00:00 PDT"); | expect(feed.items.first.pubDate, "Mon, 26 Mar 2018 14:00:00 PDT"); | ||||
| expect(feed.items.first.categories.first.domain, "news"); | expect(feed.items.first.categories.first.domain, "news"); | ||||
| expect(feed.items.first.categories.first.value, "Lorem"); | expect(feed.items.first.categories.first.value, "Lorem"); | ||||
| expect(feed.items.first.author, "alice@foo.bar.news"); | |||||
| expect(feed.items.first.source.url, "https://foo.bar.news/1?source"); | |||||
| expect(feed.items.first.source.value, "Foo Bar"); | |||||
| expect(feed.items.first.comments, "https://foo.bar.news/1/comments"); | |||||
| }); | }); | ||||
| } | } | ||||
| @@ -41,6 +41,9 @@ | |||||
| <description>Lorem ipsum dolor sit amet, consectetur adipiscing elit</description> | <description>Lorem ipsum dolor sit amet, consectetur adipiscing elit</description> | ||||
| <category domain="news">Lorem</category> | <category domain="news">Lorem</category> | ||||
| <pubDate>Mon, 26 Mar 2018 14:00:00 PDT</pubDate> | <pubDate>Mon, 26 Mar 2018 14:00:00 PDT</pubDate> | ||||
| <author>alice@foo.bar.news</author> | |||||
| <source url="https://foo.bar.news/1?source">Foo Bar</source> | |||||
| <comments>https://foo.bar.news/1/comments</comments> | |||||
| </item> | </item> | ||||
| <item> | <item> | ||||
| <title>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</title> | <title>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</title> | ||||
| @@ -51,6 +54,9 @@ | |||||
| </description> | </description> | ||||
| <category domain="auto">Ipsum</category> | <category domain="auto">Ipsum</category> | ||||
| <pubDate>Tue, 20 Mar 2018 10:00:00 PDT</pubDate> | <pubDate>Tue, 20 Mar 2018 10:00:00 PDT</pubDate> | ||||
| <author>bob@foo.bar.news</author> | |||||
| <source url="https://foo.bar.news/2?source">Lorem Ipsum</source> | |||||
| <comments>https://foo.bar.news/2/comments</comments> | |||||
| </item> | </item> | ||||
| </channel> | </channel> | ||||
| </rss> | </rss> | ||||