Skip to content

Commit

Permalink
0.0.8
Browse files Browse the repository at this point in the history
- Solved #11 and #12,
- added file Types.h,
- replaced nlohmann/json as inserted a library to the submodule
  • Loading branch information
qucals committed Sep 1, 2021
1 parent 18cc21a commit 97ad46d
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 22,987 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1041,4 +1041,5 @@ dkms.conf

# VKAPI
include/Config.hpp
include/nlohmann*
src/main.cpp
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/json"]
path = submodules/json
url = https://github.com/nlohmann/json
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ include(GNUInstallDirs)

set(VKAPI_MAJOR_VERSION 0)
set(VKAPI_MINOR_VERSION 0)
set(VKAPI_PATCH_VERSION 5)
set(VKAPI_PATCH_VERSION 8)
set(VKAPI_VERSION_STRING "${VKAPI_MAJOR_VERSION}.${VKAPI_MINOR_VERSION}.${VKAPI_PATCH_VERSION}")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/Config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/Config.hpp @ONLY)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()

set(NLOHMANN_JSON_PATH "${PROJECT_SOURCE_DIR}/include")
# set(NLOHMANN_JSON_PATH "${PROJECT_SOURCE_DIR}/include")
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})

option(BUILD_LIBRARY "Determines that, as a result, we get" ON)
option(BUILD_EXAMPLES "Determines whether examples should be performed" ON)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/Config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/Config.hpp @ONLY)

file(GLOB TARGET_SRC "./src/*.cpp")
file(GLOB TARGET_HEADERS "./include/*.hpp")

include(submodules/install.cmake)

if(BUILD_LIBRARY)
add_library(${PROJECT_NAME} STATIC ${TARGET_SRC} ${TARGET_HEADERS})
else()
Expand All @@ -37,18 +39,18 @@ else()
add_executable(${PROJECT_NAME} ${TARGET_SRC} ${TARGET_HEADERS})
endif()

# Include headers
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_INSTALL_INCLUDEDIR})

# Include json
target_link_directories(${PROJECT_NAME} PUBLIC ${NLOHMANN_JSON_PATH})
# Link nlohmann_json
target_link_libraries(${PROJECT_NAME} PUBLIC nlohmann_json)

# 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()

Expand Down
1 change: 1 addition & 0 deletions VKAPIConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(CMakeFindDependencyMacro)

find_dependency(CURL REQUIRED)

@PACKAGE_INIT@
Expand Down
2 changes: 1 addition & 1 deletion examples/1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main(int argc, const char** argv)
} else {
std::cout << "Auth is failed!" << std::endl;
}
} catch (std::exception ex) {
} catch (std::exception& ex) {
std::cout << ex.what() << std::endl;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, const char** argv)
} else {
// The further behaviour
}
} catch (std::exception ex) {
} catch (std::exception& ex) {
std::cout << ex.what() << std::endl;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(VKAPI_TESTS LANGUAGES CXX)

set(VKAPI_MAJOR_VERSION 0)
set(VKAPI_MINOR_VERSION 0)
set(VKAPI_PATCH_VERSION 5)
set(VKAPI_PATCH_VERSION 8)

set(MODULES 1 2)

Expand Down
8 changes: 4 additions & 4 deletions include/BotBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Contains the class for working with vkbot.
* @file BotBase.hpp
* @author qucals
* @version 0.0.7 24/08/21
* @version 0.0.8 24/08/21
*/

#ifndef VKAPI_BOTBASE_HPP
Expand All @@ -19,7 +19,7 @@ namespace base
namespace bot
{

constexpr const char* DEFAULT_TIME_WAIT = "25";
_VKAPI_CONSTEXPR const char* DEFAULT_TIME_WAIT = "25";

/**
* @brief The class for working from bots by Long Poll Server.
Expand Down Expand Up @@ -160,7 +160,6 @@ class BotBase : public ClientBase
*
* @retval a string (URL) of this method.
*/
_VKAPI_COMPLEXITY_FUNCTION
_VKAPI_STATIC std::string MethodToString(METHODS method);

/**
Expand Down Expand Up @@ -226,7 +225,6 @@ class BotBase : public ClientBase
*
* @retval the type of event in enum (EVENTS).
*/
_VKAPI_COMPLEXITY_FUNCTION
_VKAPI_STATIC EVENTS GetTypeEvent(const std::string& typeEvent);

private:
Expand Down Expand Up @@ -269,6 +267,8 @@ class BotBase : public ClientBase
std::string m_timeStamp;

std::string m_timeWait;


};

} // namespace bot
Expand Down
21 changes: 7 additions & 14 deletions include/ClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Contains general objects for working with VK API.
* @file ClientBase.hpp
* @author qucals
* @version 0.0.7 24/08/21
* @version 0.0.8 24/08/21
*/

#ifndef VKAPI_CLIENTBASE_HPP
Expand All @@ -14,6 +14,7 @@
#include "Utilities.hpp" // ConvertStrToUrlCode
#include "Exceptions.hpp" // already_connected, not_connected, empty_argument
#include "Defines.hpp"
#include "Types.hpp"

#ifdef __VKAPI_VERSION_ADDED_OPTIONAL
#if __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL
Expand All @@ -39,22 +40,14 @@ namespace vk
namespace base
{

#ifndef VKAPI_OPTIONAL_HPP
typedef nlohmann::json JsonType;

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"

constexpr const char* VKAPI_API_URL = "https://api.vk.com/method/";
constexpr const char* VKAPI_AUTH_URL = "https://oauth.vk.com/token?";
constexpr const char* VKAPI_OAUTH_URL = "https://oauth.vk.com/authorize?";
constexpr const char* VKAPI_OAUTH_URL_SECOND = "https://oauth.vk.com/access_token?";
constexpr const char* VKAPI_API_VERSION = "5.120";
_VKAPI_CONSTEXPR const char* VKAPI_API_URL = "https://api.vk.com/method/";
_VKAPI_CONSTEXPR const char* VKAPI_AUTH_URL = "https://oauth.vk.com/token?";
_VKAPI_CONSTEXPR const char* VKAPI_OAUTH_URL = "https://oauth.vk.com/authorize?";
_VKAPI_CONSTEXPR const char* VKAPI_OAUTH_URL_SECOND = "https://oauth.vk.com/access_token?";
_VKAPI_CONSTEXPR const char* VKAPI_API_VERSION = "5.120";

// The types of error which the VK server can return.
// You can see the description of these on https://vk.com/dev/errors
Expand Down
85 changes: 39 additions & 46 deletions include/Defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Contains general defines about the language.
* @file Defines.hpp
* @author qucals
* @version 0.0.7 24/08/21
* @version 0.0.8 24/08/21
*/

#ifndef VKAPI_DEFINES_HPP
Expand Down Expand Up @@ -35,65 +35,37 @@
#endif // (__cplusplus >= 202002L)

#ifdef __CPLUSPLUS_OVER_11
#ifndef _VKAPI_OVERRIDE
#define _VKAPI_OVERRIDE override
#endif // _VKAPI_OVERRIDE
#define _VKAPI_OVERRIDE override
#define _VKAPI_FINAL final
#define _VKAPI_NOEXCEPT noexcept
#define _VKAPI_EXPLICIT explicit
#define _VKAPI_CONSTEXPR constexpr

#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 <utility>
#define _VKAPI_MOVE(x) std::move(x)
#endif // _VKAPI_MOVE(x)
#define _VKAPI_MOVE(x) std::move(x)
#else
#ifndef _VKAPI_OVERRIDE
#define _VKAPI_OVERRIDE
#endif // _VKAPI_OVERRIDE

#ifndef _VKAPI_FINAL
#define _VKAPI_FINAL
#endif // _VKAPI_FINAL

#ifndef _VKAPI_NOEXCEPT
#define _VKAPI_NOEXCEPT
#endif // _VKAPI_NOEXCEPT

#ifndef _VKAPI_EXPLICIT
#define _VKAPI_EXPLICIT
#endif // _VKAPI_EXPLICIT

#ifndef _VKAPI_MOVE
#define _VKAPI_MOVE(x) x
#endif // _VKAPI_MOVE
#define _VKAPI_CONSTEXPR
#define _VKAPI_MOVE(x) x
#endif

#ifndef _VKAPI_VIRTUAL
#define _VKAPI_VIRTUAL virtual
#endif // _VKAPI_VIRTUAL
#define _VKAPI_VIRTUAL virtual
#define _VKAPI_INLINE inline

#ifndef _VKAPI_INLINE
#define _VKAPI_INLINE inline
#endif // _VKAPI_INLINE

#ifndef _VKAPI_UNUSED
#define _VKAPI_UNUSED(x) (void)(x)
#endif // _VKAPI_UNUSED

#if defined(_MSC_VER)
#define _VKAPI_MSVC 1

#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 _VKAPI_CLANG 1

#define __DO_PRAGMA(X) _Pragma(#X)
#define __DISABLE_WARNING_PUSH __DO_PRAGMA("GCC diagnostic push")
#define __DISABLE_WARNING_POP __DO_PRAGMA("GCC diagnostic pop")
Expand All @@ -104,11 +76,32 @@
#define __DISABLE_WARNING
#endif

#ifndef _VKAPI_MSVC
#define _VKAPI_MSVC 0
#endif // _VKAPI_MSVC

#ifndef _VKAPI_CLANG
#define _VKAPI_CLANG 0
#endif // _VKAPI_CLANG

#if _VKAPI_MSVC
#define _VKAPI_UNUSED_FOR_ANALYZER
#elif _VKAPI_CLANG
#define _VKAPI_UNUSED_FOR_ANALYZER __attribute__((unused))
#endif

#ifndef _VKAPI_DEBUG_PRINT
#if __DEBUG__
#define _VKAPI_DEBUG_STDCERR(x) (std::cerr << (x))
#define _VKAPI_DEBUG_STDCOUT(x) (std::cout << (x))
#else
#define _VKAPI_DEBUG_STDCERR(x)
#define _VKAPI_DEBUG_STDCOUT(x)
#endif // __DEBUG__
#endif // _VKAPI_DEBUG_PRINT

#ifndef __VKAPI_VERSION_ADDED_OPTIONAL
#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
20 changes: 15 additions & 5 deletions include/Exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* Contains exceptions and information about them of this library.
* @file Exceptions.hpp
* @author qucals
* @version 0.0.7 24/08/21
* @version 0.0.8 24/08/21
*/

// TODO (#17): Add comments about exceptions

#ifndef VKAPI_EXCEPTIONS_HPP
#define VKAPI_EXCEPTIONS_HPP

Expand Down Expand Up @@ -40,35 +42,43 @@ class BaseException : _VKAPI_VIRTUAL public std::exception
class AlreadyConnectedException : _VKAPI_VIRTUAL public BaseException
{
public:
explicit AlreadyConnectedException()
_VKAPI_EXPLICIT AlreadyConnectedException()
: BaseException("The client is already connected to Long Poll Server!")
{}
};

class NotConnectedException : _VKAPI_VIRTUAL public BaseException
{
public:
explicit NotConnectedException()
_VKAPI_EXPLICIT NotConnectedException()
: BaseException("The client is not already connected to Long Poll Server!")
{}
};

class EmptyArgumentException : _VKAPI_VIRTUAL public BaseException
{
public:
explicit EmptyArgumentException()
_VKAPI_EXPLICIT EmptyArgumentException()
: BaseException("The size of argument's symbols cannot equal zero!")
{}
};

class RequestError : _VKAPI_VIRTUAL public BaseException
{
public:
explicit RequestError()
_VKAPI_EXPLICIT RequestError()
: BaseException("Request returned unknown errors!")
{}
};

class AuthFailed : _VKAPI_VIRTUAL public BaseException
{
public:
_VKAPI_EXPLICIT AuthFailed()
: BaseException("Authorization completed with an error!")
{}
};

} // namespace ex

} // namespace vk
Expand Down
Loading

0 comments on commit 97ad46d

Please sign in to comment.