Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/domain/atom_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:webfeed/domain/atom_category.dart';
import 'package:webfeed/domain/atom_link.dart';
import 'package:webfeed/domain/atom_person.dart';
import 'package:webfeed/domain/atom_source.dart';
import 'package:webfeed/domain/geo/geo.dart';
import 'package:webfeed/domain/media/media.dart';
import 'package:webfeed/util/datetime.dart';
import 'package:webfeed/util/xml.dart';
Expand All @@ -22,6 +23,7 @@ class AtomItem {
final String summary;
final String rights;
final Media media;
final Geo geo;

AtomItem({
this.id,
Expand All @@ -37,6 +39,7 @@ class AtomItem {
this.summary,
this.rights,
this.media,
this.geo,
});

factory AtomItem.parse(XmlElement element) {
Expand Down Expand Up @@ -64,6 +67,7 @@ class AtomItem {
summary: findFirstElement(element, 'summary')?.text,
rights: findFirstElement(element, 'rights')?.text,
media: Media.parse(element),
geo: Geo.parse(element),
);
}
}
25 changes: 25 additions & 0 deletions lib/domain/geo/geo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart';

class Geo {
final double lat;
final double long;

Geo(this.lat, this.long);

factory Geo.parse(XmlElement element) {
if (element == null) {
return null;
}

var lat = double.tryParse(findFirstElement(element, 'geo:lat')?.text ?? '');
var long =
double.tryParse(findFirstElement(element, 'geo:long')?.text ?? '');

if (lat == null || long == null) {
return null;
} else {
return Geo(lat, long);
}
}
}
4 changes: 4 additions & 0 deletions lib/domain/rss_item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:webfeed/domain/dublin_core/dublin_core.dart';
import 'package:webfeed/domain/geo/geo.dart';
import 'package:webfeed/domain/itunes/itunes.dart';
import 'package:webfeed/domain/media/media.dart';
import 'package:webfeed/domain/rss_category.dart';
Expand All @@ -25,6 +26,7 @@ class RssItem {
final RssEnclosure enclosure;
final DublinCore dc;
final Itunes itunes;
final Geo geo;

RssItem({
this.title,
Expand All @@ -41,6 +43,7 @@ class RssItem {
this.enclosure,
this.dc,
this.itunes,
this.geo,
});

factory RssItem.parse(XmlElement element) {
Expand All @@ -62,6 +65,7 @@ class RssItem {
enclosure: RssEnclosure.parse(findFirstElement(element, 'enclosure')),
dc: DublinCore.parse(element),
itunes: Itunes.parse(element),
geo: Geo.parse(element),
);
}
}
3 changes: 3 additions & 0 deletions test/atom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ void main() {
expect(item.summary, 'This is summary 1');
expect(item.content, 'This is content 1');
expect(item.rights, 'This is rights 1');

expect(item.geo.lat, 45.3);
expect(item.geo.long, -0.5);
});
test('parse Atom-Media.xml', () {
var xmlString = File('test/xml/Atom-Media.xml').readAsStringSync();
Expand Down
3 changes: 3 additions & 0 deletions test/rss_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ void main() {
'<img width="1000" height="690" src="https://test.com/image_link"/> Test content<br />');
expect(
feed.items.first.content.images.first, 'https://test.com/image_link');

expect(feed.items.first.geo.lat, 45.3);
expect(feed.items.first.geo.long, -0.5);
});
test('parse RSS-Media.xml', () {
var xmlString = File('test/xml/RSS-Media.xml').readAsStringSync();
Expand Down
4 changes: 4 additions & 0 deletions test/xml/Atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<summary type="text">This is summary 1</summary>
<content>This is content 1</content>
<rights>This is rights 1</rights>
<geo:lat>45.3</geo:lat>
<geo:long>-0.5</geo:long>
</entry>
<entry>
<id>foo-bar-entry-id-2</id>
Expand Down Expand Up @@ -113,5 +115,7 @@
<summary type="text">This is summary 2</summary>
<content>This is content 2</content>
<rights>This is rights 2</rights>
<geo:lat>43.3</geo:lat>
<geo:long>3.5</geo:long>
</entry>
</feed>
4 changes: 4 additions & 0 deletions test/xml/RSS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<comments>https://foo.bar.news/1/comments</comments>
<content:encoded><![CDATA[<img width="1000" height="690" src="https://test.com/image_link"/> Test content<br />]]></content:encoded>
<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />
<geo:lat>45.3</geo:lat>
<geo:long>-0.5</geo:long>
</item>
<item>
<title>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</title>
Expand All @@ -62,6 +64,8 @@
<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>
<geo:lat>49.4</geo:lat>
<geo:long>9.5</geo:long>
</item>
</channel>
</rss>