3 #ifndef WIKIWALKER_WIKIMEDIAAPI_H
4 #define WIKIWALKER_WIKIMEDIAAPI_H
8 #include "ArticleCollection.h"
9 #include "CurlWikiGrabber.h"
13 namespace WikimediaApiUtils
15 //! Represents URL components
16 struct WikimediaUrlInfo
{
18 std::string apiBaseUrl
;
20 std::string articleTitle
;
23 /*! Parses a Wikimedia article URL and returns components.
24 * \param articleUrl the Wikimedia article URL.
25 * \returns a stuct containing base URL and title.
27 WikimediaUrlInfo
parseArticleUrl(const std::string
& articleUrl
);
28 } // namespace WikimediaApiUtils
30 /*! \brief Represents the Wikimedia API.
31 * \details the needed parts.
32 * The API already converts the string/Json data to a
33 * CollectionUtils::ArticleCollection.
39 enum class WikimediaGenerator
{
40 //! Don't use a generator
42 //! use the forwardlinks generator
46 /*! \brief Create a new instance of the WikimediaApi
47 * \param baseUrl the API base URL of the Wikimedia instance, including the
49 * \todo Take "DataFetcher" or whatever to replace default CURL
51 explicit WikimediaApi(std::string baseUrl
);
53 /*! Get the forward links from a specified title and store it in the
56 * \param title the title of the WikimediaArticle.
57 * \param generator which generator to use to also fetch links in
58 * articles linked from the specified artitle. ONLY this generator is used.
59 * If you specify ForwardLinks, only the ForwardLinks generator is used. You
60 * won't get the links of the article itself. Use NoGenerator for that.
61 * \param[out] collection the collection to store into. If article already
62 * exists in collection, it will be skipped (TODO: REALLY?).
64 void fetchForwardLinks(const std::string
& title
,
65 WikimediaGenerator generator
,
66 CollectionUtils::ArticleCollection
& collection
);
68 /*! Get the backward links from a specified title and store it in the
71 * \param title the title of the WikimediaArticle.
72 * \param generator which generator to use to also fetch links in
73 * articles linked from the specified artitle.
74 * \param[out] collection the collection to store into. If article already
75 * exists in collection, it will be skipped (TODO: REALLY?).
77 void fetchBackwardLinks(const std::string
& title
,
78 WikimediaGenerator generator
,
79 CollectionUtils::ArticleCollection
& collection
);
83 CurlWikiGrabber grabber_
;
85 } // namespace WikiWalker
87 #endif // WIKIWALKER_WIKIMEDIAAPI_H