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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \

Expand Down Expand Up @@ -80,6 +81,7 @@ BINS = \
getQueueMails \
getQueueMessaging \
getQueueMigrations \
getTopics \

# build all binaries
all: $(BINS)
Expand Down Expand Up @@ -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)
$(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)
8 changes: 8 additions & 0 deletions docs/Messaging.md
Original file line number Diff line number Diff line change
@@ -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) |
19 changes: 19 additions & 0 deletions examples/messaging/topics/getTopic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "Appwrite.hpp"
#include <iostream>

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;
}
3 changes: 3 additions & 0 deletions include/Appwrite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "classes/Databases.hpp"
#include "classes/Storage.hpp"
#include "classes/Health.hpp"
#include "classes/Messaging.hpp"

class Appwrite {
public:
Expand All @@ -13,6 +14,7 @@ class Appwrite {
Databases& getDatabases();
Storage& getStorage();
Health& getHealth();
Messaging& getMessaging();

private:
std::string projectId;
Expand All @@ -21,6 +23,7 @@ class Appwrite {
Databases databases;
Storage storage;
Health health;
Messaging messaging;
};

#endif
20 changes: 20 additions & 0 deletions include/classes/Messaging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MESSAGING_HPP
#define MESSAGING_HPP

#include <string>
#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
6 changes: 5 additions & 1 deletion src/Appwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -19,4 +19,8 @@ Storage& Appwrite::getStorage() {

Health& Appwrite::getHealth() {
return health;
}

Messaging& Appwrite::getMessaging() {
return messaging;
}
35 changes: 35 additions & 0 deletions src/services/Messaging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include "classes/Messaging.hpp"
#include "Validator.hpp"
#include <sstream>
#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<std::string> 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);
}
}

Binary file added tests/messaging/topics/getTopics
Binary file not shown.