diff --git a/Makefile b/Makefile index f596771..4cc50aa 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SRCS = \ $(SRC_DIR)/services/Databases.cpp \ $(SRC_DIR)/services/Storage.cpp \ $(SRC_DIR)/services/Health.cpp \ + $(SRC_DIR)/services/Messaging.cpp \ $(SRC_DIR)/Utils.cpp \ $(SRC_DIR)/Validator.cpp \ @@ -80,6 +81,7 @@ BINS = \ getQueueMails \ getQueueMessaging \ getQueueMigrations \ + getTopics \ # build all binaries all: $(BINS) @@ -234,4 +236,8 @@ getQueueMessaging: $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMessaging.cpp getQueueMigrations: $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp $(CXX) $(CXXFLAGS) -o ./tests/health/params/getQueueMigrations $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp $(LDFLAGS) full_flow_test: $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp - $(CXX) $(CXXFLAGS) -o ./tests/full_flow_test $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp $(LDFLAGS) \ No newline at end of file + $(CXX) $(CXXFLAGS) -o ./tests/full_flow_test $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp $(LDFLAGS) + +# Messaging +getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp + $(CXX) $(CXXFLAGS) -o ./tests/messaging/topics/getTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp $(LDFLAGS) diff --git a/docs/Messaging.md b/docs/Messaging.md new file mode 100644 index 0000000..93573ac --- /dev/null +++ b/docs/Messaging.md @@ -0,0 +1,8 @@ +## Class: Messaging +Works around with Messaging API in Appwrite + +### Topics + +| Method Name | Usage | Link | +|-------------|------------------------------------------------------------------------------------------------|--------------------------------------------------------| +| `getTopic()` | Fetches the Topic information from the console. | [Example](/examples/messaging/getTopic.cpp) | \ No newline at end of file diff --git a/examples/messaging/topics/getTopic.cpp b/examples/messaging/topics/getTopic.cpp new file mode 100644 index 0000000..f6ead25 --- /dev/null +++ b/examples/messaging/topics/getTopic.cpp @@ -0,0 +1,19 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = "66fbb5a100070a3a1d19"; + std::string apiKey = ""; + Appwrite appwrite(projectId, apiKey); + + std::string topicId = "67b3048600077f40b8a7"; + + try { + std::string response = appwrite.getMessaging().getTopic(topicId); + std::cout << "Topic Fetched! \nResponse: " << response << std::endl; + } catch (const AppwriteException& ex) { + std::cerr << "Exception: " << ex.what() << std::endl; + } + + return 0; +} diff --git a/include/Appwrite.hpp b/include/Appwrite.hpp index 092865e..b4c66da 100644 --- a/include/Appwrite.hpp +++ b/include/Appwrite.hpp @@ -5,6 +5,7 @@ #include "classes/Databases.hpp" #include "classes/Storage.hpp" #include "classes/Health.hpp" +#include "classes/Messaging.hpp" class Appwrite { public: @@ -13,6 +14,7 @@ class Appwrite { Databases& getDatabases(); Storage& getStorage(); Health& getHealth(); + Messaging& getMessaging(); private: std::string projectId; @@ -21,6 +23,7 @@ class Appwrite { Databases databases; Storage storage; Health health; + Messaging messaging; }; #endif diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp new file mode 100644 index 0000000..6546b6f --- /dev/null +++ b/include/classes/Messaging.hpp @@ -0,0 +1,20 @@ +#ifndef MESSAGING_HPP +#define MESSAGING_HPP + +#include +#include "Utils.hpp" +#include "exceptions/AppwriteException.hpp" +#include "enums/HttpStatus.hpp" + +class Messaging { +public: + Messaging(const std::string& projectId, const std::string& apiKey); + + std::string getTopic(const std::string& topicId); + +private: + std::string projectId; + std::string apiKey; +}; + +#endif diff --git a/src/Appwrite.cpp b/src/Appwrite.cpp index 3f74c6b..8a5e35a 100644 --- a/src/Appwrite.cpp +++ b/src/Appwrite.cpp @@ -2,7 +2,7 @@ Appwrite::Appwrite(const std::string& projectId, const std::string& apiKey) : projectId(projectId), apiKey(apiKey), account(projectId), - databases(projectId, apiKey), storage(projectId, apiKey), health(projectId, apiKey) {} + databases(projectId, apiKey), storage(projectId, apiKey), health(projectId, apiKey), messaging(projectId, apiKey) {} Account& Appwrite::getAccount() { @@ -19,4 +19,8 @@ Storage& Appwrite::getStorage() { Health& Appwrite::getHealth() { return health; +} + +Messaging& Appwrite::getMessaging() { + return messaging; } \ No newline at end of file diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp new file mode 100644 index 0000000..d41883a --- /dev/null +++ b/src/services/Messaging.cpp @@ -0,0 +1,35 @@ +#include +#include "classes/Messaging.hpp" +#include "Validator.hpp" +#include +#include "Utils.hpp" +#include "config/Config.hpp" +#include "enums/HttpStatus.hpp" +#include "exceptions/AppwriteException.hpp" + +Messaging::Messaging(const std::string& projectId, const std::string& apiKey) + : projectId(projectId), apiKey(apiKey) {} + +std::string Messaging::getTopic(const std::string& topicId) { + if (topicId.empty()) { + throw AppwriteException("Missing required parameter: 'topicId'"); + } + + std::string url = Config::API_BASE_URL + "/messaging/topics/" + topicId; + + std::vector headers = Config::getHeaders(projectId); + headers.push_back("X-Appwrite-Key: " + apiKey); + + std::string response; + + int statusCode = Utils::getRequest(url, headers, response); + std::cout << response; + + if (statusCode == HttpStatus::OK) { + return response; + } + else { + throw AppwriteException("Error fetching health. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response); + } +} + diff --git a/tests/messaging/topics/getTopics b/tests/messaging/topics/getTopics new file mode 100755 index 0000000..a0f5476 Binary files /dev/null and b/tests/messaging/topics/getTopics differ