diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/connection.hpp | 2 | ||||
-rw-r--r-- | include/curl_wrapper.hpp | 40 | ||||
-rw-r--r-- | include/instance.hpp | 2 | ||||
-rw-r--r-- | include/mastodonpp.hpp | 2 | ||||
-rw-r--r-- | include/types.hpp (renamed from include/answer.hpp) | 85 |
5 files changed, 86 insertions, 45 deletions
diff --git a/include/connection.hpp b/include/connection.hpp index 27119e4..bf37219 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -17,10 +17,10 @@ #ifndef MASTODONPP_CONNECTION_HPP #define MASTODONPP_CONNECTION_HPP -#include "answer.hpp" #include "api.hpp" #include "curl_wrapper.hpp" #include "instance.hpp" +#include "types.hpp" #include <string> #include <string_view> diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp index 30fa1ce..890b36e 100644 --- a/include/curl_wrapper.hpp +++ b/include/curl_wrapper.hpp @@ -17,28 +17,20 @@ #ifndef MASTODONPP_CURL_WRAPPER_HPP #define MASTODONPP_CURL_WRAPPER_HPP -#include "answer.hpp" +#include "types.hpp" #include "curl/curl.h" -#include <map> #include <mutex> #include <string> #include <string_view> -#include <utility> -#include <variant> -#include <vector> namespace mastodonpp { -using std::map; using std::mutex; using std::string; using std::string_view; -using std::pair; -using std::variant; -using std::vector; /*! * @brief The HTTP method. @@ -55,36 +47,6 @@ enum class http_method }; /*! - * @brief `std::map` of parameters for %API calls. - * - * Note that arrays always have to be specified as vectors, even if they have - * only 1 element. To send a file, use “<tt>\@file:</tt>” followed by the file - * name as value. - * - * Example: - * @code - * parametermap parameters - * { - * {"poll[expires_in]", "86400"}, - * {"poll[options]", vector<string_view>{"Yes", "No", "Maybe"}}, - * {"status", "How is the weather?"} - * }; - * @endcode - * - * @since 0.1.0 - */ -using parametermap = - map<string_view, variant<string_view, vector<string_view>>>; - -/*! - * @brief A single parameter of a parametermap. - * - * @since 0.1.0 - */ -using parameterpair = - pair<string_view, variant<string_view, vector<string_view>>>; - -/*! * @brief Handles the details of network connections. * * You don't need to use this. diff --git a/include/instance.hpp b/include/instance.hpp index df62646..a7feb78 100644 --- a/include/instance.hpp +++ b/include/instance.hpp @@ -18,7 +18,7 @@ #define MASTODONPP_INSTANCE_HPP #include "curl_wrapper.hpp" -#include "answer.hpp" +#include "types.hpp" #include <cstdint> #include <string> diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp index ca396d7..65c1af7 100644 --- a/include/mastodonpp.hpp +++ b/include/mastodonpp.hpp @@ -17,11 +17,11 @@ #ifndef MASTODONPP_HPP #define MASTODONPP_HPP -#include "answer.hpp" #include "api.hpp" #include "connection.hpp" #include "exceptions.hpp" #include "instance.hpp" +#include "types.hpp" /*! * @headerfile mastodonpp.hpp mastodonpp/mastodonpp.hpp diff --git a/include/answer.hpp b/include/types.hpp index b820a70..bfd5e42 100644 --- a/include/answer.hpp +++ b/include/types.hpp @@ -14,22 +14,62 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MASTODONPP_ANSWER_HPP -#define MASTODONPP_ANSWER_HPP +// Types that are used in more than one file. + +#ifndef MASTODONPP_TYPES_HPP +#define MASTODONPP_TYPES_HPP #include <cstdint> +#include <map> #include <ostream> #include <string> #include <string_view> +#include <utility> +#include <variant> +#include <vector> namespace mastodonpp { using std::uint8_t; using std::uint16_t; +using std::map; using std::ostream; using std::string; using std::string_view; +using std::pair; +using std::variant; +using std::vector; + +/*! + * @brief `std::map` of parameters for %API calls. + * + * Note that arrays always have to be specified as vectors, even if they have + * only 1 element. To send a file, use “<tt>\@file:</tt>” followed by the file + * name as value. + * + * Example: + * @code + * parametermap parameters + * { + * {"poll[expires_in]", "86400"}, + * {"poll[options]", vector<string_view>{"Yes", "No", "Maybe"}}, + * {"status", "How is the weather?"} + * }; + * @endcode + * + * @since 0.1.0 + */ +using parametermap = + map<string_view, variant<string_view, vector<string_view>>>; + +/*! + * @brief A single parameter of a parametermap. + * + * @since 0.1.0 + */ +using parameterpair = + pair<string_view, variant<string_view, vector<string_view>>>; /*! * @brief Return type for Request%s. @@ -110,9 +150,48 @@ struct answer_type * * @since 0.1.0 */ + [[nodiscard]] string_view get_header(string_view field) const; + + /*! + * @brief Returns the parameters needed for the next entries. + * + * Parses the `Link` header. + * + * @since 0.3.0 + */ + [[nodiscard]] + inline parametermap next() const + { + return parse_pagination(true); + } + + /*! + * @brief Returns the parameters needed for the previous entries. + * + * + * Parses the `Link` header. + * + * @since 0.3.0 + */ + [[nodiscard]] + inline parametermap prev() const + { + return parse_pagination(false); + } + +private: + /*! + * @brief Returns the parameters needed for the next or previous entries. + * + * + * Parses the `Link` header. + * + * @since 0.3.0 + */ + parametermap parse_pagination(bool next) const; }; } // namespace mastodonpp -#endif // MASTODONPP_ANSWER_HPP +#endif // MASTODONPP_TYPES_HPP |