Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions examples/messaging/messages/listMessages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Appwrite.hpp"
#include <iostream>

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;
}
3 changes: 3 additions & 0 deletions include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &subscribe);

std::string getSubscriber(const std::string &topicId,
const std::string &subscriberId);
std::string listSubscribers(const std::string &topicId, Queries &queries);
Expand Down
20 changes: 20 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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'");
Expand Down