From 7e5986a4bf42143e5657e8f3d0f9d3902324b8e5 Mon Sep 17 00:00:00 2001 From: qucals Date: Fri, 20 Aug 2021 00:32:32 +0500 Subject: [PATCH 1/5] Added new workflow - Changed defines names - The utilities code was moved to .cpp --- .../workflows/{cmake_github.yml => macos.yml} | 5 +- .github/workflows/ubuntu.yml | 50 ++++++ CMakeLists.txt | 8 +- README.md | 4 +- examples/1/CMakeLists.txt | 5 +- examples/2/CMakeLists.txt | 5 +- include/BotBase.hpp | 124 +++++++++------ include/ClientBase.hpp | 91 +++++++---- include/Config.hpp.in | 6 +- include/Defines.hpp | 114 ++++++++------ include/Exceptions.hpp | 26 ++-- include/Request.hpp | 28 ++-- include/UserBase.hpp | 83 ++++++---- include/Utilities.hpp | 42 +++--- src/BotBase.cpp | 62 ++++---- src/ClientBase.cpp | 12 +- src/Request.cpp | 2 + src/UserBase.cpp | 44 +++--- src/Utilities.cpp | 142 ++++++++++++++++++ 19 files changed, 580 insertions(+), 273 deletions(-) rename .github/workflows/{cmake_github.yml => macos.yml} (96%) create mode 100644 .github/workflows/ubuntu.yml create mode 100644 src/Utilities.cpp diff --git a/.github/workflows/cmake_github.yml b/.github/workflows/macos.yml similarity index 96% rename from .github/workflows/cmake_github.yml rename to .github/workflows/macos.yml index cfd2993..a1a986b 100644 --- a/.github/workflows/cmake_github.yml +++ b/.github/workflows/macos.yml @@ -1,4 +1,4 @@ -name: CMake +name: MacOS on: push: @@ -24,6 +24,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install deps + run: brew install curl + - name: Configure VKAPI Library CMake run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..0f74baf --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,50 @@ +name: Ubuntu + +on: + push: + branches: + - master + - develop + pull_request: + branches: [ master ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + name: deploy to staging + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install deps + run: sudo apt update && sudo apt upgrade && sudo apt install curl && sudo apt-get install libcurl4-openssl-dev + + - name: Configure VKAPI Library CMake + run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build VKAPI Library + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Install VKAPI Library + run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + + # Configure, Build and Install WE - With Examples + - name: Configure VKAPI Library CMake WE + run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build VKAPI Library WE + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Install VKAPI Library WE + run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} + diff --git a/CMakeLists.txt b/CMakeLists.txt index ed98f3b..9a7b606 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,10 @@ file(GLOB TARGET_HEADERS "./include/*.hpp") if(BUILD_LIBRARY) add_library(${PROJECT_NAME} STATIC ${TARGET_SRC} ${TARGET_HEADERS}) else() - set(CMAKE_CXX_FLAGS " -lcurl") + if(UNIX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lcurl") add_executable(${PROJECT_NAME} ${TARGET_SRC} ${TARGET_HEADERS}) endif() @@ -39,10 +42,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_INSTALL_INCLUDEDIR}) # Include json target_link_directories(${PROJECT_NAME} PUBLIC ${NLOHMANN_JSON_PATH}) -add_definitions(-DCURL_STATICLIB) - find_package(CURL REQUIRED) target_link_directories(${PROJECT_NAME} PUBLIC ${CURL_INCLUDE_DIR}) +target_link_libraries(${PROJECT_NAME} PUBLIC curl) set_target_properties( ${PROJECT_NAME} PROPERTIES diff --git a/README.md b/README.md index af354e0..5594fe1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@
[![Status](https://img.shields.io/badge/status-active-success.svg)]() -![Workflow](https://github.com/qucals/VK-API/actions/workflows/cmake_github.yml/badge.svg) +[![CodeFactor](https://www.codefactor.io/repository/github/qucals/VK-API/badge/master)](https://www.codefactor.io/repository/github/qucals/VK-API/overview/master) +[![Workflow](https://github.com/qucals/VK-API/actions/workflows/macos.yml/badge.svg)]() +[![Workflow](https://github.com/qucals/VK-API/actions/workflows/ubuntu.yml/badge.svg)]() [![GitHub Issues](https://img.shields.io/github/issues/qucals/VK-API.svg)](https://github.com/qucals/VK-API/issues) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr/qucals/VK-API.svg)](https://github.com/qucals/VK-API/pulls) [![License](https://img.shields.io/github/license/qucals/VK-API)](/LICENSE) diff --git a/examples/1/CMakeLists.txt b/examples/1/CMakeLists.txt index 9735e75..9a6adb1 100644 --- a/examples/1/CMakeLists.txt +++ b/examples/1/CMakeLists.txt @@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.5) set(PROJECT_NAME Example1) project(${PROJECT_NAME} LANGUAGES CXX) -set(CMAKE_CXX_FLAGS "-lcurl") +if(UNIX) + set(CMAKE_CXX_FLAGS "-L/usr/local/lib/ -L/usr/lib/ ${CMAKE_CXX_FLAGS} -pthread") +endif() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lcurl") set(VKAPI_DIR ../../lib/cmake) find_package(VKAPI CONFIG REQUIRED) diff --git a/examples/2/CMakeLists.txt b/examples/2/CMakeLists.txt index 74a6620..d409b32 100644 --- a/examples/2/CMakeLists.txt +++ b/examples/2/CMakeLists.txt @@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.5) set(PROJECT_NAME Example2) project(${PROJECT_NAME} LANGUAGES CXX) -set(CMAKE_CXX_FLAGS "-lcurl") +if(UNIX) + set(CMAKE_CXX_FLAGS "-L/usr/local/lib/ -L/usr/lib/ ${CMAKE_CXX_FLAGS} -pthread") +endif() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lcurl") set(VKAPI_DIR ../../lib/cmake) find_package(VKAPI CONFIG REQUIRED) diff --git a/include/BotBase.hpp b/include/BotBase.hpp index b1314d5..761c466 100644 --- a/include/BotBase.hpp +++ b/include/BotBase.hpp @@ -2,13 +2,13 @@ * Contains the class for working with vkbot. * @file BotBase.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #pragma once -#ifndef _BOTBASE_HPP_ -#define _BOTBASE_HPP_ +#ifndef VKAPI_BOTBASE_HPP +#define VKAPI_BOTBASE_HPP #include @@ -118,79 +118,93 @@ class BotBase : public ClientBase struct Event { - json parameters; + JsonType parameters; EVENTS type; - Event(const EVENTS _type, json _parameters) - : parameters(__MOVE(_parameters)) + Event(const EVENTS _type, JsonType _parameters) + : parameters(_VKAPI_MOVE(_parameters)) , type(_type) {} }; public: /** - * @param groupId: the id of the bot's group. - * @param timeWait: + * @param groupId: the id of the bot's group. + * + * @param timeWait: * The time of waiting for any event. - * In the default timeWait equals DEFAULT_TIME_WAIT ("25"). + * Default: DEFAULT_TIME_WAIT ("25"). */ - __EXPLICIT BotBase(std::string groupId, std::string timeWait = DEFAULT_TIME_WAIT); + _VKAPI_EXPLICIT BotBase(std::string groupId, std::string timeWait = DEFAULT_TIME_WAIT); ~BotBase() = default; /** - * @brief The authorization function by the access token - * @param accessToken: the access token + * @brief The authorization function by the access token. + * + * @param accessToken: the access token. + * * @retval 'true' if authorization is successfully and 'false' in another case. */ - bool Auth(const std::string& accessToken) __FINAL; + bool Auth(const std::string& accessToken) _VKAPI_FINAL; /** - * @brief The function of waiting for any event after authorization. + * @brief The function of waiting for any event after authorization. + * * @retval If the event has happened the function returns the description about it. */ Event WaitForEvent(); /** - * @brief The function of converting an enum's method to a string (URL). - * @param method: the enum's method. + * @brief The function of converting an enum's method to a string (URL). + * + * @param method: the enum's method. + * * @retval a string (URL) of this method. */ - __STATIC std::string MethodToString(METHODS method); + _VKAPI_STATIC std::string MethodToString(METHODS method); /** - * @brief The function of sending any request to the VK server. - * @param method: the enum's method. - * @param parametersData: the data of parameters for your request. - * @retval the answer of your request in json. + * @brief The function of sending any request to the VK server. + * + * @param method: the enum's method. + * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - json SendRequest(METHODS method, const json& parametersData); + JsonType SendRequest(METHODS method, const JsonType& parametersData); /** - * @brief The function of sending any request to the VK server. - * @param method: your method in str format. - * @param parametersData: the data of parameters for your request. - * @retval the answer of your request in json. + * @brief The function of sending any request to the VK server. + * + * @param method: your method in str format. + * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - json SendRequest(const std::string& method, const json& parametersData); + JsonType SendRequest(const std::string& method, const JsonType& parametersData) _VKAPI_OVERRIDE; #ifdef __CPLUSPLUS_OVER_11 /** - * @brief The function witch calls private function for sending a request in asynchronous mode. - * @param method: the enum's method. - * @param parametersData: the data of parameters for your request. - * @retval the answer of your request in json. + * @brief The function witch calls private function for sending a request in asynchronous mode. + * + * @param method: the enum's method. + * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - auto SendRequestAsync(METHODS method, const json& parametersData); + auto SendRequestAsync(METHODS method, const JsonType& parametersData); /** - * @brief The function witch calls private function for sending a request in asynchronous mode. - * @param method: your method in str format. - * @param parametersData: the data of parameters for your request. - * @retval the answer of your request in json. + * @brief The function witch calls private function for sending a request in asynchronous mode. + * + * @param method: your method in str format. + * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - auto SendRequestAsync(const std::string& method, const json& parametersData); + auto SendRequestAsync(const std::string& method, const JsonType& parametersData); #endif // __CPLUSPLUS_OVER_11 @@ -199,36 +213,48 @@ class BotBase : public ClientBase * @brief * Checking the data of parameters on validation. * If the following items won't be found the function will add it. - * @param parametersData: the data for checking validation. - * @retval the correctly data of parameters in json. + * + * @param parametersData: the data for checking validation. + * + * @retval the correctly data of parameters in JsonType. */ - json CheckValidationParameters(const json& parametersData) __OVERRIDE; + JsonType CheckValidationParameters(const JsonType& parametersData) _VKAPI_OVERRIDE; /** - * @brief Get the type of events by string. - * @param typeEvent: the event in str. + * @brief Get the type of events by string. + * + * @param typeEvent: the event in str. + * * @retval the type of event in enum (EVENTS). */ - __STATIC EVENTS GetTypeEvent(const std::string& typeEvent); + _VKAPI_STATIC EVENTS GetTypeEvent(const std::string& typeEvent); private: #ifdef __CPLUSPLUS_OVER_11 /** * @brief The static function of sending any request to the VK server. - * @param handle: a pointer to your handle of BotBase. + * + * @param botHandle: a pointer to your handle of BotBase. * @param method: the enum's method. * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - __STATIC json SendRequestAsync_(BotBase* handle, METHODS method, const json& parametersData); + _VKAPI_STATIC JsonType + SendRequestAsyncByMethod_(BotBase* botHandle, METHODS method, const JsonType& parametersData); /** * @brief The static function of sending any request to the VK server. - * @param handle: a pointer to your handle of BotBase. + * + * @param botHandle: a pointer to your handle of BotBase. * @param method: your method in str format. * @param parametersData: the data of parameters for your request. + * + * @retval the answer of your request in JsonType. */ - __STATIC json SendRequestAsync__(BotBase* handle, const std::string& method, const json& parametersData); + _VKAPI_STATIC JsonType + SendRequestAsyncByStr_(BotBase* botHandle, const std::string& method, const JsonType& parametersData); #endif // #ifdef __CPLUSPLUS_OVER_11 @@ -236,7 +262,7 @@ class BotBase : public ClientBase const std::string m_groupId; std::string m_accessToken; - json m_previousEvent; + JsonType m_previousEvent; std::string m_secretKey; std::string m_serverUrl; @@ -251,4 +277,4 @@ class BotBase : public ClientBase } // namespace vk -#endif // _BOTBASE_HPP_ \ No newline at end of file +#endif // VKAPI_BOTBASE_HPP diff --git a/include/ClientBase.hpp b/include/ClientBase.hpp index 7ebb7eb..35702ad 100644 --- a/include/ClientBase.hpp +++ b/include/ClientBase.hpp @@ -2,18 +2,27 @@ * Contains general objects for working with VK API. * @file ClientBase.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ + #pragma once -#ifndef _CLIENTBASE_HPP_ -#define _CLIENTBASE_HPP_ +#ifndef VKAPI_CLIENTBASE_HPP +#define VKAPI_CLIENTBASE_HPP + +#include #include // Request #include // ConvertStrToUrlCode #include // already_connected, not_connected, empty_argument #include +#ifdef __VKAPI_VERSION_ADDED_OPTIONAL +#if __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL +#include +#endif // __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL +#endif // __VKAPI_VERSION_ADDED_OPTIONAL + #include // cout, endl #include // rand #include // set @@ -23,16 +32,22 @@ #include // async, future #endif // __CPLUSPLUS_OVER_11 -#include // json +#include // nlohmann::json namespace vk { -using json = nlohmann::json; - namespace base { +#ifdef __VKAPI_VERSION_ADDED_OPTIONAL +#if __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL +typedef nlohmann::json JsonType; +#endif // __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL +#else +typedef nlohmann::json JsonType; +#endif // __VKAPI_VERSION_ADDED_OPTIONAL + #define VKAPI_INVALID_REQUEST "invalid_request" #define VKAPI_NEED_CAPTCHA "need_captcha" @@ -97,71 +112,93 @@ class ClientBase ClientBase(); /** - * @brief The function of authorization by access token. + * @brief The function of authorization by access token. + * * @note * ClientBase hasn't the own realization of auth's function because of * implementation for user and bot auths is differently. - * @param accessToken: the access token + * + * @param accessToken: the access token */ - __VIRTUAL bool Auth(const std::string& accessToken) = 0; + _VKAPI_VIRTUAL bool Auth(const std::string& accessToken) = 0; /** - * @brief Add a scope to the main scope's list. - * @param scope: your scope. + * @brief Add a scope to the main scope's list. + * + * @param scope: your scope. */ - __VIRTUAL void AddScope(std::string scope); + _VKAPI_VIRTUAL void AddScope(std::string scope); /** - * @brief Add a list of scopes to the main scope's list. - * @param scopeList: your list of scopes. + * @brief Add a list of scopes to the main scope's list. + * + * @param scopeList: your list of scopes. */ - __VIRTUAL void AddScope(std::initializer_list scopeList); + _VKAPI_VIRTUAL void AddScope(std::initializer_list scopeList); /** - * @brief Clear the main scope's list. + * @brief Clear the main scope's list. */ - __VIRTUAL void ClearScope(); + _VKAPI_VIRTUAL void ClearScope(); /** - * @brief Generate a 32 bits random number. + * @brief Generate a 32 bits random number. + * * @note For example, it is used in the messaging request to the VK server. + * * @retval a 32 bits random number. */ - __STATIC uint32_t GetRandomId(); + _VKAPI_STATIC uint32_t GetRandomId(); /** - * @brief Says about the connection. + * @brief Indicates that you are connected to long poll. * - * @return true - * @return false + * @return the connection indicator. */ - __VIRTUAL bool IsAuthorized() const + _VKAPI_VIRTUAL bool IsAuthorized() const { return m_connectedToLongPoll; } + /** + * @brief The function sends any request to the VK serve. + * + * @param method: the method in str format. + * @param parametersData: the data of parameters for the request. + * + * @retval the answer of the request in JsonType format. + */ + _VKAPI_VIRTUAL JsonType SendRequest(const std::string& method, const JsonType& parametersData) = 0; + ClientBase& operator=(const ClientBase&) = delete; protected: /** * @brief Convert parameters data to URL format. + * * @param parametersData: your parameters data which need to convert to URL format. + * * @retval a string with parameters in URL format. */ - __VIRTUAL std::string ConvertParametersDataToURL(const json& parametersData); + _VKAPI_VIRTUAL std::string ConvertParametersDataToURL(const JsonType& parametersData); /** * @brief Check validation parameters on having items like access_token and others. + * * @note If the data of parameters won't have necessary parameters the function will add it. + * * @param parametersData: the data of parameters that you want to check. + * * @retval the correctly data of parameters. */ - __VIRTUAL json CheckValidationParameters(const json& parametersData) = 0; + _VKAPI_VIRTUAL JsonType CheckValidationParameters(const JsonType& parametersData) = 0; /** * @brief Get the error type by a string. + * * @param errorStr: the error in string format. + * * @retval the type of the error in enum format (VK_REQUEST_ERROR_TYPES). */ - __STATIC VK_REQUEST_ERROR_TYPES GetRequestErrorType(const std::string& errorStr); + _VKAPI_STATIC VK_REQUEST_ERROR_TYPES GetRequestErrorType(const std::string& errorStr); protected: std::set m_scope; @@ -173,4 +210,4 @@ class ClientBase } // namespace vk -#endif // _CLIENTBASE_HPP_ \ No newline at end of file +#endif // VKAPI_CLIENTBASE_HPP diff --git a/include/Config.hpp.in b/include/Config.hpp.in index 01ec5ea..3fecc89 100644 --- a/include/Config.hpp.in +++ b/include/Config.hpp.in @@ -7,8 +7,8 @@ #pragma once -#ifndef _CONFIG_HPP_IN_ -#define _CONFIG_HPP_IN_ +#ifndef VKAPI_CONFIG_HPP_IN +#define VKAPI_CONFIG_HPP_IN namespace vk { @@ -89,4 +89,4 @@ typedef struct __vkapi_version } // namespace vk -#endif // _CONFIG_HPP_IN_ \ No newline at end of file +#endif // VKAPI_CONFIG_HPP_IN diff --git a/include/Defines.hpp b/include/Defines.hpp index 0adcd9e..841ecf4 100644 --- a/include/Defines.hpp +++ b/include/Defines.hpp @@ -2,78 +2,90 @@ * Contains general defines about the language. * @file Defines.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 20/08/21 */ #pragma once -#ifndef VKAPI_DEFINES_H -#define VKAPI_DEFINES_H +#ifndef VKAPI_DEFINES_HPP +#define VKAPI_DEFINES_HPP -#ifndef __NO_TESTED -#define __NO_TESTED -#endif // __NO_TESTED +#include -#ifndef __NO_IMPL -#define __NO_IMPL -#endif // __NO_IMPL +#ifndef _VKAPI_NO_IMPL +#define _VKAPI_NO_IMPL +#endif // _VKAPI_NO_IMPL -#ifndef __STATIC -#define __STATIC static -#endif // __STATIC +#ifndef _VKAPI_STATIC +#define _VKAPI_STATIC static +#endif // _VKAPI_STATIC #if (__cplusplus >= 201103L) #define __CPLUSPLUS_OVER_11 +#endif // (__cplusplus >= 201103L) -#ifndef __OVERRIDE -#define __OVERRIDE override -#endif // __OVERRIDE +#if (__cplusplus >= 201402L) +#define __CPLUSPLUS_OVER_14 +#endif // ((__cplusplus >= 201402L)) -#ifndef __FINAL -#define __FINAL final -#endif // __FINAL +#if (__cplusplus >= 201703L) +#define __CPLUSPLUS_OVER_17 +#endif // (__cplusplus >= 201703L) -#ifndef __NOEXCEPT -#define __NOEXCEPT noexcept -#endif // __NOEXCEPT +#if (__cplusplus >= 202002L) +#define __CPLUSPLUS_OVER_20 +#endif // (__cplusplus >= 202002L) -#ifndef __EXPLICIT -#define __EXPLICIT explicit -#endif // __EXPLICIT +#ifdef __CPLUSPLUS_OVER_11 +#ifndef _VKAPI_OVERRIDE +#define _VKAPI_OVERRIDE override +#endif // _VKAPI_OVERRIDE -#ifndef __MOVE +#ifndef _VKAPI_FINAL +#define _VKAPI_FINAL final +#endif // _VKAPI_FINAL + +#ifndef _VKAPI_NOEXCEPT +#define _VKAPI_NOEXCEPT noexcept +#endif // _VKAPI_NOEXCEPT + +#ifndef _VKAPI_EXPLICIT +#define _VKAPI_EXPLICIT explicit +#endif // _VKAPI_EXPLICIT + +#ifndef _VKAPI_MOVE #include -#define __MOVE(x) std::move(x) -#endif // __MOVE(x) +#define _VKAPI_MOVE(x) std::move(x) +#endif // _VKAPI_MOVE(x) #else -#ifndef __OVERRIDE -#define __OVERRIDE -#endif // __OVERRIDE +#ifndef _VKAPI_OVERRIDE +#define _VKAPI_OVERRIDE +#endif // _VKAPI_OVERRIDE -#ifndef __FINAL -#define __FINAL -#endif // __FINAL +#ifndef _VKAPI_FINAL +#define _VKAPI_FINAL +#endif // _VKAPI_FINAL -#ifndef __NOEXCEPT -#define __NOEXCEPT -#endif // __NOEXCEPT +#ifndef _VKAPI_NOEXCEPT +#define _VKAPI_NOEXCEPT +#endif // _VKAPI_NOEXCEPT -#ifndef __EXPLICIT -#define __EXPLICIT -#endif // __EXPLICIT +#ifndef _VKAPI_EXPLICIT +#define _VKAPI_EXPLICIT +#endif // _VKAPI_EXPLICIT -#ifndef __MOVE -#define __MOVE(x) x -#endif // __MOVE +#ifndef _VKAPI_MOVE +#define _VKAPI_MOVE(x) x +#endif // _VKAPI_MOVE #endif -#ifndef __VIRTUAL -#define __VIRTUAL virtual -#endif // __VIRTUAL +#ifndef _VKAPI_VIRTUAL +#define _VKAPI_VIRTUAL virtual +#endif // _VKAPI_VIRTUAL -#ifndef __INLINE -#define __INLINE inline -#endif // __INLINE +#ifndef _VKAPI_INLINE +#define _VKAPI_INLINE inline +#endif // _VKAPI_INLINE #if defined(_MSC_VER) #define __DISABLE_WARNING_PUSH __pragma(warning( push )) @@ -90,4 +102,8 @@ #define __DISABLE_WARNING #endif -#endif //VKAPI_DEFINES_H \ No newline at end of file +#ifndef __VKAPI_VERSION_ADDED_OPTIONAL +#define __VKAPI_VERSION_ADDED_OPTIONAL __VKAPI_VERSION_NUM(0, 0, 7) +#endif // __VKAPI_VERSION_ADDED_OPTIONAL + +#endif //VKAPI_DEFINES_HPP diff --git a/include/Exceptions.hpp b/include/Exceptions.hpp index 0a79189..8077cbc 100644 --- a/include/Exceptions.hpp +++ b/include/Exceptions.hpp @@ -2,13 +2,13 @@ * Contains exceptions and information about them of this library. * @file Exceptions.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #pragma once -#ifndef _EXCEPTIONS_HPP_ -#define _EXCEPTIONS_HPP_ +#ifndef VKAPI_EXCEPTIONS_HPP +#define VKAPI_EXCEPTIONS_HPP #include @@ -20,25 +20,25 @@ namespace vk namespace ex { -class BaseException : __VIRTUAL public std::exception +class BaseException : _VKAPI_VIRTUAL public std::exception { protected: std::string m_errorMessage; public: - __EXPLICIT BaseException(std::string msg) - : m_errorMessage(__MOVE(msg)) + _VKAPI_EXPLICIT BaseException(std::string msg) + : m_errorMessage(_VKAPI_MOVE(msg)) {} - ~BaseException() __NOEXCEPT __OVERRIDE = default; + ~BaseException() _VKAPI_NOEXCEPT _VKAPI_OVERRIDE = default; - const char* what() const __NOEXCEPT __OVERRIDE + const char* what() const _VKAPI_NOEXCEPT _VKAPI_OVERRIDE { return m_errorMessage.c_str(); } }; -class AlreadyConnectedException : __VIRTUAL public BaseException +class AlreadyConnectedException : _VKAPI_VIRTUAL public BaseException { public: explicit AlreadyConnectedException() @@ -46,7 +46,7 @@ class AlreadyConnectedException : __VIRTUAL public BaseException {} }; -class NotConnectedException : __VIRTUAL public BaseException +class NotConnectedException : _VKAPI_VIRTUAL public BaseException { public: explicit NotConnectedException() @@ -54,7 +54,7 @@ class NotConnectedException : __VIRTUAL public BaseException {} }; -class EmptyArgumentException : __VIRTUAL public BaseException +class EmptyArgumentException : _VKAPI_VIRTUAL public BaseException { public: explicit EmptyArgumentException() @@ -62,7 +62,7 @@ class EmptyArgumentException : __VIRTUAL public BaseException {} }; -class RequestError : __VIRTUAL public BaseException +class RequestError : _VKAPI_VIRTUAL public BaseException { public: explicit RequestError() @@ -74,4 +74,4 @@ class RequestError : __VIRTUAL public BaseException } // namespace vk -#endif // _EXCEPTIONS_HPP_ \ No newline at end of file +#endif // VKAPI_EXCEPTIONS_HPP diff --git a/include/Request.hpp b/include/Request.hpp index 3d642e1..3ca9a32 100644 --- a/include/Request.hpp +++ b/include/Request.hpp @@ -2,20 +2,20 @@ * Describes the class for working with CURL. * @file Request.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #pragma once -#ifndef _REQUEST_HPP_ -#define _REQUEST_HPP_ - -#include // curl -#include // string +#ifndef VKAPI_REQUEST_HPP +#define VKAPI_REQUEST_HPP #include #include // ConvertStrToUrlCode +#include // curl +#include // string + namespace vk { @@ -40,20 +40,22 @@ class Request /** * @brief Sending your request to the VK server. - * @param url: the request in url format. - * @param postData: the additional parameters which need to add to the request. + * + * @param url: the request in url format. + * @param postData: the additional parameters which need to add to the request. + * * @retval an answer in a string. */ - __STATIC std::string Send(const std::string& url, - const std::string& postData); + _VKAPI_STATIC std::string Send(const std::string& url, + const std::string& postData); protected: - __STATIC std::size_t CurlWriteData(char* ptr, size_t size, - size_t nmemb, std::string* data); + _VKAPI_STATIC std::size_t CurlWriteData(char* ptr, size_t size, + size_t nmemb, std::string* data); }; } // namespace base } // namespace vk -#endif // _REQUEST_HPP_ \ No newline at end of file +#endif // VKAPI_REQUEST_HPP diff --git a/include/UserBase.hpp b/include/UserBase.hpp index 66f6b07..a214afe 100644 --- a/include/UserBase.hpp +++ b/include/UserBase.hpp @@ -2,13 +2,13 @@ * Describes the class for working with VK account. * @file UserBase.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #pragma once -#ifndef _USERBASE_HPP_ -#define _USERBASE_HPP_ +#ifndef VKAPI_USERBASE_HPP +#define VKAPI_USERBASE_HPP #include @@ -21,7 +21,9 @@ namespace base namespace user { -// The class for working from users by Long Poll Server. +/** + * @brief The class for working from users by Long Poll Server. + */ class UserBase : public ClientBase { public: @@ -431,76 +433,93 @@ class UserBase : public ClientBase public: /** - * @param appId: the id of the application. - * @param appSecureKey: the secure key of the application. + * @param appId: the id of the application. + * @param appSecureKey: the secure key of the application. */ UserBase(std::string appId, std::string appSecureKey); ~UserBase() = default; /** - * @brief The authorization function by login and password. - * @param login: your login. - * @param password: your password. + * @brief The authorization function by login and password. + * + * @param login: your login. + * @param password: your password. + * * @retval 'true' if auth is successfully and 'false' in another case. */ - __VIRTUAL bool Auth(std::string& login, std::string& password); + _VKAPI_VIRTUAL bool Auth(std::string& login, std::string& password); /** - * @brief The authorization function by access token. - * @param accessToken: your access token. + * @brief The authorization function by access token. + * + * @param accessToken: your access token. + * * @retval 'true' if auth is successfully and 'false' in another case. */ - bool Auth(const std::string& accessToken) __FINAL; + bool Auth(const std::string& accessToken) _VKAPI_FINAL; /** - * @brief The function of sending any request to the VK server. - * @param method: the enum's method. - * @param parametersData: the data of parameters for the request. - * @retval the answer of the request in json format. + * @brief The function of sending any request to the VK server. + * + * @param method: the enum's method. + * @param parametersData: the data of parameters for the request. + * + * @retval the answer of the request in JsonType format. */ - json SendRequest(METHODS method, const json& parametersData); + JsonType SendRequest(METHODS method, const JsonType& parametersData); /** - * @brief The function sends any request to the VK serve. - * @param method: the method in str format. - * @param parametersData: the data of parameters for the request. - * @retval the answer of the request in json format. + * @brief The function sends any request to the VK serve. + * + * @param method: the method in str format. + * @param parametersData: the data of parameters for the request. + * + * @retval the answer of the request in JsonType format. */ - json SendRequest(const std::string& method, const json& parametersData); + JsonType SendRequest(const std::string& method, const JsonType& parametersData) _VKAPI_OVERRIDE; /** - * @brief The function of converting an enum's method to a string (URL). - * @param method: enum's method. + * @brief The function of converting an enum's method to a string (URL). + * + * @param method: enum's method. + * * @retval a string of this method in URL format. */ - __STATIC std::string MethodToString(METHODS method); + _VKAPI_STATIC std::string MethodToString(METHODS method); /** - * @brief Get the validation type for auth by its description in string format. - * @param descriptionType: the description of the type. + * @brief Get the validation type for auth by its description in string format. + * + * @param descriptionType: the description of the type. + * * @retval the validation type in enum format (VALIDATION_TYPES). */ - __STATIC VALIDATION_TYPES GetValidationType(const std::string& descriptionType); + _VKAPI_STATIC VALIDATION_TYPES GetValidationType(const std::string& descriptionType); UserBase& operator=(const UserBase&) = delete; protected: /** * @brief Checking validation parameters on having items like access_token and others. + * * @note If the data of parameters won't have the function will add it. + * * @param parametersData: the data of parameters that you want to check. + * * @retval the correctly data of parameters. */ - json CheckValidationParameters(const json& parametersData) __OVERRIDE; + JsonType CheckValidationParameters(const JsonType& parametersData) _VKAPI_OVERRIDE; /** * @brief Get the URL to the captcha. + * * @param parametersData: the parameters data which was sent in the previous request. * @param answerData: the answer which was received in the previous request. + * * @retval the URL to the captcha. */ - __STATIC std::string GetURLCaptcha(json& parametersData, const json& answerData); + _VKAPI_STATIC std::string GetURLCaptcha(JsonType& parametersData, const JsonType& answerData); private: const std::string m_appId; @@ -516,4 +535,4 @@ class UserBase : public ClientBase } // namespace vk -#endif // _USERBASE_HPP_ \ No newline at end of file +#endif // VKAPI_USERBASE_HPP diff --git a/include/Utilities.hpp b/include/Utilities.hpp index f42a05d..2cfea91 100644 --- a/include/Utilities.hpp +++ b/include/Utilities.hpp @@ -2,18 +2,22 @@ * Contains additional functions for working with the library. * @file Utilities.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #pragma once -#ifndef _UTILITIES_HPP_ -#define _UTILITIES_HPP_ +#ifndef VKAPI_UTILITIES_HPP +#define VKAPI_UTILITIES_HPP #include -#include // curl #include // string +#include // curl + +#ifndef __CPLUSPLUS_OVER_11 +#include +#endif // __CPLUSPLUS_OVER_11 namespace vk { @@ -21,24 +25,20 @@ namespace vk namespace utilities { -__INLINE std::string ConvertStrToUrlCode(const std::string& str) -{ - std::string temp(str); - CURL* curl = curl_easy_init(); - - if (curl) { - char* output = curl_easy_escape(curl, str.c_str(), static_cast(str.length())); +std::string ConvertStrToUrlCode(const std::string& str); - if (output) { - temp = output; - curl_free(output); - } - } - return temp; -} +std::string ToString(int val); +std::string ToString(unsigned val); +std::string ToString(long val); +std::string ToString(unsigned long val); +std::string ToString(long long val); +std::string ToString(unsigned long long val); +std::string ToString(float val); +std::string ToString(double val); +std::string ToString(long double val); -} +} // namespace utilities -} +} // namespace vk -#endif // _UTILITIES_HPP_ \ No newline at end of file +#endif // VKAPI_UTILITIES_HPP diff --git a/src/BotBase.cpp b/src/BotBase.cpp index 5de93ca..6317caa 100644 --- a/src/BotBase.cpp +++ b/src/BotBase.cpp @@ -2,7 +2,7 @@ * Contains the class for working with vkbot. * @file BotBase.cpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #include @@ -17,8 +17,8 @@ namespace bot { BotBase::BotBase(std::string groupId, std::string timeWait) - : m_groupId(__MOVE(groupId)) - , m_timeWait(__MOVE(timeWait)) + : m_groupId(_VKAPI_MOVE(groupId)) + , m_timeWait(_VKAPI_MOVE(timeWait)) {} bool BotBase::Auth(const std::string& accessToken) @@ -28,7 +28,7 @@ bool BotBase::Auth(const std::string& accessToken) if (m_accessToken != accessToken) { m_accessToken = accessToken; } - json parametersData = { + JsonType parametersData = { { "access_token", m_accessToken }, { "group_id", m_groupId }, { "v", VKAPI_API_VERSION } @@ -36,13 +36,13 @@ bool BotBase::Auth(const std::string& accessToken) const std::string method = MethodToString(METHODS::GET_LONG_POLL_SERVER); const std::string url = VKAPI_API_URL + method; - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); if (response.find("error") != response.end()) { throw ex::RequestError(); // TODO (#12): Add error handling when BotBase::Auth failed } else { - json answerDataStr = response["response"]; + JsonType answerDataStr = response["response"]; m_secretKey = answerDataStr["key"].get(); m_serverUrl = answerDataStr["server"].get(); @@ -58,20 +58,20 @@ BotBase::Event BotBase::WaitForEvent() { if (!IsAuthorized()) { throw ex::NotConnectedException(); } - json parametersData = { + JsonType parametersData = { { "key", m_secretKey }, { "ts", m_timeStamp }, { "wait", m_timeWait } }; std::string url = m_serverUrl + "?act=a_check&"; - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); if (response.find("ts") != response.end()) { m_timeStamp = response.at("ts").get(); } - json updates = response.at("updates")[0]; + JsonType updates = response.at("updates")[0]; std::string eventStr = updates.at("type").get(); return Event(GetTypeEvent(eventStr), updates); @@ -163,73 +163,73 @@ std::string BotBase::MethodToString(const METHODS method) return ""; } -json BotBase::SendRequest(const METHODS method, const json& parametersData) +JsonType BotBase::SendRequest(METHODS method, const JsonType& parametersData) { if (!IsAuthorized()) { throw ex::NotConnectedException(); } std::string methodStr = MethodToString(method); std::string url = VKAPI_API_URL + methodStr; - json pData = CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(pData))); + JsonType pData = CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(pData))); return response; } -json BotBase::SendRequest(const std::string& method, const json& parametersData) +JsonType BotBase::SendRequest(const std::string& method, const JsonType& parametersData) { if (!IsAuthorized()) { throw ex::NotConnectedException(); } if (method.empty()) { throw ex::EmptyArgumentException(); } std::string url = VKAPI_API_URL + method; - json pData = CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(pData))); + JsonType pData = CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(pData))); return response; } #ifdef __CPLUSPLUS_OVER_11 -auto BotBase::SendRequestAsync(const METHODS method, const json& parametersData) -{ return std::async(BotBase::SendRequestAsync_, this, method, parametersData); } +auto BotBase::SendRequestAsync(METHODS method, const JsonType& parametersData) +{ return std::async(BotBase::SendRequestAsyncByMethod_, this, method, parametersData); } -auto BotBase::SendRequestAsync(const std::string& method, const json& parametersData) -{ return std::async(BotBase::SendRequestAsync__, this, method, parametersData); } +auto BotBase::SendRequestAsync(const std::string& method, const JsonType& parametersData) +{ return std::async(BotBase::SendRequestAsyncByStr_, this, method, parametersData); } -json BotBase::SendRequestAsync_(BotBase* handle, const METHODS method, const json& parametersData) +JsonType BotBase::SendRequestAsyncByMethod_(BotBase* botHandle, METHODS method, const JsonType& parametersData) { - assert(handle == nullptr); - if (!handle->IsAuthorized()) { throw ex::NotConnectedException(); } + assert(botHandle == nullptr); + if (!botHandle->IsAuthorized()) { throw ex::NotConnectedException(); } std::string methodStr = BotBase::MethodToString(method); std::string url = VKAPI_API_URL + methodStr; - json pData = handle->CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, handle->ConvertParametersDataToURL(pData))); + JsonType pData = botHandle->CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, botHandle->ConvertParametersDataToURL(pData))); return response; } -json BotBase::SendRequestAsync__(BotBase* handle, const std::string& method, const json& parametersData) +JsonType BotBase::SendRequestAsyncByStr_(BotBase* botHandle, const std::string& method, const JsonType& parametersData) { - assert(handle == nullptr); - if (!handle->IsAuthorized()) { throw ex::NotConnectedException(); } + assert(botHandle == nullptr); + if (!botHandle->IsAuthorized()) { throw ex::NotConnectedException(); } if (method.empty()) { throw ex::EmptyArgumentException(); } std::string url = VKAPI_API_URL + method; - json pData = handle->CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, handle->ConvertParametersDataToURL(pData))); + JsonType pData = botHandle->CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, botHandle->ConvertParametersDataToURL(pData))); return response; } #endif // __CPLUSPLUS_OVER_11 -json BotBase::CheckValidationParameters(const json& parametersData) +JsonType BotBase::CheckValidationParameters(const JsonType& parametersData) { - json cParametersData = parametersData; + JsonType cParametersData = parametersData; if (cParametersData.find("access_token") == cParametersData.end()) { cParametersData.push_back({ "access_token", m_accessToken }); diff --git a/src/ClientBase.cpp b/src/ClientBase.cpp index e209ae9..71a58b3 100644 --- a/src/ClientBase.cpp +++ b/src/ClientBase.cpp @@ -2,7 +2,7 @@ * Contains general objects for working with VK API. * @file ClientBase.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #include @@ -18,17 +18,17 @@ ClientBase::ClientBase() {} void ClientBase::AddScope(std::string scope) -{ m_scope.insert(__MOVE(scope)); } +{ m_scope.insert(_VKAPI_MOVE(scope)); } void ClientBase::AddScope(std::initializer_list scopeList) { #ifdef __CPLUSPLUS_OVER_11 - for (const auto& scope : scopeList) { m_scope.insert(__MOVE(scope)); } + for (const auto& scope : scopeList) { m_scope.insert(_VKAPI_MOVE(scope)); } #else for (std::initializer_list::iterator iter = scopeList.begin(); iter != scopeList.end(); iter++) { - m_scope.insert(__MOVE(*iter)); + m_scope.insert(_VKAPI_MOVE(*iter)); } #endif // __CPLUSPLUS_OVER_11 } @@ -36,7 +36,7 @@ void ClientBase::AddScope(std::initializer_list scopeList) void ClientBase::ClearScope() { m_scope.clear(); } -std::string ClientBase::ConvertParametersDataToURL(const json& parametersData) +std::string ClientBase::ConvertParametersDataToURL(const JsonType& parametersData) { std::string result; @@ -46,7 +46,7 @@ std::string ClientBase::ConvertParametersDataToURL(const json& parametersData) utilities::ConvertStrToUrlCode(parameter.value().get()) + "&"; } #else - for (json::iterator iter = parametersData.begin(); + for (JsonType::iterator iter = parametersData.begin(); iter != parametersData.end(); iter++) { result += iter->key() + "=" + diff --git a/src/Request.cpp b/src/Request.cpp index 4559493..b4d2f03 100644 --- a/src/Request.cpp +++ b/src/Request.cpp @@ -50,6 +50,8 @@ std::string Request::Send(const std::string& url, const std::string& postData) return postData; } + + std::size_t Request::CurlWriteData(char* ptr, size_t size, size_t nmemb, std::string* data) { diff --git a/src/UserBase.cpp b/src/UserBase.cpp index 3b106c0..205478a 100644 --- a/src/UserBase.cpp +++ b/src/UserBase.cpp @@ -2,7 +2,7 @@ * Describes the class for working with VK account. * @file UserBase.hpp * @author qucals - * @version 0.0.5 18/08/21 + * @version 0.0.6 19/08/21 */ #include @@ -18,8 +18,8 @@ namespace user UserBase::UserBase(std::string appId, std::string appSecureKey) : ClientBase() - , m_appId(__MOVE(appId)) - , m_appSecureKey(__MOVE(appSecureKey)) + , m_appId(_VKAPI_MOVE(appId)) + , m_appSecureKey(_VKAPI_MOVE(appSecureKey)) { if (m_appId.empty() || m_appSecureKey.empty()) { throw ex::EmptyArgumentException(); } } @@ -44,7 +44,7 @@ bool UserBase::Auth(std::string& login, std::string& password) scope = scope.substr(0, scope.size() - 1); } - json parametersData = { + JsonType parametersData = { { "client_id", m_appId }, { "grant_type", "password" }, { "client_secret", m_appSecureKey }, @@ -53,8 +53,8 @@ bool UserBase::Auth(std::string& login, std::string& password) { "password", password } }; - json response = json::parse(Request::Send(VKAPI_AUTH_URL, - ConvertParametersDataToURL(parametersData))); + JsonType response = JsonType::parse(Request::Send(VKAPI_AUTH_URL, + ConvertParametersDataToURL(parametersData))); try { if (response.find("error") != response.end()) { @@ -94,7 +94,7 @@ bool UserBase::Auth(std::string& login, std::string& password) std::cin >> code; parametersData.push_back({ "code", code }); - response = json::parse(Request::Send(VKAPI_AUTH_URL, ConvertParametersDataToURL(parametersData))); + response = JsonType::parse(Request::Send(VKAPI_AUTH_URL, ConvertParametersDataToURL(parametersData))); m_accessToken = response.at("access_token").get(); m_userId = response.at("user_id").get(); @@ -105,7 +105,7 @@ bool UserBase::Auth(std::string& login, std::string& password) m_userId = response.at("user_id").get(); m_connectedToLongPoll = true; } - } catch (json::exception& exc) { + } catch (JsonType::exception& exc) { std::cerr << "exception message: " << exc.what() << std::endl; std::cerr << "exception id: " << exc.id << std::endl; } @@ -118,7 +118,7 @@ bool UserBase::Auth(const std::string& accessToken) if (accessToken.empty()) { throw ex::EmptyArgumentException(); } if (IsAuthorized()) { m_connectedToLongPoll = false; } - json parametersData = { + JsonType parametersData = { { "access_token", accessToken }, { "v", VKAPI_API_VERSION } }; @@ -126,7 +126,7 @@ bool UserBase::Auth(const std::string& accessToken) const std::string method = MethodToString(METHODS::USERS_GET); const std::string url = VKAPI_API_URL + method; - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(parametersData))); try { if (response.find("error") != response.end()) { @@ -135,8 +135,8 @@ bool UserBase::Auth(const std::string& accessToken) m_userId = data.value().at("id").get(); } #else - json __response = response.at("response").items(); - for (json::iterator iter = __response.begin(); + JsonType __response = response.at("response").items(); + for (JsonType::iterator iter = __response.begin(); iter != __response.end(); iter++) { m_userId = iter->value().at("id").get(); @@ -149,7 +149,7 @@ bool UserBase::Auth(const std::string& accessToken) m_accessToken.clear(); m_connectedToLongPoll = false; } - } catch (json::exception& exc) { + } catch (JsonType::exception& exc) { std::cerr << "exception message: " << exc.what() << std::endl; std::cerr << "exception id: " << exc.id << std::endl; } @@ -157,9 +157,9 @@ bool UserBase::Auth(const std::string& accessToken) return m_connectedToLongPoll; } -json UserBase::CheckValidationParameters(const json& parametersData) +JsonType UserBase::CheckValidationParameters(const JsonType& parametersData) { - json cParametersData = parametersData; + JsonType cParametersData = parametersData; if (cParametersData.find("access_token") == cParametersData.end()) { cParametersData.push_back({ "access_token", m_accessToken }); @@ -172,7 +172,7 @@ json UserBase::CheckValidationParameters(const json& parametersData) return cParametersData; } -std::string UserBase::GetURLCaptcha(json& parametersData, const json& response) +std::string UserBase::GetURLCaptcha(JsonType& parametersData, const JsonType& response) { parametersData.push_back( { "captcha_sid", response.at("captcha_sid").get() }); @@ -190,28 +190,28 @@ UserBase::VALIDATION_TYPES UserBase::GetValidationType(const std::string& descri } } -json UserBase::SendRequest(METHODS method, const json& parametersData) +JsonType UserBase::SendRequest(METHODS method, const JsonType& parametersData) { if (!IsAuthorized()) { throw ex::NotConnectedException(); } std::string methodStr = MethodToString(method); std::string url = VKAPI_API_URL + methodStr; - json pData = CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(pData))); + JsonType pData = CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(pData))); return response; } -json UserBase::SendRequest(const std::string& method, const json& parametersData) +JsonType UserBase::SendRequest(const std::string& method, const JsonType& parametersData) { if (!IsAuthorized()) { throw ex::NotConnectedException(); } if (method.empty()) { throw ex::EmptyArgumentException(); } std::string url = VKAPI_API_URL + method; - json pData = CheckValidationParameters(parametersData); - json response = json::parse(Request::Send(url, ConvertParametersDataToURL(pData))); + JsonType pData = CheckValidationParameters(parametersData); + JsonType response = JsonType::parse(Request::Send(url, ConvertParametersDataToURL(pData))); return response; } diff --git a/src/Utilities.cpp b/src/Utilities.cpp new file mode 100644 index 0000000..26b4e57 --- /dev/null +++ b/src/Utilities.cpp @@ -0,0 +1,142 @@ +/** + * Contains additional functions for working with the library. + * @file Utilities.hpp + * @author qucals + * @version 0.0.6 19/08/21 + */ + +#include + +namespace vk +{ + +namespace utilities +{ + +std::string ConvertStrToUrlCode(const std::string& str) +{ + std::string temp(str); + CURL* curl = curl_easy_init(); + + if (curl) { + char* output = curl_easy_escape(curl, str.c_str(), static_cast(str.length())); + + if (output) { + temp = output; + curl_free(output); + } + } + return temp; +} + +std::string ToString(int val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(unsigned val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(long val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(unsigned long val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(long long val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(unsigned long long val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(float val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(double val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +std::string ToString(long double val) +{ +#ifdef __CPLUSPLUS_OVER_11 + return std::to_string(val); +#else + std::ostringstream ostr; + ostr << val; + std::string str = ostr.str(); + return str; +#endif +} + +} // namespace utilities + +} // namespace vk From 010885128b4ee09a68b4bed738812ec94eb76f7f Mon Sep 17 00:00:00 2001 From: qucals Date: Sat, 21 Aug 2021 12:17:07 +0500 Subject: [PATCH 2/5] Added windows workflow --- .github/workflows/windows.yml | 64 +++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..ca811d4 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,64 @@ +name: Windows + +on: + push: + branches: + - master + - develop + pull_request: + branches: [ master ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + name: deploy to staging + runs-on: windows-latest + + strategy: + matrix: + architecture: [x64, x86] + + steps: + - uses: actions/checkout@v2 + + - name: Restore from cache and install vcpkg + uses: lukka/run-vcpkg@v7.4 + with: + setupOnly: true + + - name: Install deps + run: $VCPKG_ROOT/vcpkg install curl + shell: bash + + - name: Configure VKAPI Library CMake + run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build VKAPI Library + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Install VKAPI Library + run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + + # Configure, Build and Install WE - With Examples + - name: Configure VKAPI Library CMake WE + run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build VKAPI Library WE + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Install VKAPI Library WE + run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} + diff --git a/README.md b/README.md index 5594fe1..464290b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![CodeFactor](https://www.codefactor.io/repository/github/qucals/VK-API/badge/master)](https://www.codefactor.io/repository/github/qucals/VK-API/overview/master) [![Workflow](https://github.com/qucals/VK-API/actions/workflows/macos.yml/badge.svg)]() [![Workflow](https://github.com/qucals/VK-API/actions/workflows/ubuntu.yml/badge.svg)]() +[![Workflow](https://github.com/qucals/VK-API/actions/workflows/windows.yml/badge.svg)]() [![GitHub Issues](https://img.shields.io/github/issues/qucals/VK-API.svg)](https://github.com/qucals/VK-API/issues) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr/qucals/VK-API.svg)](https://github.com/qucals/VK-API/pulls) [![License](https://img.shields.io/github/license/qucals/VK-API)](/LICENSE) From c0f06aa1d4f5d80a3eb88da5330155057cc3bb6b Mon Sep 17 00:00:00 2001 From: qucals Date: Sat, 21 Aug 2021 12:49:23 +0500 Subject: [PATCH 3/5] Added submodule vcpkg --- .github/workflows/action.yml | 52 ++++++++++++++++++++++++++++ .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows.yml | 65 +++++++++++++++++------------------ .gitmodules | 3 ++ README.md | 2 ++ include/ClientBase.hpp | 2 +- vcpkg | 1 + vcpkg.json | 7 ++++ 9 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/action.yml create mode 100644 .gitmodules create mode 160000 vcpkg create mode 100644 vcpkg.json diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..cd900cc --- /dev/null +++ b/.github/workflows/action.yml @@ -0,0 +1,52 @@ +name: Build (MacOS, Ubuntu, Windows) + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ master ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + job: + name: ${{ matrix.os }}-build + runs-on: ${{ matrix.on }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + triplet: x64-ubuntu + - os: macos-latest + triplet: x64-osx + - os: windows-latest + triplet: x64-windows + env: + CMAKE_BUILD_DIR: ${{ github.workspace }}/build/ + VCPKG_ROOT: ${{ github.workspace }}/submodules/vcpkg + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - uses: lukka/get-cmake@latest + + - name: Restore vcpkg and its artifacts + uses: actions/cache@v2 + with: + path: | + ${{ env.CMAKE_BUILD_DIR }}/vcpkg_installed/ + ${{ env.VCPKG_ROOT }} + !${{ env.VCPKG_ROOT }}/buildtrees + !${{ env.VCPKG_ROOT }}/packages + !${{ env.VCPKG_ROOT }}/downloads + key: | + ${{ hashFiles( 'vcpkg_manifest/vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }}-invalidate + + - name: Show content of workspace after cache has been restored + \ No newline at end of file diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a1a986b..29c18a2 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -18,7 +18,7 @@ jobs: # well on Windows or Mac. You can convert this to a matrix build if you need # cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - name: deploy to staging + name: Deploy on MacOS runs-on: macos-latest steps: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0f74baf..77dc8f7 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -14,7 +14,7 @@ env: jobs: build: - name: deploy to staging + name: Deploy on Ubuntu runs-on: ubuntu-latest steps: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index ca811d4..4620c6a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -6,7 +6,7 @@ on: - master - develop pull_request: - branches: [ master ] + branches: [master] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) @@ -18,47 +18,46 @@ jobs: # well on Windows or Mac. You can convert this to a matrix build if you need # cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - name: deploy to staging + name: Deploy on Windows runs-on: windows-latest - strategy: - matrix: - architecture: [x64, x86] - steps: - - uses: actions/checkout@v2 - - - name: Restore from cache and install vcpkg - uses: lukka/run-vcpkg@v7.4 - with: - setupOnly: true + - uses: actions/checkout@v2 + with: + submodules: true - - name: Install deps - run: $VCPKG_ROOT/vcpkg install curl - shell: bash + - uses: lukka/run-vcpkg@main + id: runvcpkg + with: + setupOnly: true + vcpkgCommitId: '30124253eecff36bc90f73341edbfb4f845e2a1e' + vcpkgDirectory: '${{ github.workspace }}/vcpkg' - - name: Configure VKAPI Library CMake - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Install deps + run: $VCPKG_ROOT/vcpkg install @$VCPKGRESPONSEFILE + shell: bash - - name: Build VKAPI Library - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Configure VKAPI Library CMake + run: cmake -B ${{ github.workspace }}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - - name: Install VKAPI Library - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + - name: Build VKAPI Library + run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} - # Configure, Build and Install WE - With Examples - - name: Configure VKAPI Library CMake WE - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Install VKAPI Library + run: cmake --build ${{ github.workspace }}/build --target install --config ${{ env.BUILD_TYPE }} - - name: Build VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + # Configure, Build and Install WE - With Examples + - name: Configure VKAPI Library CMake WE + run: cmake -B ${{ github.workspace }}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - - name: Install VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + - name: Build VKAPI Library WE + run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} - - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + - name: Install VKAPI Library WE + run: cmake --build ${{ github.workspace }}/build --target install --config ${{ env.BUILD_TYPE }} + - name: Test + working-directory: ${{ github.workspace }}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{ env.BUILD_TYPE }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4d25e49 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vcpkg"] + path = vcpkg + url = https://github.com/lukka/run-vcpkg diff --git a/README.md b/README.md index 464290b..e12c0f1 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,11 @@ [![Status](https://img.shields.io/badge/status-active-success.svg)]() [![CodeFactor](https://www.codefactor.io/repository/github/qucals/VK-API/badge/master)](https://www.codefactor.io/repository/github/qucals/VK-API/overview/master) +
[![Workflow](https://github.com/qucals/VK-API/actions/workflows/macos.yml/badge.svg)]() [![Workflow](https://github.com/qucals/VK-API/actions/workflows/ubuntu.yml/badge.svg)]() [![Workflow](https://github.com/qucals/VK-API/actions/workflows/windows.yml/badge.svg)]() +
[![GitHub Issues](https://img.shields.io/github/issues/qucals/VK-API.svg)](https://github.com/qucals/VK-API/issues) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr/qucals/VK-API.svg)](https://github.com/qucals/VK-API/pulls) [![License](https://img.shields.io/github/license/qucals/VK-API)](/LICENSE) diff --git a/include/ClientBase.hpp b/include/ClientBase.hpp index 35702ad..417add1 100644 --- a/include/ClientBase.hpp +++ b/include/ClientBase.hpp @@ -47,7 +47,7 @@ typedef nlohmann::json JsonType; #else typedef nlohmann::json JsonType; #endif // __VKAPI_VERSION_ADDED_OPTIONAL - + #define VKAPI_INVALID_REQUEST "invalid_request" #define VKAPI_NEED_CAPTCHA "need_captcha" diff --git a/vcpkg b/vcpkg new file mode 160000 index 0000000..279a0f1 --- /dev/null +++ b/vcpkg @@ -0,0 +1 @@ +Subproject commit 279a0f12c24858e7e71c4957a58b81c0af9ea4a9 diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..05a94e7 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "VK-API", + "version-string": "0.0.6", + "dependencies": [ + "curl" + ] + } \ No newline at end of file From 4bb530f0ab4fa263c4d742b575dfaab9e9d768f3 Mon Sep 17 00:00:00 2001 From: qucals Date: Sun, 22 Aug 2021 13:56:05 +0500 Subject: [PATCH 4/5] Removed submodules - Updated windows.yml - Updated CMakeLists.txt for Windows --- .github/workflows/action.yml | 52 ----------------------- .github/workflows/macos.yml | 29 ++++++------- .github/workflows/ubuntu.yml | 26 +++++++----- .github/workflows/windows.yml | 78 +++++++++++++++++++---------------- .gitmodules | 3 -- CMakeLists.txt | 14 +++++-- vcpkg | 1 - vcpkg.json | 7 ---- 8 files changed, 84 insertions(+), 126 deletions(-) delete mode 100644 .github/workflows/action.yml delete mode 160000 vcpkg delete mode 100644 vcpkg.json diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml deleted file mode 100644 index cd900cc..0000000 --- a/.github/workflows/action.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build (MacOS, Ubuntu, Windows) - -on: - push: - branches: [ master, develop ] - pull_request: - branches: [ master ] - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - -jobs: - job: - name: ${{ matrix.os }}-build - runs-on: ${{ matrix.on }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - include: - - os: ubuntu-latest - triplet: x64-ubuntu - - os: macos-latest - triplet: x64-osx - - os: windows-latest - triplet: x64-windows - env: - CMAKE_BUILD_DIR: ${{ github.workspace }}/build/ - VCPKG_ROOT: ${{ github.workspace }}/submodules/vcpkg - - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - - uses: lukka/get-cmake@latest - - - name: Restore vcpkg and its artifacts - uses: actions/cache@v2 - with: - path: | - ${{ env.CMAKE_BUILD_DIR }}/vcpkg_installed/ - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - key: | - ${{ hashFiles( 'vcpkg_manifest/vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }}-invalidate - - - name: Show content of workspace after cache has been restored - \ No newline at end of file diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 29c18a2..edfdbfe 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -9,46 +9,47 @@ on: branches: [ master ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CMAKE_BUILD_DIR: ${{ github.workspace }}/build/ jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally - # well on Windows or Mac. You can convert this to a matrix build if you need - # cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix name: Deploy on MacOS runs-on: macos-latest steps: - uses: actions/checkout@v2 + with: + submodules: true - name: Install deps - run: brew install curl + run: | + brew update + brew install curl - name: Configure VKAPI Library CMake - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - name: Build VKAPI Library - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} - name: Install VKAPI Library - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} # Configure, Build and Install WE - With Examples - name: Configure VKAPI Library CMake WE - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - name: Build VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} - name: Install VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} - name: Test - working-directory: ${{github.workspace}}/build + working-directory: ${{ env.CMAKE_BUILD_DIR }} # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + run: ctest -C ${{ env.BUILD_TYPE }} + diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 77dc8f7..47f6a89 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -9,8 +9,8 @@ on: branches: [ master ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CMAKE_BUILD_DIR: ${{ github.workspace }}/build/ jobs: build: @@ -19,32 +19,38 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: true - name: Install deps - run: sudo apt update && sudo apt upgrade && sudo apt install curl && sudo apt-get install libcurl4-openssl-dev + run: | + sudo apt update + sudo apt upgrade + sudo apt install curl + sudo apt-get install libcurl4-openssl-dev - name: Configure VKAPI Library CMake - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - name: Build VKAPI Library - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} - name: Install VKAPI Library - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} # Configure, Build and Install WE - With Examples - name: Configure VKAPI Library CMake WE - run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - name: Build VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} - name: Install VKAPI Library WE - run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} - name: Test - working-directory: ${{github.workspace}}/build + working-directory: ${{ env.CMAKE_BUILD_DIR }} # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + run: ctest -C ${{ env.BUILD_TYPE }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4620c6a..ccf1b9e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -6,58 +6,64 @@ on: - master - develop pull_request: - branches: [master] + branches: [ master ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CMAKE_BUILD_DIR: ${{ github.workspace }}/build jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally - # well on Windows or Mac. You can convert this to a matrix build if you need - # cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix name: Deploy on Windows runs-on: windows-latest steps: - - uses: actions/checkout@v2 - with: - submodules: true + - uses: actions/checkout@v2 + with: + submodules: true - - uses: lukka/run-vcpkg@main - id: runvcpkg - with: - setupOnly: true - vcpkgCommitId: '30124253eecff36bc90f73341edbfb4f845e2a1e' - vcpkgDirectory: '${{ github.workspace }}/vcpkg' + # - name: Install vcpkg and deps + # run: | + # cd .. + # git clone ${{ env.VCPKG_GIT }} + # cd vcpkg + # git checkout --force 2020.01 + # .\bootstrap-vcpkg.bat + # .\vcpkg.exe install curl + # cd ${{ github.workspace }} - - name: Install deps - run: $VCPKG_ROOT/vcpkg install @$VCPKGRESPONSEFILE - shell: bash + # - name: Configure VKAPI Library CMake + # run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} /../vcpkg/scripts/buildsystems/vcpkg.cmake - - name: Configure VKAPI Library CMake - run: cmake -B ${{ github.workspace }}/build -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} + - name: Install deps + uses: crazy-max/ghaction-chocolatey@v1 + with: + args: install curl - - name: Build VKAPI Library - run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} + - name: Configure VKAPI Library CMake + run: | + cd ${{ github.workspace }} + mkdir build + cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - - name: Install VKAPI Library - run: cmake --build ${{ github.workspace }}/build --target install --config ${{ env.BUILD_TYPE }} + - name: Build VKAPI Library + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} - # Configure, Build and Install WE - With Examples - - name: Configure VKAPI Library CMake WE - run: cmake -B ${{ github.workspace }}/build -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} + - name: Install VKAPI Library + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} - - name: Build VKAPI Library WE - run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} + # Configure, Build and Install WE - With Examples + - name: Configure VKAPI Library CMake WE + run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} - - name: Install VKAPI Library WE - run: cmake --build ${{ github.workspace }}/build --target install --config ${{ env.BUILD_TYPE }} + - name: Build VKAPI Library WE + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --config ${{ env.BUILD_TYPE }} + + - name: Install VKAPI Library WE + run: cmake --build ${{ env.CMAKE_BUILD_DIR }} --target install --config ${{ env.BUILD_TYPE }} - - name: Test - working-directory: ${{ github.workspace }}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{ env.BUILD_TYPE }} + - name: Test + working-directory: ${{ env.CMAKE_BUILD_DIR }} + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{ env.BUILD_TYPE }} \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 4d25e49..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "vcpkg"] - path = vcpkg - url = https://github.com/lukka/run-vcpkg diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a7b606..f8c61b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,17 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_INSTALL_INCLUDEDIR}) # Include json target_link_directories(${PROJECT_NAME} PUBLIC ${NLOHMANN_JSON_PATH}) -find_package(CURL REQUIRED) -target_link_directories(${PROJECT_NAME} PUBLIC ${CURL_INCLUDE_DIR}) -target_link_libraries(${PROJECT_NAME} PUBLIC curl) +# Link curl +if(UNIX) + find_package(CURL REQUIRED) + target_link_directories(${PROJECT_NAME} PUBLIC ${CURL_INCLUDE_DIR}) +else() + include(FindPkgConfig) + # find_package(CURL REQUIRED) + pkg_check_modules(CURL libcurl REQUIRED) +endif() + +target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl) set_target_properties( ${PROJECT_NAME} PROPERTIES diff --git a/vcpkg b/vcpkg deleted file mode 160000 index 279a0f1..0000000 --- a/vcpkg +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 279a0f12c24858e7e71c4957a58b81c0af9ea4a9 diff --git a/vcpkg.json b/vcpkg.json deleted file mode 100644 index 05a94e7..0000000 --- a/vcpkg.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "VK-API", - "version-string": "0.0.6", - "dependencies": [ - "curl" - ] - } \ No newline at end of file From 18cc21a91b50d83da427b494c8d703d3911bc5d8 Mon Sep 17 00:00:00 2001 From: qucals Date: Tue, 24 Aug 2021 10:53:05 +0500 Subject: [PATCH 5/5] Updated to 0.0.7 - Fixed the recommendations of the static analyzer - The problem of not compiling on windows has not yet been solved - Added Optional type --- .github/workflows/windows.yml | 13 ---- include/BotBase.hpp | 12 ++-- include/ClientBase.hpp | 31 +++++---- include/Config.hpp.in | 4 +- include/Defines.hpp | 25 +++++--- include/Exceptions.hpp | 7 +-- include/Optional.hpp | 115 ++++++++++++++++++++++++++++++++++ include/Request.hpp | 8 +-- include/UserBase.hpp | 7 +-- include/Utilities.hpp | 6 +- src/BotBase.cpp | 12 ++-- src/ClientBase.cpp | 13 ++-- src/Request.cpp | 4 +- src/UserBase.cpp | 13 ++-- src/Utilities.cpp | 4 +- 15 files changed, 189 insertions(+), 85 deletions(-) create mode 100644 include/Optional.hpp diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index ccf1b9e..69620e2 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -22,19 +22,6 @@ jobs: with: submodules: true - # - name: Install vcpkg and deps - # run: | - # cd .. - # git clone ${{ env.VCPKG_GIT }} - # cd vcpkg - # git checkout --force 2020.01 - # .\bootstrap-vcpkg.bat - # .\vcpkg.exe install curl - # cd ${{ github.workspace }} - - # - name: Configure VKAPI Library CMake - # run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} /../vcpkg/scripts/buildsystems/vcpkg.cmake - - name: Install deps uses: crazy-max/ghaction-chocolatey@v1 with: diff --git a/include/BotBase.hpp b/include/BotBase.hpp index 761c466..c3fbba3 100644 --- a/include/BotBase.hpp +++ b/include/BotBase.hpp @@ -2,15 +2,13 @@ * Contains the class for working with vkbot. * @file BotBase.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_BOTBASE_HPP #define VKAPI_BOTBASE_HPP -#include +#include "ClientBase.hpp" namespace vk { @@ -162,6 +160,7 @@ class BotBase : public ClientBase * * @retval a string (URL) of this method. */ + _VKAPI_COMPLEXITY_FUNCTION _VKAPI_STATIC std::string MethodToString(METHODS method); /** @@ -194,7 +193,7 @@ class BotBase : public ClientBase * * @retval the answer of your request in JsonType. */ - auto SendRequestAsync(METHODS method, const JsonType& parametersData); + auto SendRequestAsync(METHODS method, const JsonType& parametersData) -> std::future; /** * @brief The function witch calls private function for sending a request in asynchronous mode. @@ -204,7 +203,7 @@ class BotBase : public ClientBase * * @retval the answer of your request in JsonType. */ - auto SendRequestAsync(const std::string& method, const JsonType& parametersData); + auto SendRequestAsync(const std::string& method, const JsonType& parametersData) -> std::future; #endif // __CPLUSPLUS_OVER_11 @@ -227,6 +226,7 @@ class BotBase : public ClientBase * * @retval the type of event in enum (EVENTS). */ + _VKAPI_COMPLEXITY_FUNCTION _VKAPI_STATIC EVENTS GetTypeEvent(const std::string& typeEvent); private: diff --git a/include/ClientBase.hpp b/include/ClientBase.hpp index 417add1..f37dfd7 100644 --- a/include/ClientBase.hpp +++ b/include/ClientBase.hpp @@ -2,24 +2,22 @@ * Contains general objects for working with VK API. * @file ClientBase.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_CLIENTBASE_HPP #define VKAPI_CLIENTBASE_HPP -#include +#include "Config.hpp" -#include // Request -#include // ConvertStrToUrlCode -#include // already_connected, not_connected, empty_argument -#include +#include "Request.hpp" // Request +#include "Utilities.hpp" // ConvertStrToUrlCode +#include "Exceptions.hpp" // already_connected, not_connected, empty_argument +#include "Defines.hpp" #ifdef __VKAPI_VERSION_ADDED_OPTIONAL #if __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL -#include +#include "Optional.hpp" #endif // __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL #endif // __VKAPI_VERSION_ADDED_OPTIONAL @@ -27,12 +25,13 @@ #include // rand #include // set #include // string +#include // begin, end #ifdef __CPLUSPLUS_OVER_11 #include // async, future #endif // __CPLUSPLUS_OVER_11 -#include // nlohmann::json +#include "nlohmann/json.hpp" // nlohmann::json namespace vk { @@ -40,13 +39,13 @@ namespace vk namespace base { -#ifdef __VKAPI_VERSION_ADDED_OPTIONAL -#if __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL -typedef nlohmann::json JsonType; -#endif // __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL -#else +#ifndef VKAPI_OPTIONAL_HPP typedef nlohmann::json JsonType; -#endif // __VKAPI_VERSION_ADDED_OPTIONAL + +typedef long long int IdType; +typedef unsigned long long UIdType; +typedef bool IndicatorType; +#endif // VKAPI_OPTIONAL_HPP #define VKAPI_INVALID_REQUEST "invalid_request" #define VKAPI_NEED_CAPTCHA "need_captcha" diff --git a/include/Config.hpp.in b/include/Config.hpp.in index 3fecc89..86db997 100644 --- a/include/Config.hpp.in +++ b/include/Config.hpp.in @@ -2,11 +2,9 @@ * Contains information about the project's version. * @file Config.hpp * @author qucals - * @version @VKAPI_MAJOR_VERSION@.@VKAPI_MINOR_VERSION@.@VKAPI_PATCH_VERSION@ 18/08/21 + * @version @VKAPI_MAJOR_VERSION@.@VKAPI_MINOR_VERSION@.@VKAPI_PATCH_VERSION@ 24/08/21 */ -#pragma once - #ifndef VKAPI_CONFIG_HPP_IN #define VKAPI_CONFIG_HPP_IN diff --git a/include/Defines.hpp b/include/Defines.hpp index 841ecf4..cf5f02a 100644 --- a/include/Defines.hpp +++ b/include/Defines.hpp @@ -2,15 +2,13 @@ * Contains general defines about the language. * @file Defines.hpp * @author qucals - * @version 0.0.6 20/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_DEFINES_HPP #define VKAPI_DEFINES_HPP -#include +#include "Config.hpp" #ifndef _VKAPI_NO_IMPL #define _VKAPI_NO_IMPL @@ -87,15 +85,19 @@ #define _VKAPI_INLINE inline #endif // _VKAPI_INLINE +#ifndef _VKAPI_UNUSED +#define _VKAPI_UNUSED(x) (void)(x) +#endif // _VKAPI_UNUSED + #if defined(_MSC_VER) -#define __DISABLE_WARNING_PUSH __pragma(warning( push )) -#define __DISABLE_WARNING_POP __pragma(warning( pop )) -#define __DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber )) +#define __DISABLE_WARNING_PUSH __pragma(warning(push)) +#define __DISABLE_WARNING_POP __pragma(warning(pop)) +#define __DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber)) #elif defined(__GNUC__) || defined(__clang__) #define __DO_PRAGMA(X) _Pragma(#X) -#define __DISABLE_WARNING_PUSH __DO_PRAGMA(GCC diagnostic push) -#define __DISABLE_WARNING_POP __DO_PRAGMA(GCC diagnostic pop) -#define __DISABLE_WARNING(warningName) __DO_PRAGMA(ide diagnostic ignored #warningName) +#define __DISABLE_WARNING_PUSH __DO_PRAGMA("GCC diagnostic push") +#define __DISABLE_WARNING_POP __DO_PRAGMA("GCC diagnostic pop") +#define __DISABLE_WARNING(warningName) __DO_PRAGMA("GCC diagnostic ignored \"#warningName\"") #else #define __DISABLE_WARNING_PUSH #define __DISABLE_WARNING_POP @@ -106,4 +108,7 @@ #define __VKAPI_VERSION_ADDED_OPTIONAL __VKAPI_VERSION_NUM(0, 0, 7) #endif // __VKAPI_VERSION_ADDED_OPTIONAL +// TODO(#14): Write defines for disable complexity warnings +#define _VKAPI_COMPLEXITY_FUNCTION + #endif //VKAPI_DEFINES_HPP diff --git a/include/Exceptions.hpp b/include/Exceptions.hpp index 8077cbc..75b6a62 100644 --- a/include/Exceptions.hpp +++ b/include/Exceptions.hpp @@ -2,17 +2,16 @@ * Contains exceptions and information about them of this library. * @file Exceptions.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_EXCEPTIONS_HPP #define VKAPI_EXCEPTIONS_HPP +#include #include -#include +#include "Defines.hpp" namespace vk { diff --git a/include/Optional.hpp b/include/Optional.hpp new file mode 100644 index 0000000..b49d51d --- /dev/null +++ b/include/Optional.hpp @@ -0,0 +1,115 @@ +/** + * Describes optional class. + * @file Optional.hpp + * @author qucals + * @version 0.0.7 24/08/21 + */ + +#ifndef VKAPI_OPTIONAL_HPP +#define VKAPI_OPTIONAL_HPP + +#include + +#include "Defines.hpp" +#include "nlohmann/json.hpp" + +namespace vk +{ + +namespace base +{ + +#if defined(__CPLUSPLUS_OVER_17) + +#include + +template +class Optional : public std::optional +{}; + +#else + +template +class BasicOptional +{ +public: +#if defined(__CPLUSPLUS_OVER_11) + typedef _Type&& _RValue_Type; + typedef const _Type& _ConstRef_Type; +#else + typedef const _Type& _RValue_Type; + typedef const _Type& _ConstRef_Type; +#endif // defined(__CPLUSPLUS_OVER_14) + + BasicOptional() + : m_isSet(false) + {} + + _VKAPI_EXPLICIT BasicOptional(_RValue_Type val) + : m_val(_VKAPI_MOVE(val)) + , m_isSet(true) + {} + + void Set(_ConstRef_Type val) + { + m_val = val; + m_isSet = true; + } + + const _Type& Get() const& _VKAPI_NOEXCEPT + { return m_val; } + + void Clear() + { + m_val = _Type(); + m_isSet = false; + } + + bool Empty() + { return !m_isSet; } + + BasicOptional& operator=(_ConstRef_Type val) + { + m_val = val; + m_isSet = true; + return *this; + } + + _VKAPI_EXPLICIT operator _Type() const + { + return m_val; + } + + bool operator==(const bool& val) const + { return m_isSet == val; } + +private: + _Type m_val; + bool m_isSet; +}; + +template +class Optional : public BasicOptional +{}; + +#endif // defined(__CPLUSPLUS_OVER_17) + +typedef long long int IdType; +typedef unsigned long long UIdType; +typedef bool IndicatorType; + +typedef nlohmann::json JsonType; + +typedef Optional Opt_IdType; +typedef Optional Opt_UIdType; +typedef Optional Opt_StrType; +typedef Optional Opt_FloatType; +typedef Optional Opt_JsonType; +typedef Optional&> Opt_IdArrayType; +typedef Optional Opt_IndicatorType; + +} // namespace base + +} // namespace vk + +#endif //VKAPI_OPTIONAL_HPP diff --git a/include/Request.hpp b/include/Request.hpp index 3ca9a32..cf40a7f 100644 --- a/include/Request.hpp +++ b/include/Request.hpp @@ -2,16 +2,14 @@ * Describes the class for working with CURL. * @file Request.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_REQUEST_HPP #define VKAPI_REQUEST_HPP -#include -#include // ConvertStrToUrlCode +#include "Defines.hpp" +#include "Utilities.hpp" // ConvertStrToUrlCode #include // curl #include // string diff --git a/include/UserBase.hpp b/include/UserBase.hpp index a214afe..188fd20 100644 --- a/include/UserBase.hpp +++ b/include/UserBase.hpp @@ -2,15 +2,13 @@ * Describes the class for working with VK account. * @file UserBase.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_USERBASE_HPP #define VKAPI_USERBASE_HPP -#include +#include "ClientBase.hpp" namespace vk { @@ -486,6 +484,7 @@ class UserBase : public ClientBase * * @retval a string of this method in URL format. */ + _VKAPI_COMPLEXITY_FUNCTION _VKAPI_STATIC std::string MethodToString(METHODS method); /** diff --git a/include/Utilities.hpp b/include/Utilities.hpp index 2cfea91..ed631bf 100644 --- a/include/Utilities.hpp +++ b/include/Utilities.hpp @@ -2,15 +2,13 @@ * Contains additional functions for working with the library. * @file Utilities.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#pragma once - #ifndef VKAPI_UTILITIES_HPP #define VKAPI_UTILITIES_HPP -#include +#include "Defines.hpp" #include // string #include // curl diff --git a/src/BotBase.cpp b/src/BotBase.cpp index 6317caa..f3cd4f6 100644 --- a/src/BotBase.cpp +++ b/src/BotBase.cpp @@ -2,10 +2,10 @@ * Contains the class for working with vkbot. * @file BotBase.cpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#include +#include "BotBase.hpp" namespace vk { @@ -26,7 +26,7 @@ bool BotBase::Auth(const std::string& accessToken) if (IsAuthorized()) { throw ex::AlreadyConnectedException(); } if (accessToken.empty()) { throw ex::EmptyArgumentException(); } - if (m_accessToken != accessToken) { m_accessToken = accessToken; } + m_accessToken = accessToken; JsonType parametersData = { { "access_token", m_accessToken }, @@ -77,6 +77,7 @@ BotBase::Event BotBase::WaitForEvent() return Event(GetTypeEvent(eventStr), updates); } +_VKAPI_COMPLEXITY_FUNCTION std::string BotBase::MethodToString(const METHODS method) { switch (method) { @@ -191,10 +192,10 @@ JsonType BotBase::SendRequest(const std::string& method, const JsonType& paramet #ifdef __CPLUSPLUS_OVER_11 -auto BotBase::SendRequestAsync(METHODS method, const JsonType& parametersData) +auto BotBase::SendRequestAsync(METHODS method, const JsonType& parametersData) -> std::future { return std::async(BotBase::SendRequestAsyncByMethod_, this, method, parametersData); } -auto BotBase::SendRequestAsync(const std::string& method, const JsonType& parametersData) +auto BotBase::SendRequestAsync(const std::string& method, const JsonType& parametersData) -> std::future { return std::async(BotBase::SendRequestAsyncByStr_, this, method, parametersData); } JsonType BotBase::SendRequestAsyncByMethod_(BotBase* botHandle, METHODS method, const JsonType& parametersData) @@ -246,6 +247,7 @@ JsonType BotBase::CheckValidationParameters(const JsonType& parametersData) return cParametersData; } +_VKAPI_COMPLEXITY_FUNCTION BotBase::EVENTS BotBase::GetTypeEvent(const std::string& typeEvent) { if (typeEvent == "message_new") { diff --git a/src/ClientBase.cpp b/src/ClientBase.cpp index 71a58b3..626f05f 100644 --- a/src/ClientBase.cpp +++ b/src/ClientBase.cpp @@ -2,10 +2,10 @@ * Contains general objects for working with VK API. * @file ClientBase.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#include +#include "ClientBase.hpp" namespace vk { @@ -27,7 +27,7 @@ void ClientBase::AddScope(std::initializer_list scopeList) #else for (std::initializer_list::iterator iter = scopeList.begin(); iter != scopeList.end(); - iter++) { + ++iter) { m_scope.insert(_VKAPI_MOVE(*iter)); } #endif // __CPLUSPLUS_OVER_11 @@ -41,14 +41,15 @@ std::string ClientBase::ConvertParametersDataToURL(const JsonType& parametersDat std::string result; #ifdef __CPLUSPLUS_OVER_11 + // TODO(#16): Rewrite below function with using std::accumulate for (const auto& parameter : parametersData.items()) { result += parameter.key() + "=" + - utilities::ConvertStrToUrlCode(parameter.value().get()) + "&"; + utilities::ConvertStrToUrlCode(parameter.value().get()) + "&"; } #else for (JsonType::iterator iter = parametersData.begin(); iter != parametersData.end(); - iter++) { + ++iter) { result += iter->key() + "=" + utilities::ConvertStrToUrlCode(iter->value().get()) + "&"; } @@ -73,7 +74,7 @@ VK_REQUEST_ERROR_TYPES ClientBase::GetRequestErrorType(const std::string& errorS { using VK_ERROR = VK_REQUEST_ERROR_TYPES; - // TODO: Add all VK_ERRORS + // TODO (#13): Add all VK_ERRORS if (errorStr == VKAPI_INVALID_REQUEST) { return VK_ERROR::INVALID_REQUEST; } else if (errorStr == VKAPI_NEED_CAPTCHA) { diff --git a/src/Request.cpp b/src/Request.cpp index b4d2f03..7ed765d 100644 --- a/src/Request.cpp +++ b/src/Request.cpp @@ -2,10 +2,10 @@ * Describes the class for working with CURL. * @file Request.hpp * @author qucals - * @version 0.0.3 15/08/21 + * @version 0.0.7 24/08/21 */ -#include +#include "Request.hpp" namespace vk { diff --git a/src/UserBase.cpp b/src/UserBase.cpp index 205478a..feb120d 100644 --- a/src/UserBase.cpp +++ b/src/UserBase.cpp @@ -2,10 +2,10 @@ * Describes the class for working with VK account. * @file UserBase.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#include +#include "UserBase.hpp" namespace vk { @@ -33,11 +33,13 @@ bool UserBase::Auth(std::string& login, std::string& password) if (!m_scope.empty()) { #ifdef __CPLUSPLUS_OVER_11 - for (const auto& i : m_scope) { scope += "," + i; } + scope = std::accumulate(std::begin(m_scope), std::end(m_scope), std::string(), + [](const std::string& temp, const std::string& item) + { return temp + "," + item; }); #else for (std::set::iterator iter = m_scope.begin(); iter != m_scope.end(); - iter++) { + ++iter) { scope += "," + i; } #endif // __CPLUSPLUS_OVER_11 @@ -138,7 +140,7 @@ bool UserBase::Auth(const std::string& accessToken) JsonType __response = response.at("response").items(); for (JsonType::iterator iter = __response.begin(); iter != __response.end(); - iter++) { + ++iter) { m_userId = iter->value().at("id").get(); } #endif // __CPLUSPLUS_OVER_11 @@ -216,6 +218,7 @@ JsonType UserBase::SendRequest(const std::string& method, const JsonType& parame return response; } +_VKAPI_COMPLEXITY_FUNCTION std::string UserBase::MethodToString(METHODS method) { switch (method) { diff --git a/src/Utilities.cpp b/src/Utilities.cpp index 26b4e57..081a5a3 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -2,10 +2,10 @@ * Contains additional functions for working with the library. * @file Utilities.hpp * @author qucals - * @version 0.0.6 19/08/21 + * @version 0.0.7 24/08/21 */ -#include +#include "Utilities.hpp" namespace vk {