From f21f087025e7790caa3190eef2b45b904a56925e Mon Sep 17 00:00:00 2001 From: Wito Chandra Date: Sun, 1 Apr 2018 21:07:48 +0700 Subject: [PATCH] add cloud support --- lib/domain/rss_cloud.dart | 20 ++++++++++++++++++++ lib/domain/rss_feed.dart | 10 +++++++++- test/rss_test.dart | 6 ++++++ test/xml/RSS.xml | 6 +++++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 lib/domain/rss_cloud.dart diff --git a/lib/domain/rss_cloud.dart b/lib/domain/rss_cloud.dart new file mode 100644 index 0000000..2cd0042 --- /dev/null +++ b/lib/domain/rss_cloud.dart @@ -0,0 +1,20 @@ +import 'package:xml/xml.dart'; + +class RssCloud { + String domain; + String port; + String path; + String registerProcedure; + String protocol; + + RssCloud(this.domain, this.port, this.path, this.registerProcedure, this.protocol); + + factory RssCloud.parse(XmlElement node) { + var domain = node.getAttribute("domain"); + var port = node.getAttribute("port"); + var path = node.getAttribute("path"); + var registerProcedure = node.getAttribute("registerProcedure"); + var protocol = node.getAttribute("protocol"); + return new RssCloud(domain, port, path, registerProcedure, protocol); + } +} \ No newline at end of file diff --git a/lib/domain/rss_feed.dart b/lib/domain/rss_feed.dart index 24f4768..7509a75 100644 --- a/lib/domain/rss_feed.dart +++ b/lib/domain/rss_feed.dart @@ -1,6 +1,7 @@ import 'dart:core'; import 'package:webfeedclient/domain/rss_category.dart'; +import 'package:webfeedclient/domain/rss_cloud.dart'; import 'package:webfeedclient/domain/rss_item.dart'; import 'package:webfeedclient/util/helpers.dart'; import 'package:xml/xml.dart'; @@ -14,6 +15,7 @@ class RssFeed { final List items; final RssImage image; + final RssCloud cloud; final List categories; final String lastBuildDate; final String language; @@ -21,7 +23,7 @@ class RssFeed { final String copyright; RssFeed(this.title, this.description, this.link, this.items, - {this.image, this.categories, this.lastBuildDate, this.language, this.generator, this.copyright}); + {this.image, this.cloud, this.categories, this.lastBuildDate, this.language, this.generator, this.copyright}); factory RssFeed.parse(XmlDocument document) { XmlElement channelElement; @@ -43,6 +45,11 @@ class RssFeed { image = new RssImage.parse(channelElement.findElements("image").first); } on StateError {} + RssCloud cloud; + try { + cloud = new RssCloud.parse(channelElement.findElements("cloud").first); + } on StateError {} + List categories = channelElement.findElements("category").map((element) { return new RssCategory.parse(element); }).toList(); @@ -54,6 +61,7 @@ class RssFeed { return new RssFeed(title, description, link, feeds, image: image, + cloud: cloud, categories: categories, lastBuildDate: lastBuildDate, language: language, diff --git a/test/rss_test.dart b/test/rss_test.dart index 69ebf33..3761e92 100644 --- a/test/rss_test.dart +++ b/test/rss_test.dart @@ -32,6 +32,12 @@ void main() { expect(feed.image.url, "https://foo.bar.news/logo.gif"); expect(feed.image.link, "https://foo.bar.news/"); + expect(feed.cloud.domain, "radio.foo.bar.news"); + expect(feed.cloud.port, "80"); + expect(feed.cloud.path, "/RPC2"); + expect(feed.cloud.registerProcedure, "foo.bar.rssPleaseNotify"); + expect(feed.cloud.protocol, "xml-rpc"); + expect(feed.categories.length, 2); expect(feed.categories[0].domain, null); expect(feed.categories[0].value, "Ipsum"); diff --git a/test/xml/RSS.xml b/test/xml/RSS.xml index f3bff1c..f9d54f2 100644 --- a/test/xml/RSS.xml +++ b/test/xml/RSS.xml @@ -9,6 +9,8 @@ Foo bar News https://foo.bar.news/ + Ipsum Lorem Ipsum en-US @@ -27,7 +29,9 @@ Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC https://foo.bar.news/2 https://foo.bar.news/2?guid - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium + Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque + laudantium + Ipsum Tue, 20 Mar 2018 10:00:00 PDT