Fix - allow port be specified in URL
[dueringa_WikiWalker.git] / inc / WikimediaApi.h
blob88316475552053bd45633e265000c55f06f7b6f5
1 //! \file
3 #ifndef WIKIWALKER_WIKIMEDIAAPI_H
4 #define WIKIWALKER_WIKIMEDIAAPI_H
6 #include <string>
8 #include "ArticleCollection.h"
9 #include "CurlWikiGrabber.h"
11 namespace WikiWalker
13 namespace WikimediaApiUtils
15 //! Represents URL components
16 struct WikimediaUrlInfo {
17 //! the API base URL
18 std::string apiBaseUrl;
19 //! the article title
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.
35 class WikimediaApi
37 public:
38 //! Usable generators
39 enum class WikimediaGenerator {
40 //! Don't use a generator
41 NoGenerator,
42 //! use the forwardlinks generator
43 ForwardLinkGenerator
46 /*! \brief Create a new instance of the WikimediaApi
47 * \param baseUrl the API base URL of the Wikimedia instance, including the
48 * protocol.
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
54 * collection.
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
69 * collection.
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);
81 private:
82 std::string baseUrl_;
83 CurlWikiGrabber grabber_;
85 } // namespace WikiWalker
87 #endif // WIKIWALKER_WIKIMEDIAAPI_H