Add conversion for backwards links
[dueringa_WikiWalker.git] / inc / CurlUrlCreator.h
blob09c10c7bef2795d7cc5a2d36e995a543806c1825
1 //! \file CurlUrlCreator.h
3 #ifndef WIKIWALKER_CURLURLCREATOR_H
4 #define WIKIWALKER_CURLURLCREATOR_H
6 #include <map>
7 #include <string>
8 #include <unordered_map>
10 #include <curl/curl.h>
12 namespace WikiWalker
14 /*! Creates GET URLs with parameters.
15 * With the help of curl
17 class CurlUrlCreator
19 public:
20 /*! Create a new instance, given a base URL
21 * \param baseUrl Base URL that will be used for adding parameters
23 explicit CurlUrlCreator(std::string baseUrl);
25 //! delete copy constructor, because of CURL handle
26 CurlUrlCreator(const CurlUrlCreator&) = delete;
28 //! default move constructor
29 CurlUrlCreator(CurlUrlCreator&&) = default;
31 //! delete copy assignment, because of CURL handle
32 CurlUrlCreator& operator=(const CurlUrlCreator&) = delete;
34 //! default move assignment
35 CurlUrlCreator& operator=(CurlUrlCreator&&) = default;
37 /*! Add GET parameters to URL.
38 * If parameter keys are specified multiple times, later occurrences
39 * overwrite earlier ones.
40 * \param param the parameter name
41 * \param value the parameter value - UNESCAPED!
42 * This will be done by curl. If you already escape
43 * it will be double-escaped.
44 * \return reference to self, so method chaining is possible.
46 CurlUrlCreator& addParameter(const std::string& param,
47 const std::string& value);
49 /*! Add GET parameters to URL.
50 * \param params a map of keys and values.
51 * values have to be UNESCAPED!
52 * This will be done by curl. If you already escape
53 * it will be double-escaped.
54 * \return reference to self, so method chaining is possible.
56 CurlUrlCreator& addParameter(
57 const std::map<const std::string, const std::string>& params);
59 //! Reset parameters
60 void reset();
62 /*! Creates the URL
63 * \return Complete GET URL.
65 std::string buildUrl() const;
67 ~CurlUrlCreator();
69 private:
70 std::string baseUrl_;
71 std::unordered_map<std::string, std::string> args_;
72 CURL* handle_;
74 } // namespace WikiWalker
75 #endif // WIKIWALKER_CURLURLCREATOR_H