The Webfeed Flutter package for Appeto SDK.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

  1. import 'package:webfeed/util/datetime.dart';
  2. import 'package:webfeed/util/xml.dart';
  3. import 'package:xml/xml.dart';
  4. enum SyndicationUpdatePeriod { hourly, daily, weekly, monthly, yearly }
  5. class Syndication {
  6. final SyndicationUpdatePeriod? updatePeriod;
  7. final int? updateFrequency;
  8. final DateTime? updateBase;
  9. Syndication({
  10. this.updatePeriod,
  11. this.updateFrequency,
  12. this.updateBase,
  13. });
  14. static parse(XmlElement? element) {
  15. if (element == null) return null;
  16. SyndicationUpdatePeriod updatePeriod;
  17. switch (findFirstElement(element, 'sy:updatePeriod')?.text) {
  18. case 'hourly':
  19. updatePeriod = SyndicationUpdatePeriod.hourly;
  20. break;
  21. case 'daily':
  22. updatePeriod = SyndicationUpdatePeriod.daily;
  23. break;
  24. case 'weekly':
  25. updatePeriod = SyndicationUpdatePeriod.weekly;
  26. break;
  27. case 'monthly':
  28. updatePeriod = SyndicationUpdatePeriod.monthly;
  29. break;
  30. case 'yearly':
  31. updatePeriod = SyndicationUpdatePeriod.yearly;
  32. break;
  33. default:
  34. updatePeriod = SyndicationUpdatePeriod.daily;
  35. break;
  36. }
  37. return Syndication(
  38. updatePeriod: updatePeriod,
  39. updateFrequency: int.tryParse(
  40. findFirstElement(element, 'sy:updateFrequency')?.text ?? '1'),
  41. updateBase:
  42. parseDateTime(findFirstElement(element, 'sy:updateBase')?.text),
  43. );
  44. }
  45. }