diff --git a/Makefile b/Makefile index 1ec64b0..9a7beb7 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LDFLAGS = -lcurl SRC_DIR = src INCLUDE_DIR = include EXAMPLES_DIR = examples -TESTS_DIR = tests/ +TESTS_DIR = tests SRCS = \ $(SRC_DIR)/Appwrite.cpp \ @@ -233,7 +233,12 @@ getQueueMigrations: $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/params/getQueueMigrations $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp $(LDFLAGS) -# Messaging +# Messaging - Messages +listMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listMessages $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessages.cpp $(LDFLAGS) + +# Messaging - Topics getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp $(LDFLAGS) @@ -246,6 +251,8 @@ deleteTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/deleteTopic.cpp createTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp $(LDFLAGS) + +# Messaging - subscribers getSubscriber: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/getSubscriber $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp $(LDFLAGS) diff --git a/examples/messaging/messages/listMessages.cpp b/examples/messaging/messages/listMessages.cpp new file mode 100644 index 0000000..c242342 --- /dev/null +++ b/examples/messaging/messages/listMessages.cpp @@ -0,0 +1,20 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = "66fbb5a100070a3a1d19"; + std::string apiKey = ""; + Appwrite appwrite(projectId, apiKey); + + Queries queries; + queries.queryLimit(50); + + try { + std::string response = appwrite.getMessaging().listMessages(queries); + std::cout << "Messages fetched! \nResponse: " << response << std::endl; + } catch (const AppwriteException &ex) { + std::cerr << "Exception: " << ex.what() << std::endl; + } + + return 0; +} diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index 88230fd..6bf5147 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -11,11 +11,14 @@ class Messaging { public: Messaging(const std::string &projectId, const std::string &apiKey); + std::string listMessages(Queries &queries); + std::string getTopic(const std::string &topicId); std::string listTopics(Queries &queries); std::string deleteTopic(const std::string &topicId); std::string createTopic(const std::string &topicId, const std::string &name, const std::vector &subscribe); + std::string getSubscriber(const std::string &topicId, const std::string &subscriberId); std::string listSubscribers(const std::string &topicId, Queries &queries); diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 0e196b0..a4fec40 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -11,6 +11,26 @@ Messaging::Messaging(const std::string &projectId, const std::string &apiKey) : projectId(projectId), apiKey(apiKey) {} +std::string Messaging::listMessages(Queries &queries) { + std::string url = + Config::API_BASE_URL + "/messaging/messages" + queries.to_string(); + + std::vector headers = Config::getHeaders(projectId); + headers.push_back("X-Appwrite-Key: " + apiKey); + + std::string response; + + int statusCode = Utils::getRequest(url, headers, response); + + if (statusCode == HttpStatus::OK) { + return response; + } else { + throw AppwriteException("Error listing messages. Status code: " + + std::to_string(statusCode) + + "\n\nResponse: " + response); + } +} + std::string Messaging::getTopic(const std::string &topicId) { if (topicId.empty()) { throw AppwriteException("Missing required parameter: 'topicId'");