diff --git a/.github/workflows/linux-build-qt5.yml b/.github/workflows/linux-build-qt5.yml index 7ffd784..19db029 100644 --- a/.github/workflows/linux-build-qt5.yml +++ b/.github/workflows/linux-build-qt5.yml @@ -36,7 +36,7 @@ jobs: with: build-dir: ${{ runner.workspace }}/build build-type: Release - configure-options: -DGitHubAPI_Tests=ON -DGitHubAPI_UseQt6=OFF + configure-options: -DCppRestAPI_Tests=ON -DCppRestAPI_UseQt6=OFF run-test: true - name: Build Examples diff --git a/.github/workflows/linux-build-qt6.yml b/.github/workflows/linux-build-qt6.yml index ab33d21..aed9dea 100644 --- a/.github/workflows/linux-build-qt6.yml +++ b/.github/workflows/linux-build-qt6.yml @@ -36,7 +36,7 @@ jobs: with: build-dir: ${{ runner.workspace }}/build build-type: Release - configure-options: -DGitHubAPI_Tests=ON -DGitHubAPI_UseQt6=ON + configure-options: -DCppRestAPI_Tests=ON -DCppRestAPI_UseQt6=ON run-test: true - name: Build Examples @@ -45,4 +45,4 @@ jobs: source-dir: ${{ github.workspace }}/examples build-dir: ${{ runner.workspace }}/build-examples build-type: Release - configure-options: -DGitHubAPI_UseQt6=ON + configure-options: -DCppRestAPI_UseQt6=ON diff --git a/CMakeLists.txt b/CMakeLists.txt index ba97df9..d96e71c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,20 +21,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include(GenerateExportHeader) -# For compatibility. TODO: remove -if(GitHubAPI_QtBackend) - set(CppRestAPI_QtBackend ${GitHubAPI_QtBackend}) - message(WARNING "GitHubAPI_QtBackend is deprecated, please use CppRestAPI_QtBackend") -endif() -if(GitHubAPI_CurlBackend) - set(CppRestAPI_CurlBackend ${GitHubAPI_CurlBackend}) - message(WARNING "GitHubAPI_CurlBackend is deprecated, please use CppRestAPI_CurlBackend") -endif() -if(GitHubAPI_Tests) - set(CppRestAPI_Tests ${GitHubAPI_Tests}) - message(WARNING "GitHubAPI_Tests is deprecated, please use CppRestAPI_Tests") -endif() - option(CppRestAPI_QtBackend "Qt backend for GitHubApi" OFF) option(CppRestAPI_CurlBackend "libcurl backend for GitHubApi" OFF) option(CppRestAPI_Tests "Enable GitHubApi tests. Forces both CppRestAPI_QtBackend and CppRestAPI_CurlBackend to be ON" OFF) @@ -47,7 +33,6 @@ endif() add_library(cpp_restapi src/base_connection.cpp src/header_utils.cpp - src/services/github/github_api_base.cpp src/services/github/request.cpp ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c90c5c2..299be19 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,29 +7,16 @@ if (NOT Qt6_FOUND) find_package(Qt5 REQUIRED COMPONENTS Network Core) endif() -set(GitHubAPI_UseQt6 ${Qt6_FOUND}) -set(GitHubAPI_QtBackend ON) -set(GitHubAPI_CurlBackend ON) +set(CppRestAPI_UseQt6 ${Qt6_FOUND}) +set(CppRestAPI_QtBackend ON) +set(CppRestAPI_CurlBackend ON) add_subdirectory(.. cpp_restapi_root) #include directory with github_api -add_executable(deprecated_qt_example deprecated_qt_example.cpp) -add_executable(deprecated_curl_example deprecated_curl_example.cpp) add_executable(qt_example qt_example.cpp) add_executable(curl_example curl_example.cpp) add_executable(bare_curl_connection_example bare_curl_connection_example.cpp) add_executable(bare_qt_connection_example bare_qt_connection_example.cpp) -target_link_libraries(deprecated_qt_example - PRIVATE - github_api - Qt::Network -) - -target_link_libraries(deprecated_curl_example - PRIVATE - github_api -) - target_link_libraries(qt_example PRIVATE github_api diff --git a/include/cpp_restapi/github/github_api_base.hpp b/include/cpp_restapi/github/github_api_base.hpp deleted file mode 100644 index 6e68499..0000000 --- a/include/cpp_restapi/github/github_api_base.hpp +++ /dev/null @@ -1,21 +0,0 @@ - -#ifndef GITHUB_API_BASE_HPP_INCLUDED -#define GITHUB_API_BASE_HPP_INCLUDED - -#include "igithub_api.hpp" - -namespace cpp_restapi -{ - class [[deprecated("Use GitHubConnectionBuilder")]] GitHubBase: public cpp_restapi::GitHub::IApi - { - public: - GitHubBase(const std::string& address); - - const std::string& address() const override; - - private: - std::string m_address; - }; -} - -#endif diff --git a/include/cpp_restapi/github/github_api_curl.hpp b/include/cpp_restapi/github/github_api_curl.hpp deleted file mode 100644 index 1fa39c4..0000000 --- a/include/cpp_restapi/github/github_api_curl.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef GITHUBAPI_CURL_HPP -#define GITHUBAPI_CURL_HPP - -#include - -#include "cpp_restapi/iconnection.hpp" -#include "github_api_base.hpp" -#include "cpp_restapi_export.h" - -namespace cpp_restapi::GitHub::CurlBackend -{ - /** - * @brief Class for establishing connection with GitHub api with Curl. Deprecated, use @ref cpp_restapi::GitHub::ConnectionBuilder instead - */ - class CPP_RESTAPI_DEPRECATED_EXPORT Api: public cpp_restapi::GitHubBase - { - public: - Api(const std::string& addr = "https://api.github.com"); - Api(const Api &) = delete; - ~Api(); - - std::unique_ptr connect(const std::string& token = "") override; - - Api& operator=(const Api &) = delete; - }; - -} - -#endif diff --git a/include/cpp_restapi/github/github_api_qt.hpp b/include/cpp_restapi/github/github_api_qt.hpp deleted file mode 100644 index de2fc3c..0000000 --- a/include/cpp_restapi/github/github_api_qt.hpp +++ /dev/null @@ -1,41 +0,0 @@ - -#ifndef GITHUBAPI_QT_HPP -#define GITHUBAPI_QT_HPP - -// Based on: -// https://developer.github.com/guides/getting-started/ -// https://developer.github.com/v3/ - -#include - -#include - -#include "cpp_restapi/iconnection.hpp" -#include "github_api_base.hpp" -#include "cpp_restapi_export.h" - -class QNetworkAccessManager; - -namespace cpp_restapi::GitHub::QtBackend -{ - - /** - * @brief Class for establishing connection with GitHub api with Qt's QNetworkAccessManager. Deprecated, use @ref cpp_restapi::GitHub::ConnectionBuilder instead - */ - class CPP_RESTAPI_DEPRECATED_EXPORT Api: public cpp_restapi::GitHubBase - { - public: - Api(QNetworkAccessManager &, const QString& addr = "https://api.github.com"); - Api(const Api &) = delete; - - std::unique_ptr connect(const std::string& token = "") override; - - Api& operator=(const Api &) = delete; - - private: - QNetworkAccessManager& m_manager; - }; - -} - -#endif diff --git a/include/cpp_restapi/github/igithub_api.hpp b/include/cpp_restapi/github/igithub_api.hpp deleted file mode 100644 index a4a5ad2..0000000 --- a/include/cpp_restapi/github/igithub_api.hpp +++ /dev/null @@ -1,37 +0,0 @@ - -#ifndef GITHUBAPI_HPP -#define GITHUBAPI_HPP - -#include -#include - -#include - - -namespace cpp_restapi::GitHub -{ - -/** - * @brief common interface for all api backends. Deprecated, use @ref cpp_restapi::GitHub::ConnectionBuilder instead - */ -class [[deprecated("Use GitHubConnectionBuilder")]] IApi -{ -public: - virtual ~IApi() = default; - - /** - * @brief open authorized connection with GitHub api - * @param token GitHub's authentication token. One can be generated on https://github.com/settings/tokens - * @return \ref cpp_restapi::IConnection object which can be used with \ref cpp_restapi::GitHub::Request - */ - virtual std::unique_ptr connect(const std::string& token) = 0; - - /** - * @return GitHub api address - */ - virtual const std::string& address() const = 0; -}; - -} - -#endif diff --git a/include/github_api/github_api_curl.hpp b/include/github_api/github_api_curl.hpp deleted file mode 100644 index bfa81be..0000000 --- a/include/github_api/github_api_curl.hpp +++ /dev/null @@ -1,5 +0,0 @@ - -#warning This file is deprecated. Please include instead -#include - -namespace GitHub = cpp_restapi::GitHub; diff --git a/include/github_api/github_api_qt.hpp b/include/github_api/github_api_qt.hpp deleted file mode 100644 index f9c101f..0000000 --- a/include/github_api/github_api_qt.hpp +++ /dev/null @@ -1,5 +0,0 @@ - -#warning This file is deprecated. Please include instead -#include - -namespace GitHub = cpp_restapi::GitHub; diff --git a/include/github_api/request.hpp b/include/github_api/request.hpp deleted file mode 100644 index b3520a4..0000000 --- a/include/github_api/request.hpp +++ /dev/null @@ -1,3 +0,0 @@ - -#warning This file is deprecated. Please include instead -#include diff --git a/src/curl_backend/CMakeLists.txt b/src/curl_backend/CMakeLists.txt index 6cd1bb6..5bca0d1 100644 --- a/src/curl_backend/CMakeLists.txt +++ b/src/curl_backend/CMakeLists.txt @@ -3,9 +3,7 @@ find_package(CURL REQUIRED) target_sources(cpp_restapi PRIVATE - ${PROJECT_SOURCE_DIR}/include/github_api/github_api_curl.hpp connection.cpp - github_api.cpp ) target_link_libraries(cpp_restapi diff --git a/src/curl_backend/github_api.cpp b/src/curl_backend/github_api.cpp deleted file mode 100644 index c45b48f..0000000 --- a/src/curl_backend/github_api.cpp +++ /dev/null @@ -1,34 +0,0 @@ - -#include - -#include -#include - - -namespace cpp_restapi::GitHub::CurlBackend -{ - -Api::Api(const std::string& addr) - : cpp_restapi::GitHubBase(addr) -{ - curl_global_init(CURL_GLOBAL_DEFAULT); -} - - -Api::~Api() -{ - curl_global_cleanup(); -} - - -std::unique_ptr Api::connect(const std::string& token) -{ - std::map headerEntries; - - if (token.empty() == false) - headerEntries.emplace("Authorization", "token " + token); - - return std::make_unique(address(), headerEntries); -} - -} diff --git a/src/qt_backend/CMakeLists.txt b/src/qt_backend/CMakeLists.txt index 225307d..5f9a4f6 100644 --- a/src/qt_backend/CMakeLists.txt +++ b/src/qt_backend/CMakeLists.txt @@ -1,10 +1,4 @@ -# For compatibility. TODO: remove -if(GitHubAPI_UseQt6) - set(CppRestAPI_UseQt6 ${GitHubAPI_UseQt6}) - message(WARNING "GitHubAPI_UseQt6 is deprecated, please use CppRestAPI_UseQt6") -endif() - if(CppRestAPI_UseQt6) find_package(Qt6 REQUIRED COMPONENTS Core Network) else() @@ -12,9 +6,7 @@ else() endif() target_sources(cpp_restapi PRIVATE - ${PROJECT_SOURCE_DIR}/include/github_api/github_api_qt.hpp connection.cpp - github_api.cpp ) target_link_libraries(cpp_restapi diff --git a/src/qt_backend/github_api.cpp b/src/qt_backend/github_api.cpp deleted file mode 100644 index 1fd6002..0000000 --- a/src/qt_backend/github_api.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include -#include - - -namespace cpp_restapi::GitHub::QtBackend -{ - -Api::Api(QNetworkAccessManager& manager, const QString& addr) - : cpp_restapi::GitHubBase(addr.toStdString()) - , m_manager(manager) -{ - -} - - -std::unique_ptr Api::connect(const std::string& token) -{ - std::map headerEntries; - - if (token.empty() == false) - headerEntries.emplace("Authorization", "token " + token); - - return std::make_unique(m_manager, address(), headerEntries); -} - -} diff --git a/src/services/github/github_api_base.cpp b/src/services/github/github_api_base.cpp deleted file mode 100644 index 3f80044..0000000 --- a/src/services/github/github_api_base.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include "cpp_restapi/github/github_api_base.hpp" - - -namespace cpp_restapi -{ - - GitHubBase::GitHubBase(const std::string& address) - : m_address(address) - { - - } - - const std::string& GitHubBase::address() const - { - return m_address; - } -} diff --git a/tests/api_tests.cpp b/tests/api_tests.cpp index fa22f87..e94825d 100644 --- a/tests/api_tests.cpp +++ b/tests/api_tests.cpp @@ -6,8 +6,6 @@ #include "cpp_restapi/curl_connection.hpp" #include "cpp_restapi/qt_connection.hpp" -#include "cpp_restapi/github/github_api_curl.hpp" -#include "cpp_restapi/github/github_api_qt.hpp" #include "cpp_restapi/github/connection_builder.hpp" #include "cpp_restapi/github/request.hpp" @@ -24,33 +22,17 @@ namespace { constexpr int port = 9010; - template - T buildApi(); - template std::shared_ptr buildNewApi(); template<> - GitHub::CurlBackend::Api buildApi() - { - return GitHub::CurlBackend::Api(std::string("http://localhost:") + std::to_string(port)); - } - - template<> - GitHub::QtBackend::Api buildApi() - { - static QNetworkAccessManager networkmanager; - return GitHub::QtBackend::Api(networkmanager, QString("http://localhost:%1").arg(port)); - } - - template<> - std::shared_ptr buildNewApi() + std::shared_ptr buildNewApi() { return GitHub::ConnectionBuilder().setAddress(std::string("http://localhost:") + std::to_string(port)).build(); } template<> - std::shared_ptrbuildNewApi() + std::shared_ptrbuildNewApi() { static QNetworkAccessManager networkmanager; return GitHub::ConnectionBuilder().setAddress(std::string("http://localhost:") + std::to_string(port)).build(networkmanager); @@ -71,22 +53,8 @@ class ApiTest: public testing::Test NiceMock server; }; -template -struct BackendTraits; - -template<> -struct BackendTraits -{ - using Connection = CurlBackend::Connection; -}; - -template<> -struct BackendTraits -{ - using Connection = QtBackend::Connection; -}; -using Backends = testing::Types; +using Backends = testing::Types; TYPED_TEST_SUITE(ApiTest, Backends); @@ -95,25 +63,9 @@ TYPED_TEST(ApiTest, fetchRegularUser) GithubServerMock::Response response(200, R"({"login":"userName1234","id":1234"})"); ON_CALL(this->server, responseHandler).WillByDefault(Return(response)); - auto api = buildApi(); - auto connection = api.connect(); - - GitHub::Request request(std::move(connection)); - const auto info = request.getUserInfo("userName1234"); - - EXPECT_EQ(info, "{\"id\":1234,\"login\":\"userName1234\"}\n"); -} - - -TYPED_TEST(ApiTest, newInterface) -{ - GithubServerMock::Response response(200, R"({"login":"userName1234","id":1234"})"); - ON_CALL(this->server, responseHandler).WillByDefault(Return(response)); - - using Connection = typename BackendTraits::Connection; auto connection = buildNewApi(); - GitHub::Request request(connection); + GitHub::Request request(std::move(connection)); const auto info = request.getUserInfo("userName1234"); EXPECT_EQ(info, "{\"id\":1234,\"login\":\"userName1234\"}\n"); @@ -122,15 +74,14 @@ TYPED_TEST(ApiTest, newInterface) TYPED_TEST(ApiTest, pagination) { - auto api = buildApi(); - auto connection = api.connect(); + auto connection = buildNewApi(); GithubServerMock::Response response1(200, R"({"login":"userName1234","id":1234})"); - const std::string secondPage = api.address() + "/url/to/second/page&page=2"; + const std::string secondPage = connection->url() + "/url/to/second/page&page=2"; response1.addHeader( {"link", "<" + secondPage + ">; rel=\"next\""} ); GithubServerMock::Response response2(200, R"({"someotherfield":"value"})"); - const std::string thirdPage = api.address() + "/url/to/last/page&page=3"; + const std::string thirdPage = connection->url() + "/url/to/last/page&page=3"; response2.addHeader( {"Link", "; rel=\"prev\", <" + thirdPage + ">; rel=\"next\""} ); GithubServerMock::Response response3(200, R"({"more_fields":"value234"})"); @@ -148,15 +99,14 @@ TYPED_TEST(ApiTest, pagination) TYPED_TEST(ApiTest, arraysPagination) { - auto api = buildApi(); - auto connection = api.connect(); + auto connection = buildNewApi(); GithubServerMock::Response response1(200, R"([{"login":"userName1234","id":1234}])"); - const std::string secondPage = api.address() + "/url/to/second/page&page=2"; + const std::string secondPage = connection->url() + "/url/to/second/page&page=2"; response1.addHeader( {"Link", "<" + secondPage + ">; rel=\"next\""} ); GithubServerMock::Response response2(200, R"([{"someotherfield":"value"}])"); - const std::string thirdPage = api.address() + "/url/to/last/page&page=3"; + const std::string thirdPage = connection->url() + "/url/to/last/page&page=3"; response2.addHeader( {"link", "<" + thirdPage + ">; rel=\"next\""} ); GithubServerMock::Response response3(200, R"([{"more_fields":"value234"}])");