SyndicationDomination 0.0
An RSS/Atom parser, because there's nothing else out there.
Loading...
Searching...
No Matches
feed.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pugixml.hpp>
4#include <string>
5#include <vector>
6
7#include "utils.hpp"
8#include "feed_type.hpp"
9#include "feed_item.hpp"
10#include "extraction_param.hpp"
11
12using namespace pugi;
13
22class Feed {
23private:
24
25 std::string path;
26 xml_document doc;
27 xml_node feed_node;
28
30
31 std::string title;
32 std::string description;
33 std::string url;
34 std::string last_update;
35 std::string img_url;
36 std::string rss_url;
37
38 std::vector<FeedItem> feed_items{};
39
44 bool verify_feed();
45
50 xml_node get_feed_node();
51
56 void fix_url(std::string &s);
57
61 std::string extract_url();
62
63 static inline const std::vector<ExtractionParam> __LAST_UPDATE_PARAMS{
65 {ExtractionParam::ParamType::CHILD, {"lastBuildDate"}},
68 };
73 std::string extract_last_update();
74
75 static inline const std::vector<ExtractionParam> __IMG_URL_PARAMS{
77 {ExtractionParam::ParamType::CHILD, {"image", "url"}},
80 {ExtractionParam::ParamType::ATTRIBUTE, {"itunes:image"}, "href"}
81 };
86 std::string extract_img_url();
87
92 std::string extract_rss_url();
93
94 static inline const std::vector<ExtractionParam> __DESCRIPTION_PARAMS{
95 {ExtractionParam::ParamType::CHILD, {"description"}},
97 };
102 void extract_feed_data();
103
108 void extract_feed_items();
109
114 void parse();
115
116public:
117
125 Feed(std::string path) : path{path} {
126 parse();
127 }
128
129 std::string get_title() { return title; }
130 std::string get_description() { return description; }
131 std::string get_url() { return url; }
132 std::string get_last_update() { return last_update; }
133 std::string get_img_url() { return img_url; }
134 std::string get_rss_url() { return rss_url; }
135
136 std::vector<FeedItem> get_items() { return feed_items; }
137
141 std::string to_json(bool no_items=false);
142};
Represents an RSS/Atom feed.
Definition feed.hpp:22
std::string get_last_update()
Definition feed.hpp:132
std::string get_url()
Definition feed.hpp:131
Feed(std::string path)
Constructs the Feed object from a valid RSS/Atom file path.
Definition feed.hpp:125
std::vector< FeedItem > get_items()
Definition feed.hpp:136
std::string get_img_url()
Definition feed.hpp:133
std::string to_json(bool no_items=false)
Represents the Feed object (itself) as a json, returned as a string.
Definition feed.cpp:146
std::string get_title()
Definition feed.hpp:129
std::string get_rss_url()
Definition feed.hpp:134
std::string get_description()
Definition feed.hpp:130
FeedType
Definition feed_type.hpp:3
@ INVALID
Definition feed_type.hpp:4
@ ATTRIBUTE
Definition extraction_param.hpp:19
@ CHILD
Definition extraction_param.hpp:18