Pārlūkot izejas kodu

add author, source & comments into rss_item

master
Wito Chandra pirms 8 gadiem
vecāks
revīzija
f8c79f2ccd
4 mainītis faili ar 52 papildinājumiem un 2 dzēšanām
  1. +19
    -2
      lib/domain/rss_item.dart
  2. +23
    -0
      lib/domain/rss_source.dart
  3. +4
    -0
      test/rss_test.dart
  4. +6
    -0
      test/xml/RSS.xml

+ 19
- 2
lib/domain/rss_item.dart Parādīt failu

@@ -1,4 +1,5 @@
import 'package:webfeedclient/domain/rss_category.dart';
import 'package:webfeedclient/domain/rss_source.dart';
import 'package:webfeedclient/util/helpers.dart';
import 'package:xml/xml.dart';

@@ -10,8 +11,12 @@ class RssItem {
final List<RssCategory> categories;
final String guid;
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) {
var title = xmlGetString(element, "title");
@@ -24,8 +29,16 @@ class RssItem {

var guid = xmlGetString(element, "guid", 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
@@ -34,7 +47,11 @@ class RssItem {
title: $title
description: $description
link: $link
guid: $guid
pubDate: $pubDate
author: $author
comments: $comments
source: $source
''';
}
}

+ 23
- 0
lib/domain/rss_source.dart Parādīt failu

@@ -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
''';
}
}

+ 4
- 0
test/rss_test.dart Parādīt failu

@@ -68,5 +68,9 @@ void main() {
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.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");
});
}

+ 6
- 0
test/xml/RSS.xml Parādīt failu

@@ -41,6 +41,9 @@
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit</description>
<category domain="news">Lorem</category>
<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>
<title>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</title>
@@ -51,6 +54,9 @@
</description>
<category domain="auto">Ipsum</category>
<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>
</channel>
</rss>

Notiek ielāde…
Atcelt
Saglabāt