Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions include/cpp_restapi/cpp-httplib_connection.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/cpp_restapi/create_cpp-httplib_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include "cpp_restapi_export.h"

#include "iconnection.hpp"

namespace cpp_restapi
{
struct IConnection;

/**
* @brief Create a connection using the cpp-httplib backend
* @param address base URL of the API (e.g. "https://api.github.com")
Expand Down
26 changes: 0 additions & 26 deletions include/cpp_restapi/curl_connection.hpp

This file was deleted.

14 changes: 1 addition & 13 deletions include/cpp_restapi/github/connection_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <functional>
#include <map>
#include <memory>
#include <utility>

#include <cpp_restapi/iconnection.hpp>

Expand Down Expand Up @@ -68,19 +69,6 @@ namespace cpp_restapi::GitHub
std::forward<Args>(args)..., m_address, m_headerEntries);
}

/**
* @brief build @ref cpp_restapi::IConnection object
* @tparam CT connection type (Qt or Curl backend). @ref cpp_restapi::CurlBackend::Connection or @ref cpp_restapi::QtBackend::Connection
* @param args backend specific arguments to be passed to connection.
* @deprecated Use build(factory, args...) with a factory function instead (e.g. build(createCurlConnection))
*/
template<typename CT, typename... Args>
[[deprecated("Use build(factory, args...) with a factory function instead")]]
std::shared_ptr<IConnection> build(Args&&... args)
{
return std::make_shared<CT>(std::forward<Args>(args)..., m_address, m_headerEntries);
}

private:
std::map<std::string, std::string> m_headerEntries;
std::string m_address;
Expand Down
10 changes: 2 additions & 8 deletions include/cpp_restapi/github/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace cpp_restapi::GitHub
class CPP_RESTAPI_GITHUB_EXPORT Request
{
public:
Request(std::shared_ptr<cpp_restapi::IConnection>);
explicit Request(std::unique_ptr<cpp_restapi::IConnection>);
Request(const Request &) = delete;
~Request();

Expand Down Expand Up @@ -97,12 +97,6 @@ namespace cpp_restapi::GitHub
*/
std::string getAuthenticatedUser();

/**
* @deprecated Use getAuthenticatedUser() instead (fixes typo in method name).
*/
[[deprecated("Use getAuthenticatedUser() instead")]]
std::string getAuntenticatedUser();

/**
* @brief Lists all users, in the order that they
* signed up on GitHub. This list includes personal
Expand Down Expand Up @@ -520,7 +514,7 @@ namespace cpp_restapi::GitHub
std::string repoContributors(const std::string& owner, const std::string& repo);

private:
std::shared_ptr<cpp_restapi::IConnection> m_connection;
std::unique_ptr<cpp_restapi::IConnection> m_connection;

std::string doRequest(const std::string &);
};
Expand Down
2 changes: 1 addition & 1 deletion include/cpp_restapi/isse_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace cpp_restapi
* @brief Interface for SSE (Server-Sent Events) connections
*
* Provides streaming subscription to an SSE endpoint.
* Unlike IConnection::get() which returns a complete response,
* Unlike IConnection::fetch() which returns a complete response,
* SSE delivers events continuously via a callback.
*/
struct ISseConnection
Expand Down
42 changes: 0 additions & 42 deletions include/cpp_restapi/qt_connection.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion src/base_connection.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#include <cpp_restapi/base_connection.hpp>
#include <cpp_restapi/ipagination_strategy.hpp>

#include "base_connection.hpp"


namespace cpp_restapi
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include <map>

#include <cpp_restapi/iconnection.hpp>
#include "cpp_restapi_export.h"


namespace cpp_restapi
{
/**
* @brief base class with common parts for backend specific implementations
*/
class CPP_RESTAPI_EXPORT BaseConnection: public cpp_restapi::IConnection
class BaseConnection: public cpp_restapi::IConnection
{
public:
explicit BaseConnection(const std::string& address, const std::map<std::string, std::string>& headerEntries);
Expand Down
1 change: 0 additions & 1 deletion src/cpp-httplib_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ endif()
target_sources(cpp_restapi_core
PRIVATE
connection.cpp
create_connection.cpp
sse_connection.cpp
)

Expand Down
44 changes: 34 additions & 10 deletions src/cpp-httplib_backend/connection.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@

#include <utility>

#include <httplib.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <cpp_restapi/cpp-httplib_connection.hpp>
#pragma GCC diagnostic pop
#include <cpp_restapi/create_cpp-httplib_connection.hpp>
#include "cpp-httplib_sse_connection.hpp"
#include "threaded_connection.hpp"


namespace cpp_restapi::CppHttplibBackend
namespace
{
Connection::Connection(const std::string& address, const std::map<std::string, std::string>& headerEntries)
: ThreadedConnection(address, headerEntries)
class CppHttplibConnection final: public cpp_restapi::ThreadedConnection
{
public:
CppHttplibConnection(const std::string& address, const std::map<std::string, std::string>& headerEntries);
CppHttplibConnection(const CppHttplibConnection &) = delete;

CppHttplibConnection& operator=(const CppHttplibConnection &) = delete;

cpp_restapi::Response fetchPage(const std::string& request) override;
std::unique_ptr<cpp_restapi::ISseConnection> subscribe(const std::string& request, cpp_restapi::IConnection::EventCallback callback) override;
};


CppHttplibConnection::CppHttplibConnection(const std::string& address, const std::map<std::string, std::string>& headerEntries)
: cpp_restapi::ThreadedConnection(address, headerEntries)
{

}


Response Connection::fetchPage(const std::string& page)
cpp_restapi::Response CppHttplibConnection::fetchPage(const std::string& page)
{
auto pos = page.find("//");
if (pos == std::string::npos)
Expand Down Expand Up @@ -48,10 +61,21 @@ namespace cpp_restapi::CppHttplibBackend
}


std::unique_ptr<ISseConnection> Connection::subscribe(const std::string& request, EventCallback callback)
std::unique_ptr<cpp_restapi::ISseConnection> CppHttplibConnection::subscribe(const std::string& request, cpp_restapi::IConnection::EventCallback callback)
{
auto sse = std::make_unique<SseConnection>(address(), getHeaderEntries());
auto sse = std::make_unique<cpp_restapi::CppHttplibBackend::SseConnection>(address(), getHeaderEntries());
sse->subscribe(request, std::move(callback));
return sse;
}
}


namespace cpp_restapi
{
std::unique_ptr<IConnection> createCppHttplibConnection(
const std::string& address,
const std::map<std::string, std::string>& headerEntries)
{
return std::make_unique<CppHttplibConnection>(address, headerEntries);
}
}
20 changes: 0 additions & 20 deletions src/cpp-httplib_backend/create_connection.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/curl_backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ find_package(CURL REQUIRED)
target_sources(cpp_restapi_core
PRIVATE
connection.cpp
create_connection.cpp
sse_connection.cpp
)

Expand Down
47 changes: 36 additions & 11 deletions src/curl_backend/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,45 @@
#include <cassert>
#include <iterator>
#include <string>
#include <utility>
#include <curl/curl.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <cpp_restapi/curl_connection.hpp>
#pragma GCC diagnostic pop
#include <cpp_restapi/create_curl_connection.hpp>
#include "curl_sse_connection.hpp"
#include "threaded_connection.hpp"


namespace cpp_restapi::CurlBackend
namespace
{
Connection::Connection(const std::string& address, const std::map<std::string, std::string>& headerEntries)
: ThreadedConnection(address, headerEntries)
class CurlConnection final: public cpp_restapi::ThreadedConnection
{
public:
CurlConnection(const std::string& address, const std::map<std::string, std::string>& headerEntries);
CurlConnection(const CurlConnection &) = delete;

~CurlConnection() override;

CurlConnection& operator=(const CurlConnection &) = delete;

cpp_restapi::Response fetchPage(const std::string& request) override;
std::unique_ptr<cpp_restapi::ISseConnection> subscribe(const std::string& request, cpp_restapi::IConnection::EventCallback callback) override;
};


CurlConnection::CurlConnection(const std::string& address, const std::map<std::string, std::string>& headerEntries)
: cpp_restapi::ThreadedConnection(address, headerEntries)
{

}


Connection::~Connection()
CurlConnection::~CurlConnection()
{

}


Response Connection::fetchPage(const std::string& page)
cpp_restapi::Response CurlConnection::fetchPage(const std::string& page)
{
std::string body;
std::string headers;
Expand Down Expand Up @@ -102,10 +116,21 @@ namespace cpp_restapi::CurlBackend
}


std::unique_ptr<ISseConnection> Connection::subscribe(const std::string& request, EventCallback callback)
std::unique_ptr<cpp_restapi::ISseConnection> CurlConnection::subscribe(const std::string& request, cpp_restapi::IConnection::EventCallback callback)
{
auto sse = std::make_unique<SseConnection>(address(), getHeaderEntries());
auto sse = std::make_unique<cpp_restapi::CurlBackend::SseConnection>(address(), getHeaderEntries());
sse->subscribe(request, std::move(callback));
return sse;
}
}


namespace cpp_restapi
{
std::unique_ptr<IConnection> createCurlConnection(
const std::string& address,
const std::map<std::string, std::string>& headerEntries)
{
return std::make_unique<CurlConnection>(address, headerEntries);
}
}
Loading
Loading