Просмотр исходного кода

remove xml dependency from client

master
Wito Chandra 8 лет назад
Родитель
Сommit
8e1dd85ed6
3 измененных файлов: 5 добавлений и 8 удалений
  1. +1
    -3
      lib/client.dart
  2. +2
    -1
      lib/domain/rss_feed.dart
  3. +2
    -4
      test/rss_test.dart

+ 1
- 3
lib/client.dart Просмотреть файл

@@ -2,7 +2,6 @@ import 'dart:async';


import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:webfeedclient/domain/rss_feed.dart'; import 'package:webfeedclient/domain/rss_feed.dart';
import 'package:xml/xml.dart' as xml;


class WebFeedClient { class WebFeedClient {
http.Client client; http.Client client;
@@ -17,8 +16,7 @@ class WebFeedClient {
print("Response Body: ${response.body}"); print("Response Body: ${response.body}");
return response.body; return response.body;
}).then((bodyString) { }).then((bodyString) {
var document = xml.parse(bodyString);
var channel = new RssFeed.parse(document);
var channel = new RssFeed.parse(bodyString);
return channel; return channel;
}); });
} }


+ 2
- 1
lib/domain/rss_feed.dart Просмотреть файл

@@ -45,7 +45,8 @@ class RssFeed {
this.webMaster, this.webMaster,
this.ttl}); this.ttl});


factory RssFeed.parse(XmlDocument document) {
factory RssFeed.parse(String xmlString) {
XmlDocument document = parse(xmlString);
XmlElement channelElement; XmlElement channelElement;
try { try {
channelElement = document.findAllElements("channel").first; channelElement = document.findAllElements("channel").first;


+ 2
- 4
test/rss_test.dart Просмотреть файл

@@ -7,18 +7,16 @@ import 'package:xml/xml.dart' as xml;
void main() { void main() {
test("parsing Invalid.xml", () { test("parsing Invalid.xml", () {
var xmlString = new File("test/xml/Invalid.xml").readAsStringSync(); var xmlString = new File("test/xml/Invalid.xml").readAsStringSync();
var doc = xml.parse(xmlString);


try { try {
new RssFeed.parse(doc);
new RssFeed.parse(xmlString);
fail("Should throw Argument Error"); fail("Should throw Argument Error");
} on ArgumentError {} } on ArgumentError {}
}); });
test("parsing RSS.xml", () { test("parsing RSS.xml", () {
var xmlString = new File("test/xml/RSS.xml").readAsStringSync(); var xmlString = new File("test/xml/RSS.xml").readAsStringSync();
var doc = xml.parse(xmlString);


var feed = new RssFeed.parse(doc);
var feed = new RssFeed.parse(xmlString);


expect(feed.title, "News - Foo bar News"); expect(feed.title, "News - Foo bar News");
expect(feed.description, "Foo bar News and Updates feed provided by Foo bar, Inc."); expect(feed.description, "Foo bar News and Updates feed provided by Foo bar, Inc.");


Загрузка…
Отмена
Сохранить