summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-01-11 16:07:40 +0100
committertastytea2020-01-11 16:07:40 +0100
commitf556df296f7395a3662e1c371d9b942f404105cd (patch)
tree6c086572090ac0c4508ec2383399d447ba4c695a
parent5051664136357bb38dc235084e82c4d741f25c3f (diff)
downloadmastodonpp-f556df296f7395a3662e1c371d9b942f404105cd.tar
mastodonpp-f556df296f7395a3662e1c371d9b942f404105cd.tar.gz
mastodonpp-f556df296f7395a3662e1c371d9b942f404105cd.zip
Add HTTP methods PATCH and PUT.
-rw-r--r--include/connection.hpp52
-rw-r--r--src/connection.cpp14
-rw-r--r--src/curl_wrapper.cpp18
3 files changed, 83 insertions, 1 deletions
diff --git a/include/connection.hpp b/include/connection.hpp
index 0ed09eb..398b8d5 100644
--- a/include/connection.hpp
+++ b/include/connection.hpp
@@ -162,6 +162,58 @@ public:
}
/*!
+ * @brief Make a HTTP PATCH call with parameters.
+ *
+ * @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
+ * @param parameters A map of parameters.
+ *
+ *
+ * @since 0.1.0
+ */
+ [[nodiscard]]
+ answer_type patch(const endpoint_variant &endpoint,
+ const parametermap &parameters);
+
+ /*!
+ * @brief Make a HTTP PATCH call.
+ *
+ * @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
+ *
+ * @since 0.1.0
+ */
+ [[nodiscard]]
+ inline answer_type patch(const endpoint_variant &endpoint)
+ {
+ return post(endpoint, {});
+ }
+
+ /*!
+ * @brief Make a HTTP PUT call with parameters.
+ *
+ * @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
+ * @param parameters A map of parameters.
+ *
+ *
+ * @since 0.1.0
+ */
+ [[nodiscard]]
+ answer_type put(const endpoint_variant &endpoint,
+ const parametermap &parameters);
+
+ /*!
+ * @brief Make a HTTP PUT call.
+ *
+ * @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
+ *
+ * @since 0.1.0
+ */
+ [[nodiscard]]
+ inline answer_type put(const endpoint_variant &endpoint)
+ {
+ return post(endpoint, {});
+ }
+
+ /*!
* @brief Copy new stream contents and delete the “original”.
*
* Note that the last event is not necessarily complete, it could happen
diff --git a/src/connection.cpp b/src/connection.cpp
index f74a816..9cde7d3 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -61,6 +61,20 @@ answer_type Connection::post(const endpoint_variant &endpoint,
endpoint_to_uri(endpoint), parameters);
}
+answer_type Connection::patch(const endpoint_variant &endpoint,
+ const parametermap &parameters)
+{
+ return make_request(http_method::PATCH,
+ endpoint_to_uri(endpoint), parameters);
+}
+
+answer_type Connection::put(const endpoint_variant &endpoint,
+ const parametermap &parameters)
+{
+ return make_request(http_method::PUT,
+ endpoint_to_uri(endpoint), parameters);
+}
+
string Connection::get_new_stream_contents()
{
buffer_mutex.lock();
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp
index 047b799..7b2b352 100644
--- a/src/curl_wrapper.cpp
+++ b/src/curl_wrapper.cpp
@@ -111,14 +111,30 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri,
}
case http_method::PATCH:
{
+ if (!parameters.empty())
+ {
+ curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ code = curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
+ }
+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "PATCH");
+
break;
}
case http_method::PUT:
{
+ if (!parameters.empty())
+ {
+ curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ code = curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
+ }
+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
- code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
+ code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "PUT");
+
break;
}
case http_method::DELETE: