From cbb1e18b0c8d4493e9e3bee30a7c0b07fc5c35fd Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 22 Feb 2019 12:33:03 +0100 Subject: [PATCH] Replaced return types for get_stream, patch, post, put, del --- src/api/delete.cpp | 19 ++-- src/api/get.cpp | 2 +- src/api/get_stream.cpp | 27 +++--- src/api/patch.cpp | 13 ++- src/api/post.cpp | 24 +++--- src/api/put.cpp | 20 ++--- src/easy/easy.hpp | 4 +- src/http.cpp | 2 +- src/mastodon-cpp.cpp | 4 +- src/mastodon-cpp.hpp | 192 ++++++++++++++++------------------------- 10 files changed, 126 insertions(+), 181 deletions(-) diff --git a/src/api/delete.cpp b/src/api/delete.cpp index 8ce7382..eff70e2 100644 --- a/src/api/delete.cpp +++ b/src/api/delete.cpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. * Copyright © 2018 tastytea - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. @@ -20,8 +20,8 @@ using namespace Mastodon; -uint16_t API::del(const Mastodon::API::v1 &call, - const parametermap ¶meters) +return_call API::del(const Mastodon::API::v1 &call, + const parametermap ¶meters) { string strcall = ""; string strid = ""; @@ -51,19 +51,16 @@ uint16_t API::del(const Mastodon::API::v1 &call, strcall = "/api/v1/push/subscription"; break; default: - ttdebug << "ERROR: Invalid call.\n"; - return 11; + ttdebug << "ERROR: Invalid argument.\n"; + return { 22, "Invalid argument", 0, "" }; break; } - string answer; - return del(strcall, parameters, answer); + return del(strcall, parameters); } -uint16_t API::del(const std::string &call, - const parametermap ¶meters, string &answer) +return_call API::del(const std::string &call, const parametermap ¶meters) { - return _http.request(http::method::DELETE, call, - maptoformdata(parameters), answer); + return _http.request(http::method::DELETE, call, maptoformdata(parameters)); } diff --git a/src/api/get.cpp b/src/api/get.cpp index e81f2f1..4486f37 100644 --- a/src/api/get.cpp +++ b/src/api/get.cpp @@ -1,5 +1,5 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/api/get_stream.cpp b/src/api/get_stream.cpp index 9f150bb..a709af6 100644 --- a/src/api/get_stream.cpp +++ b/src/api/get_stream.cpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. @@ -21,10 +21,9 @@ using namespace Mastodon; using std::cerr; -uint16_t API::get_stream(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer, - std::unique_ptr &ptr) +return_call API::get_stream(const Mastodon::API::v1 &call, + const parametermap ¶meters, + std::unique_ptr &ptr) { string strcall = ""; @@ -47,7 +46,7 @@ uint16_t API::get_stream(const Mastodon::API::v1 &call, break; default: ttdebug << "ERROR: Invalid call.\n"; - return 11; + return { 22, "Invalid argument", 0, "" }; break; } @@ -56,20 +55,18 @@ uint16_t API::get_stream(const Mastodon::API::v1 &call, strcall += maptostr(parameters); } - return get_stream(strcall, answer, ptr); + return get_stream(strcall, ptr); } -uint16_t API::get_stream(const Mastodon::API::v1 &call, - string &answer, - std::unique_ptr &ptr) +return_call API::get_stream(const Mastodon::API::v1 &call, + std::unique_ptr &ptr) { parametermap p = {}; - return get_stream(call, p, answer, ptr); + return get_stream(call, p, ptr); } -uint16_t API::get_stream(const std::string &call, string &answer, - std::unique_ptr &ptr) +return_call API::get_stream(const std::string &call, std::unique_ptr &ptr) { ptr = std::make_unique(*this, _instance, _access_token); - return ptr->request(http::method::GET_STREAM, call, answer); + return ptr->request(http::method::GET_STREAM, call); } diff --git a/src/api/patch.cpp b/src/api/patch.cpp index c0fbc81..5095e56 100644 --- a/src/api/patch.cpp +++ b/src/api/patch.cpp @@ -1,5 +1,5 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,9 +21,8 @@ using namespace Mastodon; using std::cerr; -uint16_t API::patch(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer) +return_call API::patch(const Mastodon::API::v1 &call, + const parametermap ¶meters) { string strcall = ""; switch (call) @@ -32,11 +31,11 @@ uint16_t API::patch(const Mastodon::API::v1 &call, strcall = "/api/v1/accounts/update_credentials"; break; default: - ttdebug << "ERROR: Invalid call.\n"; - return 11; + ttdebug << "ERROR: Invalid argument.\n"; + return { 22, "Invalid argument", 0, "" }; break; } return _http.request(API::http::method::PATCH, - strcall, maptoformdata(parameters), answer); + strcall, maptoformdata(parameters)); } diff --git a/src/api/post.cpp b/src/api/post.cpp index 2935a1d..a2e228e 100644 --- a/src/api/post.cpp +++ b/src/api/post.cpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. @@ -20,8 +20,8 @@ using namespace Mastodon; -uint16_t API::post(const Mastodon::API::v1 &call, - const parametermap ¶meters, string &answer) +return_call API::post(const Mastodon::API::v1 &call, + const parametermap ¶meters) { string strcall = ""; string strid = ""; @@ -129,24 +129,22 @@ uint16_t API::post(const Mastodon::API::v1 &call, strcall = "/api/v1/statuses/" + strid + "/unbookmark"; break; default: - ttdebug << "ERROR: Invalid call.\n"; - return 11; + ttdebug << "ERROR: Invalid argument.\n"; + return { 22, "Invalid argument", 0, ""}; break; } - return post(strcall, parameters, answer); + return post(strcall, parameters); } -uint16_t API::post(const Mastodon::API::v1 &call, string &answer) +return_call API::post(const Mastodon::API::v1 &call) { const parametermap p; - return post(call, p, answer); + return post(call, p); } -uint16_t API::post(const string &call, - const parametermap ¶meters, string &answer) +return_call API::post(const string &call, const parametermap ¶meters) { - return _http.request(http::method::POST, call, - maptoformdata(parameters), answer); + return _http.request(http::method::POST, call, maptoformdata(parameters)); } diff --git a/src/api/put.cpp b/src/api/put.cpp index 1608665..6ecedc0 100644 --- a/src/api/put.cpp +++ b/src/api/put.cpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. @@ -20,8 +20,8 @@ using namespace Mastodon; -uint16_t API::put(const Mastodon::API::v1 &call, - const parametermap ¶meters, string &answer) +return_call API::put(const Mastodon::API::v1 &call, + const parametermap ¶meters) { string strcall = ""; string strid = ""; @@ -45,18 +45,16 @@ uint16_t API::put(const Mastodon::API::v1 &call, strcall = "/api/v1/push/subscription"; break; default: - ttdebug << "ERROR: Invalid call.\n"; - return 11; + ttdebug << "ERROR: Invalid argument.\n"; + return { 22, "Invalid argument", 0, "" }; break; } - return put(strcall, parameters, answer); + return put(strcall, parameters); } -uint16_t API::put(const string &call, - const parametermap ¶meters, string &answer) +return_call API::put(const string &call, const parametermap ¶meters) { - return _http.request(http::method::PUT, call, - maptoformdata(parameters), answer); + return _http.request(http::method::PUT, call, maptoformdata(parameters)); } diff --git a/src/easy/easy.hpp b/src/easy/easy.hpp index d6adf52..7a9cf7d 100644 --- a/src/easy/easy.hpp +++ b/src/easy/easy.hpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. diff --git a/src/http.cpp b/src/http.cpp index 71f927d..d877c01 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -1,5 +1,5 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/mastodon-cpp.cpp b/src/mastodon-cpp.cpp index 0bfa246..618a45b 100644 --- a/src/mastodon-cpp.cpp +++ b/src/mastodon-cpp.cpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 7ddac86..5cd621d 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -1,6 +1,6 @@ /* This file is part of mastodon-cpp. - * Copyright © 2018 tastytea - * + * Copyright © 2018, 2019 tastytea + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. @@ -476,12 +476,10 @@ public: * @brief Make a GET request which doesn't require parameters. * * @param call A call defined in Mastodon::API::v1 - * @param answer The answer from the server. Usually JSON. On error an - * empty string. * * @return @ref error "Error code". - * - * @since before 0.11.0 + * + * @since 0.100.0 */ const return_call get(const Mastodon::API::v1 &call); @@ -490,11 +488,8 @@ public: * * @param call A call defined in Mastodon::API::v1 * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. + * @return @ref error "Error code". */ const return_call get(const Mastodon::API::v1 &call, const parametermap ¶meters); @@ -502,7 +497,12 @@ public: /*! * @brief Make a GET request which requires parameters. * - * @since 0.16.0 + * @since 0.100.0 + * + * @param call A call defined in Mastodon::API::v2 + * @param parameters A Mastodon::API::parametermap containing parameters + * + * @return @ref error "Error code". */ const return_call get(const Mastodon::API::v2 &call, const parametermap ¶meters); @@ -511,13 +511,10 @@ public: * @brief Make a custom GET request. * * @param call String in the form `/api/v1/example` - * @param answer The answer from the server. Usually JSON. On error an - * empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ const return_call get(const string &call); @@ -526,54 +523,44 @@ public: * * @param call A call defined in Mastodon::API::v1 * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Events with JSON-payload. * @param ptr Pointer to the http object. Can be used to call * ptr->cancel_stream() * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t get_stream(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer, - std::unique_ptr &ptr); + return_call get_stream(const Mastodon::API::v1 &call, + const parametermap ¶meters, + std::unique_ptr &ptr); /*! * @brief Make a streaming GET request. * - * @param call A call defined in Mastodon::API::v1 - * @param answer The answer from the server. Events with JSON-payload. - * @param ptr Pointer to the http object. Can be used to call - * ptr->cancel_stream() + * @param call A call defined in Mastodon::API::v1 + * @param ptr Pointer to the http object. Can be used to call + * ptr->cancel_stream() * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t get_stream(const Mastodon::API::v1 &call, - string &answer, - std::unique_ptr &ptr); + return_call get_stream(const Mastodon::API::v1 &call, + std::unique_ptr &ptr); /*! * @brief Make a streaming GET request. * - * @param call String in the form `/api/v1/example` - * @param answer The answer from the server. Usually JSON. On error an - * empty string. - * @param ptr Pointer to the http object. Can be used to call - * ptr->cancel_stream() + * @param call String in the form `/api/v1/example` + * @param ptr Pointer to the http object. Can be used to call + * ptr->cancel_stream() * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t get_stream(const string &call, - string &answer, - std::unique_ptr &ptr); + return_call get_stream(const string &call, + std::unique_ptr &ptr); /*! * @brief Make a PATCH request. @@ -582,31 +569,24 @@ public: * * @param call A call defined in Mastodon::API::v1 * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t patch(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer); + return_call patch(const Mastodon::API::v1 &call, + const parametermap ¶meters); /*! * @brief Make a POST request which doesn't require parameters. * * @param call A call defined in Mastodon::API::v1 - * @param answer The answer from the server. Usually JSON. On error an - * empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t post(const Mastodon::API::v1 &call, string &answer); + return_call post(const Mastodon::API::v1 &call); /*! * @brief Make a POST request which requires parameters. @@ -615,17 +595,13 @@ public: * * @param call A call defined in Mastodon::API::v1 * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t post(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer); + return_call post(const Mastodon::API::v1 &call, + const parametermap ¶meters); /*! * @brief Make a custom POST request. @@ -634,53 +610,38 @@ public: * * @param call String in the form `/api/v1/example` * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t post(const string &call, - const parametermap ¶meters, - string &answer); + return_call post(const string &call, + const parametermap ¶meters); /*! * @brief Make a PUT request which requires a parameters. * * @param call A call defined in Mastodon::API::v1 - * @param parameters A Mastodon::API::parametermap containing - * parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. + * @param parameters A Mastodon::API::parametermap containing parameters * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t put(const Mastodon::API::v1 &call, - const parametermap ¶meters, - string &answer); + return_call put(const Mastodon::API::v1 &call, + const parametermap ¶meters); /*! * @brief Make a custom PUT request. * * @param call String in the form `/api/v1/example` - * @param parameters A Mastodon::API::parametermap containing - * parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. + * @param parameters A Mastodon::API::parametermap containing parameters * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t put(const string &call, - const parametermap ¶meters, - string &answer); + return_call put(const string &call, const parametermap ¶meters); /*! * @brief Make a DELETE request which requires parameters. @@ -689,28 +650,23 @@ public: * @param parameters A Mastodon::API::parametermap containing parameters * * @return @ref error "Error code". - * - * @since before 0.11.0 + * + * @since 0.100.0 */ - uint16_t del(const Mastodon::API::v1 &call, - const parametermap ¶meters); + return_call del(const Mastodon::API::v1 &call, + const parametermap ¶meters); /*! * @brief Make a custom DELETE request. * * @param call String in the form `/api/v1/example` * @param parameters A Mastodon::API::parametermap containing parameters - * @param answer The answer from the server. Usually JSON. On error - * an empty string. * - * @return @ref error "Error code". If the URL has permanently changed, 13 - * is returned and answer is set to the new URL. - * - * @since before 0.11.0 + * @return @ref error "Error code". + * + * @since 0.100.0 */ - uint16_t del(const string &call, - const parametermap ¶meters, - string &answer); + return_call del(const string &call, const parametermap ¶meters); private: const string _instance;