summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/connection.cpp20
-rw-r--r--src/curl_wrapper.cpp40
-rw-r--r--src/instance.cpp27
3 files changed, 30 insertions, 57 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 0eba695..77e7ad0 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -21,26 +21,6 @@ namespace mastodonpp
using std::holds_alternative;
-Connection::Connection(Instance &instance)
- : _instance{instance}
- , _baseuri{instance.get_baseuri()}
-{
- auto proxy{_instance.get_proxy()};
- if (!proxy.empty())
- {
- CURLWrapper::set_proxy(proxy);
- }
-
- if (!_instance.get_access_token().empty())
- {
- CURLWrapper::set_access_token(_instance.get_access_token());
- }
- if (!_instance.get_cainfo().empty())
- {
- CURLWrapper::set_cainfo(_instance.get_cainfo());
- }
-}
-
string Connection::endpoint_to_uri(const endpoint_variant &endpoint) const
{
if (holds_alternative<API::endpoint_type>(endpoint))
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp
index 4cfb9b5..50e20ab 100644
--- a/src/curl_wrapper.cpp
+++ b/src/curl_wrapper.cpp
@@ -64,16 +64,6 @@ CURLWrapper::~CURLWrapper() noexcept
}
}
-void CURLWrapper::set_proxy(const string_view proxy)
-{
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
- CURLcode code{curl_easy_setopt(_connection, CURLOPT_PROXY, proxy.data())};
- if (code != CURLE_OK)
- {
- throw CURLException{code, "Failed to set proxy", _curl_buffer_error};
- }
-}
-
answer_type CURLWrapper::make_request(const http_method &method, string uri,
const parametermap &parameters)
{
@@ -197,6 +187,36 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri,
return answer;
}
+void CURLWrapper::setup_connection_properties(string_view proxy,
+ string_view access_token,
+ string_view cainfo)
+{
+ if (!proxy.empty())
+ {
+ set_proxy(proxy);
+ }
+
+ if (!access_token.empty())
+ {
+ set_access_token(access_token);
+ }
+
+ if (!cainfo.empty())
+ {
+ set_cainfo(cainfo);
+ }
+}
+
+void CURLWrapper::set_proxy(const string_view proxy)
+{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ CURLcode code{curl_easy_setopt(_connection, CURLOPT_PROXY, proxy.data())};
+ if (code != CURLE_OK)
+ {
+ throw CURLException{code, "Failed to set proxy", _curl_buffer_error};
+ }
+}
+
void CURLWrapper::set_access_token(const string_view access_token)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-signed-bitwise)
diff --git a/src/instance.cpp b/src/instance.cpp
index 19c6b8b..cd99645 100644
--- a/src/instance.cpp
+++ b/src/instance.cpp
@@ -32,13 +32,6 @@ using std::regex;
using std::regex_search;
using std::smatch;
-Instance::Instance(const string_view hostname, const string_view access_token)
- : _hostname{hostname}
- , _baseuri{"https://" + _hostname}
- , _access_token{access_token}
- , _max_chars{0}
-{}
-
uint64_t Instance::get_max_chars() noexcept
{
constexpr uint64_t default_max_chars{500};
@@ -162,26 +155,6 @@ vector<string> Instance::get_post_formats() noexcept
return _post_formats;
}
-Instance::ObtainToken::ObtainToken(Instance &instance)
- : _instance{instance}
- , _baseuri{instance.get_baseuri()}
-{
- auto proxy{_instance.get_proxy()};
- if (!proxy.empty())
- {
- CURLWrapper::set_proxy(proxy);
- }
-
- if (!_instance.get_access_token().empty())
- {
- CURLWrapper::set_access_token(_instance.get_access_token());
- }
- if (!_instance.get_cainfo().empty())
- {
- CURLWrapper::set_cainfo(_instance.get_cainfo());
- }
-}
-
answer_type Instance::ObtainToken::step_1(const string_view client_name,
const string_view scopes,
const string_view website)