Skip to content

Commit

Permalink
Re-formatted all code, added a few more lint rules. (Resolves #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll committed Jan 13, 2024
1 parent 71ec7e2 commit aabcea8
Show file tree
Hide file tree
Showing 66 changed files with 1,058 additions and 1,066 deletions.
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
include: package:lints/recommended.yaml

linter:
rules:
- always_use_package_imports
- avoid_print
- curly_braces_in_flow_control_structures
6 changes: 1 addition & 5 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ void main() {
final client = http.Client();

// RSS feed
client
.get(Uri.parse('https://developer.apple.com/news/releases/rss/releases.rss'))
.then((response) {
client.get(Uri.parse('https://developer.apple.com/news/releases/rss/releases.rss')).then((response) {
return response.body;
}).then((bodyString) {
final channel = RssFeed.parse(bodyString);
print(channel);
return channel;
});

Expand All @@ -20,7 +17,6 @@ void main() {
return response.body;
}).then((bodyString) {
final feed = AtomFeed.parse(bodyString);
print(feed);
return feed;
});
}
12 changes: 6 additions & 6 deletions lib/domain/atom_category.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:xml/xml.dart';

class AtomCategory {
final String? term;
final String? scheme;
final String? label;

const AtomCategory(this.term, this.scheme, this.label);

factory AtomCategory.parse(XmlElement element) {
final term = element.getAttribute('term');
final scheme = element.getAttribute('scheme');
final label = element.getAttribute('label');
return AtomCategory(term, scheme, label);
}

const AtomCategory(this.term, this.scheme, this.label);

final String? term;
final String? scheme;
final String? label;
}
90 changes: 37 additions & 53 deletions lib/domain/atom_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ import 'package:dart_rss/util/helpers.dart';
import 'package:xml/xml.dart';

class AtomFeed {
final String? id;
final String? title;
final String? updated;
final List<AtomItem> items;

final List<AtomLink> links;
final List<AtomPerson> authors;
final List<AtomPerson> contributors;
final List<AtomCategory> categories;
final AtomGenerator? generator;
final String? icon;
final String? logo;
final String? rights;
final String? subtitle;

const AtomFeed({
this.id,
this.title,
this.updated,
this.items = const <AtomItem>[],
this.links = const <AtomLink>[],
this.authors = const <AtomPerson>[],
this.contributors = const <AtomPerson>[],
this.categories = const <AtomCategory>[],
this.generator,
this.icon,
this.logo,
this.rights,
this.subtitle,
});

factory AtomFeed.parse(String xmlString) {
final document = XmlDocument.parse(xmlString);
XmlElement feedElement;
Expand All @@ -51,32 +20,47 @@ class AtomFeed {
id: findElementOrNull(feedElement, 'id')?.innerText,
title: findElementOrNull(feedElement, 'title')?.innerText,
updated: findElementOrNull(feedElement, 'updated')?.innerText,
items: feedElement
.findElements('entry')
.map((element) => AtomItem.parse(element))
.toList(),
links: feedElement
.findElements('link')
.map((element) => AtomLink.parse(element))
.toList(),
authors: feedElement
.findElements('author')
.map((element) => AtomPerson.parse(element))
.toList(),
contributors: feedElement
.findElements('contributor')
.map((element) => AtomPerson.parse(element))
.toList(),
categories: feedElement
.findElements('category')
.map((element) => AtomCategory.parse(element))
.toList(),
generator:
AtomGenerator.parse(findElementOrNull(feedElement, 'generator')),
items: feedElement.findElements('entry').map((element) => AtomItem.parse(element)).toList(),
links: feedElement.findElements('link').map((element) => AtomLink.parse(element)).toList(),
authors: feedElement.findElements('author').map((element) => AtomPerson.parse(element)).toList(),
contributors: feedElement.findElements('contributor').map((element) => AtomPerson.parse(element)).toList(),
categories: feedElement.findElements('category').map((element) => AtomCategory.parse(element)).toList(),
generator: AtomGenerator.parse(findElementOrNull(feedElement, 'generator')),
icon: findElementOrNull(feedElement, 'icon')?.innerText,
logo: findElementOrNull(feedElement, 'logo')?.innerText,
rights: findElementOrNull(feedElement, 'rights')?.innerText,
subtitle: findElementOrNull(feedElement, 'subtitle')?.innerText,
);
}

const AtomFeed({
this.id,
this.title,
this.updated,
this.items = const <AtomItem>[],
this.links = const <AtomLink>[],
this.authors = const <AtomPerson>[],
this.contributors = const <AtomPerson>[],
this.categories = const <AtomCategory>[],
this.generator,
this.icon,
this.logo,
this.rights,
this.subtitle,
});

final String? id;
final String? title;
final String? updated;
final List<AtomItem> items;

final List<AtomLink> links;
final List<AtomPerson> authors;
final List<AtomPerson> contributors;
final List<AtomCategory> categories;
final AtomGenerator? generator;
final String? icon;
final String? logo;
final String? rights;
final String? subtitle;
}
13 changes: 7 additions & 6 deletions lib/domain/atom_generator.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import 'package:xml/xml.dart';

class AtomGenerator {
final String? uri;
final String? version;
final String? value;

const AtomGenerator(this.uri, this.version, this.value);

static AtomGenerator? parse(XmlElement? element) {
if (element == null) {
return null;
}

final uri = element.getAttribute('uri');
final version = element.getAttribute('version');
final value = element.innerText;
return AtomGenerator(uri, version, value);
}

const AtomGenerator(this.uri, this.version, this.value);

final String? uri;
final String? version;
final String? value;
}
74 changes: 31 additions & 43 deletions lib/domain/atom_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import 'package:dart_rss/util/helpers.dart';
import 'package:xml/xml.dart';

class AtomItem {
final String? id;
final String? title;
final String? updated;

final List<AtomPerson> authors;
final List<AtomLink> links;
final List<AtomCategory> categories;
final List<AtomPerson> contributors;
final AtomSource? source;
final String? published;
final String? content;
final String? summary;
final String? rights;
final Media? media;
factory AtomItem.parse(XmlElement element) {
return AtomItem(
id: findElementOrNull(element, 'id')?.innerText,
title: findElementOrNull(element, 'title')?.innerText,
updated: findElementOrNull(element, 'updated')?.innerText,
authors: element.findElements('author').map((element) => AtomPerson.parse(element)).toList(),
links: element.findElements('link').map((element) => AtomLink.parse(element)).toList(),
categories: element.findElements('category').map((element) => AtomCategory.parse(element)).toList(),
contributors: element.findElements('contributor').map((element) => AtomPerson.parse(element)).toList(),
source: AtomSource.parse(findElementOrNull(element, 'source')),
published: findElementOrNull(element, 'published')?.innerText,
content: findElementOrNull(element, 'content')?.innerText,
summary: findElementOrNull(element, 'summary')?.innerText,
rights: findElementOrNull(element, 'rights')?.innerText,
media: Media.parse(element),
);
}

const AtomItem({
this.id,
Expand All @@ -38,33 +41,18 @@ class AtomItem {
this.media,
});

factory AtomItem.parse(XmlElement element) {
return AtomItem(
id: findElementOrNull(element, 'id')?.innerText,
title: findElementOrNull(element, 'title')?.innerText,
updated: findElementOrNull(element, 'updated')?.innerText,
authors: element
.findElements('author')
.map((element) => AtomPerson.parse(element))
.toList(),
links: element
.findElements('link')
.map((element) => AtomLink.parse(element))
.toList(),
categories: element
.findElements('category')
.map((element) => AtomCategory.parse(element))
.toList(),
contributors: element
.findElements('contributor')
.map((element) => AtomPerson.parse(element))
.toList(),
source: AtomSource.parse(findElementOrNull(element, 'source')),
published: findElementOrNull(element, 'published')?.innerText,
content: findElementOrNull(element, 'content')?.innerText,
summary: findElementOrNull(element, 'summary')?.innerText,
rights: findElementOrNull(element, 'rights')?.innerText,
media: Media.parse(element),
);
}
final String? id;
final String? title;
final String? updated;

final List<AtomPerson> authors;
final List<AtomLink> links;
final List<AtomCategory> categories;
final List<AtomPerson> contributors;
final AtomSource? source;
final String? published;
final String? content;
final String? summary;
final String? rights;
final Media? media;
}
33 changes: 17 additions & 16 deletions lib/domain/atom_link.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import 'package:xml/xml.dart';

class AtomLink {
final String? href;
final String? rel;
final String? type;
final String? hreflang;
final String? title;
final int length;

const AtomLink(
this.href,
this.rel,
this.type,
this.hreflang,
this.title,
this.length,
);

factory AtomLink.parse(XmlElement element) {
final href = element.getAttribute('href');
final rel = element.getAttribute('rel');
Expand All @@ -28,6 +12,23 @@ class AtomLink {
if (lengthElement != null) {
length = int.tryParse(lengthElement) ?? 0;
}

return AtomLink(href, rel, type, hreflang, title, length);
}

const AtomLink(
this.href,
this.rel,
this.type,
this.hreflang,
this.title,
this.length,
);

final String? href;
final String? rel;
final String? type;
final String? hreflang;
final String? title;
final int length;
}
12 changes: 6 additions & 6 deletions lib/domain/atom_person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import 'package:dart_rss/util/helpers.dart';
import 'package:xml/xml.dart';

class AtomPerson {
final String? name;
final String? uri;
final String? email;

const AtomPerson(this.name, this.uri, this.email);

factory AtomPerson.parse(XmlElement element) {
final name = findElementOrNull(element, 'name')?.innerText;
final uri = findElementOrNull(element, 'uri')?.innerText;
final email = findElementOrNull(element, 'email')?.innerText;
return AtomPerson(name, uri, email);
}

const AtomPerson(this.name, this.uri, this.email);

final String? name;
final String? uri;
final String? email;
}
14 changes: 8 additions & 6 deletions lib/domain/atom_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import 'package:dart_rss/util/helpers.dart';
import 'package:xml/xml.dart';

class AtomSource {
final String? id;
final String? title;
final String? updated;

const AtomSource(this.id, this.title, this.updated);

static AtomSource? parse(XmlElement? element) {
if (element == null) {
return null;
}

final id = findElementOrNull(element, 'id')?.innerText;
final title = findElementOrNull(element, 'title')?.innerText;
final updated = findElementOrNull(element, 'updated')?.innerText;

return AtomSource(id, title, updated);
}

const AtomSource(this.id, this.title, this.updated);

final String? id;
final String? title;
final String? updated;
}
Loading

0 comments on commit aabcea8

Please sign in to comment.