Replaced return types for get_stream, patch, post, put, del
the build failed Details

This commit is contained in:
tastytea 2019-02-22 12:33:03 +01:00
parent ade55f8f19
commit cbb1e18b0c
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
10 changed files with 126 additions and 181 deletions

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
@ -20,8 +20,8 @@
using namespace Mastodon; using namespace Mastodon;
uint16_t API::del(const Mastodon::API::v1 &call, return_call API::del(const Mastodon::API::v1 &call,
const parametermap &parameters) const parametermap &parameters)
{ {
string strcall = ""; string strcall = "";
string strid = ""; string strid = "";
@ -51,19 +51,16 @@ uint16_t API::del(const Mastodon::API::v1 &call,
strcall = "/api/v1/push/subscription"; strcall = "/api/v1/push/subscription";
break; break;
default: default:
ttdebug << "ERROR: Invalid call.\n"; ttdebug << "ERROR: Invalid argument.\n";
return 11; return { 22, "Invalid argument", 0, "" };
break; break;
} }
string answer; return del(strcall, parameters);
return del(strcall, parameters, answer);
} }
uint16_t API::del(const std::string &call, return_call API::del(const std::string &call, const parametermap &parameters)
const parametermap &parameters, string &answer)
{ {
return _http.request(http::method::DELETE, call, return _http.request(http::method::DELETE, call, maptoformdata(parameters));
maptoformdata(parameters), answer);
} }

View File

@ -1,5 +1,5 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
@ -21,10 +21,9 @@
using namespace Mastodon; using namespace Mastodon;
using std::cerr; using std::cerr;
uint16_t API::get_stream(const Mastodon::API::v1 &call, return_call API::get_stream(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters,
string &answer, std::unique_ptr<Mastodon::API::http> &ptr)
std::unique_ptr<Mastodon::API::http> &ptr)
{ {
string strcall = ""; string strcall = "";
@ -47,7 +46,7 @@ uint16_t API::get_stream(const Mastodon::API::v1 &call,
break; break;
default: default:
ttdebug << "ERROR: Invalid call.\n"; ttdebug << "ERROR: Invalid call.\n";
return 11; return { 22, "Invalid argument", 0, "" };
break; break;
} }
@ -56,20 +55,18 @@ uint16_t API::get_stream(const Mastodon::API::v1 &call,
strcall += maptostr(parameters); strcall += maptostr(parameters);
} }
return get_stream(strcall, answer, ptr); return get_stream(strcall, ptr);
} }
uint16_t API::get_stream(const Mastodon::API::v1 &call, return_call API::get_stream(const Mastodon::API::v1 &call,
string &answer, std::unique_ptr<Mastodon::API::http> &ptr)
std::unique_ptr<Mastodon::API::http> &ptr)
{ {
parametermap p = {}; 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, return_call API::get_stream(const std::string &call, std::unique_ptr<http> &ptr)
std::unique_ptr<http> &ptr)
{ {
ptr = std::make_unique<http>(*this, _instance, _access_token); ptr = std::make_unique<http>(*this, _instance, _access_token);
return ptr->request(http::method::GET_STREAM, call, answer); return ptr->request(http::method::GET_STREAM, call);
} }

View File

@ -1,5 +1,5 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,9 +21,8 @@
using namespace Mastodon; using namespace Mastodon;
using std::cerr; using std::cerr;
uint16_t API::patch(const Mastodon::API::v1 &call, return_call API::patch(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters)
string &answer)
{ {
string strcall = ""; string strcall = "";
switch (call) switch (call)
@ -32,11 +31,11 @@ uint16_t API::patch(const Mastodon::API::v1 &call,
strcall = "/api/v1/accounts/update_credentials"; strcall = "/api/v1/accounts/update_credentials";
break; break;
default: default:
ttdebug << "ERROR: Invalid call.\n"; ttdebug << "ERROR: Invalid argument.\n";
return 11; return { 22, "Invalid argument", 0, "" };
break; break;
} }
return _http.request(API::http::method::PATCH, return _http.request(API::http::method::PATCH,
strcall, maptoformdata(parameters), answer); strcall, maptoformdata(parameters));
} }

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
@ -20,8 +20,8 @@
using namespace Mastodon; using namespace Mastodon;
uint16_t API::post(const Mastodon::API::v1 &call, return_call API::post(const Mastodon::API::v1 &call,
const parametermap &parameters, string &answer) const parametermap &parameters)
{ {
string strcall = ""; string strcall = "";
string strid = ""; string strid = "";
@ -129,24 +129,22 @@ uint16_t API::post(const Mastodon::API::v1 &call,
strcall = "/api/v1/statuses/" + strid + "/unbookmark"; strcall = "/api/v1/statuses/" + strid + "/unbookmark";
break; break;
default: default:
ttdebug << "ERROR: Invalid call.\n"; ttdebug << "ERROR: Invalid argument.\n";
return 11; return { 22, "Invalid argument", 0, ""};
break; 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; const parametermap p;
return post(call, p, answer); return post(call, p);
} }
uint16_t API::post(const string &call, return_call API::post(const string &call, const parametermap &parameters)
const parametermap &parameters, string &answer)
{ {
return _http.request(http::method::POST, call, return _http.request(http::method::POST, call, maptoformdata(parameters));
maptoformdata(parameters), answer);
} }

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
@ -20,8 +20,8 @@
using namespace Mastodon; using namespace Mastodon;
uint16_t API::put(const Mastodon::API::v1 &call, return_call API::put(const Mastodon::API::v1 &call,
const parametermap &parameters, string &answer) const parametermap &parameters)
{ {
string strcall = ""; string strcall = "";
string strid = ""; string strid = "";
@ -45,18 +45,16 @@ uint16_t API::put(const Mastodon::API::v1 &call,
strcall = "/api/v1/push/subscription"; strcall = "/api/v1/push/subscription";
break; break;
default: default:
ttdebug << "ERROR: Invalid call.\n"; ttdebug << "ERROR: Invalid argument.\n";
return 11; return { 22, "Invalid argument", 0, "" };
break; break;
} }
return put(strcall, parameters, answer); return put(strcall, parameters);
} }
uint16_t API::put(const string &call, return_call API::put(const string &call, const parametermap &parameters)
const parametermap &parameters, string &answer)
{ {
return _http.request(http::method::PUT, call, return _http.request(http::method::PUT, call, maptoformdata(parameters));
maptoformdata(parameters), answer);
} }

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.

View File

@ -1,5 +1,5 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.

View File

@ -1,6 +1,6 @@
/* This file is part of mastodon-cpp. /* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
@ -476,12 +476,10 @@ public:
* @brief Make a GET request which doesn't require parameters. * @brief Make a GET request which doesn't require parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
* *
* @since before 0.11.0 * @since 0.100.0
*/ */
const return_call get(const Mastodon::API::v1 &call); const return_call get(const Mastodon::API::v1 &call);
@ -490,11 +488,8 @@ public:
* *
* @param call A call defined in Mastodon::API::v1 * @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL.
*/ */
const return_call get(const Mastodon::API::v1 &call, const return_call get(const Mastodon::API::v1 &call,
const parametermap &parameters); const parametermap &parameters);
@ -502,7 +497,12 @@ public:
/*! /*!
* @brief Make a GET request which requires parameters. * @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 return_call get(const Mastodon::API::v2 &call,
const parametermap &parameters); const parametermap &parameters);
@ -511,13 +511,10 @@ public:
* @brief Make a custom GET request. * @brief Make a custom GET request.
* *
* @param call String in the form `/api/v1/example` * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
const return_call get(const string &call); const return_call get(const string &call);
@ -526,54 +523,44 @@ public:
* *
* @param call A call defined in Mastodon::API::v1 * @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @param ptr Pointer to the http object. Can be used to call
* ptr->cancel_stream() * ptr->cancel_stream()
* *
* @return @ref error "Error code". If the URL has permanently changed, 13 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t get_stream(const Mastodon::API::v1 &call, return_call get_stream(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters,
string &answer, std::unique_ptr<Mastodon::API::http> &ptr);
std::unique_ptr<Mastodon::API::http> &ptr);
/*! /*!
* @brief Make a streaming GET request. * @brief Make a streaming GET request.
* *
* @param call A call defined in Mastodon::API::v1 * @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
* @param ptr Pointer to the http object. Can be used to call * ptr->cancel_stream()
* ptr->cancel_stream()
* *
* @return @ref error "Error code". If the URL has permanently changed, 13 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t get_stream(const Mastodon::API::v1 &call, return_call get_stream(const Mastodon::API::v1 &call,
string &answer, std::unique_ptr<Mastodon::API::http> &ptr);
std::unique_ptr<Mastodon::API::http> &ptr);
/*! /*!
* @brief Make a streaming GET request. * @brief Make a streaming GET request.
* *
* @param call String in the form `/api/v1/example` * @param call String in the form `/api/v1/example`
* @param answer The answer from the server. Usually JSON. On error an * @param ptr Pointer to the http object. Can be used to call
* empty string. * ptr->cancel_stream()
* @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t get_stream(const string &call, return_call get_stream(const string &call,
string &answer, std::unique_ptr<Mastodon::API::http> &ptr);
std::unique_ptr<Mastodon::API::http> &ptr);
/*! /*!
* @brief Make a PATCH request. * @brief Make a PATCH request.
@ -582,31 +569,24 @@ public:
* *
* @param call A call defined in Mastodon::API::v1 * @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t patch(const Mastodon::API::v1 &call, return_call patch(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters);
string &answer);
/*! /*!
* @brief Make a POST request which doesn't require parameters. * @brief Make a POST request which doesn't require parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.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. * @brief Make a POST request which requires parameters.
@ -615,17 +595,13 @@ public:
* *
* @param call A call defined in Mastodon::API::v1 * @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t post(const Mastodon::API::v1 &call, return_call post(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters);
string &answer);
/*! /*!
* @brief Make a custom POST request. * @brief Make a custom POST request.
@ -634,53 +610,38 @@ public:
* *
* @param call String in the form `/api/v1/example` * @param call String in the form `/api/v1/example`
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t post(const string &call, return_call post(const string &call,
const parametermap &parameters, const parametermap &parameters);
string &answer);
/*! /*!
* @brief Make a PUT request which requires a parameters. * @brief Make a PUT request which requires a parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing * @param parameters A Mastodon::API::parametermap containing parameters
* 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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t put(const Mastodon::API::v1 &call, return_call put(const Mastodon::API::v1 &call,
const parametermap &parameters, const parametermap &parameters);
string &answer);
/*! /*!
* @brief Make a custom PUT request. * @brief Make a custom PUT request.
* *
* @param call String in the form `/api/v1/example` * @param call String in the form `/api/v1/example`
* @param parameters A Mastodon::API::parametermap containing * @param parameters A Mastodon::API::parametermap containing parameters
* 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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t put(const string &call, return_call put(const string &call, const parametermap &parameters);
const parametermap &parameters,
string &answer);
/*! /*!
* @brief Make a DELETE request which requires parameters. * @brief Make a DELETE request which requires parameters.
@ -689,28 +650,23 @@ public:
* @param parameters A Mastodon::API::parametermap containing parameters * @param parameters A Mastodon::API::parametermap containing parameters
* *
* @return @ref error "Error code". * @return @ref error "Error code".
* *
* @since before 0.11.0 * @since 0.100.0
*/ */
uint16_t del(const Mastodon::API::v1 &call, return_call del(const Mastodon::API::v1 &call,
const parametermap &parameters); const parametermap &parameters);
/*! /*!
* @brief Make a custom DELETE request. * @brief Make a custom DELETE request.
* *
* @param call String in the form `/api/v1/example` * @param call String in the form `/api/v1/example`
* @param parameters A Mastodon::API::parametermap containing parameters * @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 * @return @ref error "Error code".
* is returned and answer is set to the new URL. *
* * @since 0.100.0
* @since before 0.11.0
*/ */
uint16_t del(const string &call, return_call del(const string &call, const parametermap &parameters);
const parametermap &parameters,
string &answer);
private: private:
const string _instance; const string _instance;