SyndicationDomination 0.0
An RSS/Atom parser, because there's nothing else out there.
Loading...
Searching...
No Matches
feed_item.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
9using namespace pugi;
10
20class FeedItem {
21private:
22 xml_node item_node;
23 std::string website_url;
24
25 std::string title;
26 std::string content;
27 std::string url;
28 std::string media_url;
29 std::string pub_date;
30 std::string img_url;
31 std::string author_name;
32 std::string author_url;
33
37 std::string extract_url();
38
43 std::string extract_media_url();
44
45 static inline const std::vector<ExtractionParam> __IMG_URL_PARAMS{
46 {ExtractionParam::ParamType::ATTRIBUTE, {"thumbnail"}, "url"},
47 {ExtractionParam::ParamType::ATTRIBUTE, {"media:thumbnail"}, "url"},
48 {ExtractionParam::ParamType::ATTRIBUTE, {"group", "thumbnail"}, "url"},
49 {ExtractionParam::ParamType::ATTRIBUTE, {"media:group", "thumbnail"}, "url"},
50 {ExtractionParam::ParamType::ATTRIBUTE, {"media:group", "media:thumbnail"}, "url"}
51 };
56 std::string extract_img_url();
57
62 void fix_url(std::string &s);
63
64 static inline const std::vector<ExtractionParam> __CONTENT_PARAMS{
66 {ExtractionParam::ParamType::CHILD, {"content:encoded"}},
67 {ExtractionParam::ParamType::CHILD, {"description"}},
69 {ExtractionParam::ParamType::CHILD, {"media:group", "media:description"}}
70 };
71 static inline const std::vector<ExtractionParam> __PUB_DATE_PARAMS{
73 {ExtractionParam::ParamType::CHILD, {"published"}},
77 };
78 static inline const std::vector<ExtractionParam> __AUTHOR_NAME_PARAMS{
79 {ExtractionParam::ParamType::CHILD, {"author", "name"}},
81 {ExtractionParam::ParamType::CHILD, {"dc:creator"}},
83 {ExtractionParam::ParamType::CHILD, {"itunes:author"}},
84 };
85 static inline const std::vector<ExtractionParam> __AUTHOR_URL_PARAMS{
86 {ExtractionParam::ParamType::CHILD, {"author", "uri"}}
87 };
92 void parse();
93
94public:
105 xml_node item_node, std::string website_url
106 ): item_node{item_node}, website_url{website_url} {
107 parse();
108 }
109
110 std::string get_title() { return title; }
111 std::string get_content() { return content; }
112 std::string get_url() { return url; }
113 std::string get_media_url() { return media_url; }
114 std::string get_pub_date() { return pub_date; }
115 std::string get_img_url() { return img_url; }
116 std::string get_author_name() { return author_name; }
117 std::string get_author_url() { return author_url; }
118
122 std::string to_json();
123};
Represents a feed item or article.
Definition feed_item.hpp:20
std::string get_title()
Definition feed_item.hpp:110
std::string get_pub_date()
Definition feed_item.hpp:114
std::string get_author_url()
Definition feed_item.hpp:117
std::string get_url()
Definition feed_item.hpp:112
std::string to_json()
Represents the FeedItem object (itself) as a json, returned as a string.
Definition feed_item.cpp:87
FeedItem(xml_node item_node, std::string website_url)
Constructs the FeedItem object from a pugi::xml_node representing a feed item.
Definition feed_item.hpp:104
std::string get_content()
Definition feed_item.hpp:111
std::string get_author_name()
Definition feed_item.hpp:116
std::string get_img_url()
Definition feed_item.hpp:115
std::string get_media_url()
Definition feed_item.hpp:113
@ ATTRIBUTE
Definition extraction_param.hpp:19
@ CHILD
Definition extraction_param.hpp:18