Add conversion for backwards links
[dueringa_WikiWalker.git] / inc / WikimediaJsonToArticleConverter.h
blobe52d40e6a0a05daa6fbf8737fa4a91141afed728
1 //! \file WikimediaJsonToArticleConverter.h
3 #ifndef WIKIWALKER_WIKIMEDIAJSONTOARTICLECONVERTER_H
4 #define WIKIWALKER_WIKIMEDIAJSONTOARTICLECONVERTER_H
6 #include "ArticleCollection.h"
8 #include <memory>
9 #include <string>
11 namespace WikiWalker
13 /*! converts a JSON reply from the Wikimedia query links request.
14 * This class only supports JSON format 2! JSON format 1 is not supported
15 * anymore.
17 class WikimediaJsonToArticleConverter
19 public:
20 //! Represents the state of the json to article conversion
21 enum class ContinuationStatus {
22 //! the conversion is completed
23 ConversionCompleted,
24 //! the conversion indicated more data is needed
25 ConversionNeedsMoreData
28 //! Type used for continuation data
29 using continuationData_type =
30 std::map<const std::string, const std::string>;
32 //! create a new instance
33 WikimediaJsonToArticleConverter() = default;
35 /*! convert JSON data to Article.
36 * convert a string containing json data containing the reply of a Wikimedia
37 * query links request in JSON format 2 to an article with links and puts it
38 * in an ArticleCollection.
39 * \param json json data
40 * \param articleCache reference to an article collection that gets filled
41 * \returns the conversion status. If this is
42 * #ContinuationStatus::ConversionNeedsMoreData, get continuation data with
43 * #continuationData.
45 ContinuationStatus convert(
46 const std::string& json,
47 CollectionUtils::ArticleCollection& articleCache);
49 /*! Get the continuation data, if
50 * #ContinuationStat::ConversionNeedsMoreData was returned by
51 * #convert.
52 * \return continuation string
54 continuationData_type continuationData() const
56 return continuationData_;
59 private:
60 //! string required for API operation
61 continuationData_type continuationData_;
63 } // namespace WikiWalker
64 #endif // WIKIWALKER_WIKIMEDIAJSONTOARTICLECONVERTER_H