Skip to content

Commit b6e1b5a

Browse files
authored
Merge pull request #43 from pooranjoyb/feat/pooranjoyb
feat: getTopic #14
2 parents 41416fb + 4ec2a39 commit b6e1b5a

File tree

8 files changed

+97
-2
lines changed

8 files changed

+97
-2
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SRCS = \
1212
$(SRC_DIR)/services/Databases.cpp \
1313
$(SRC_DIR)/services/Storage.cpp \
1414
$(SRC_DIR)/services/Health.cpp \
15+
$(SRC_DIR)/services/Messaging.cpp \
1516
$(SRC_DIR)/Utils.cpp \
1617
$(SRC_DIR)/Validator.cpp \
1718

@@ -80,6 +81,7 @@ BINS = \
8081
getQueueMails \
8182
getQueueMessaging \
8283
getQueueMigrations \
84+
getTopics \
8385

8486
# build all binaries
8587
all: $(BINS)
@@ -234,4 +236,8 @@ getQueueMessaging: $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMessaging.cpp
234236
getQueueMigrations: $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp
235237
$(CXX) $(CXXFLAGS) -o ./tests/health/params/getQueueMigrations $(SRCS) $(EXAMPLES_DIR)/health/params/getQueueMigrations.cpp $(LDFLAGS)
236238
full_flow_test: $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp
237-
$(CXX) $(CXXFLAGS) -o ./tests/full_flow_test $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp $(LDFLAGS)
239+
$(CXX) $(CXXFLAGS) -o ./tests/full_flow_test $(SRCS) $(EXAMPLES_DIR)/full_flow_test.cpp $(LDFLAGS)
240+
241+
# Messaging
242+
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp
243+
$(CXX) $(CXXFLAGS) -o ./tests/messaging/topics/getTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp $(LDFLAGS)

docs/Messaging.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Class: Messaging
2+
Works around with Messaging API in Appwrite
3+
4+
### Topics
5+
6+
| Method Name | Usage | Link |
7+
|-------------|------------------------------------------------------------------------------------------------|--------------------------------------------------------|
8+
| `getTopic()` | Fetches the Topic information from the console. | [Example](/examples/messaging/getTopic.cpp) |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "66fbb5a100070a3a1d19";
6+
std::string apiKey = "";
7+
Appwrite appwrite(projectId, apiKey);
8+
9+
std::string topicId = "67b3048600077f40b8a7";
10+
11+
try {
12+
std::string response = appwrite.getMessaging().getTopic(topicId);
13+
std::cout << "Topic Fetched! \nResponse: " << response << std::endl;
14+
} catch (const AppwriteException& ex) {
15+
std::cerr << "Exception: " << ex.what() << std::endl;
16+
}
17+
18+
return 0;
19+
}

include/Appwrite.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "classes/Databases.hpp"
66
#include "classes/Storage.hpp"
77
#include "classes/Health.hpp"
8+
#include "classes/Messaging.hpp"
89

910
class Appwrite {
1011
public:
@@ -13,6 +14,7 @@ class Appwrite {
1314
Databases& getDatabases();
1415
Storage& getStorage();
1516
Health& getHealth();
17+
Messaging& getMessaging();
1618

1719
private:
1820
std::string projectId;
@@ -21,6 +23,7 @@ class Appwrite {
2123
Databases databases;
2224
Storage storage;
2325
Health health;
26+
Messaging messaging;
2427
};
2528

2629
#endif

include/classes/Messaging.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef MESSAGING_HPP
2+
#define MESSAGING_HPP
3+
4+
#include <string>
5+
#include "Utils.hpp"
6+
#include "exceptions/AppwriteException.hpp"
7+
#include "enums/HttpStatus.hpp"
8+
9+
class Messaging {
10+
public:
11+
Messaging(const std::string& projectId, const std::string& apiKey);
12+
13+
std::string getTopic(const std::string& topicId);
14+
15+
private:
16+
std::string projectId;
17+
std::string apiKey;
18+
};
19+
20+
#endif

src/Appwrite.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Appwrite::Appwrite(const std::string& projectId, const std::string& apiKey)
44
: projectId(projectId), apiKey(apiKey), account(projectId),
5-
databases(projectId, apiKey), storage(projectId, apiKey), health(projectId, apiKey) {}
5+
databases(projectId, apiKey), storage(projectId, apiKey), health(projectId, apiKey), messaging(projectId, apiKey) {}
66

77

88
Account& Appwrite::getAccount() {
@@ -19,4 +19,8 @@ Storage& Appwrite::getStorage() {
1919

2020
Health& Appwrite::getHealth() {
2121
return health;
22+
}
23+
24+
Messaging& Appwrite::getMessaging() {
25+
return messaging;
2226
}

src/services/Messaging.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include "classes/Messaging.hpp"
3+
#include "Validator.hpp"
4+
#include <sstream>
5+
#include "Utils.hpp"
6+
#include "config/Config.hpp"
7+
#include "enums/HttpStatus.hpp"
8+
#include "exceptions/AppwriteException.hpp"
9+
10+
Messaging::Messaging(const std::string& projectId, const std::string& apiKey)
11+
: projectId(projectId), apiKey(apiKey) {}
12+
13+
std::string Messaging::getTopic(const std::string& topicId) {
14+
if (topicId.empty()) {
15+
throw AppwriteException("Missing required parameter: 'topicId'");
16+
}
17+
18+
std::string url = Config::API_BASE_URL + "/messaging/topics/" + topicId;
19+
20+
std::vector<std::string> headers = Config::getHeaders(projectId);
21+
headers.push_back("X-Appwrite-Key: " + apiKey);
22+
23+
std::string response;
24+
25+
int statusCode = Utils::getRequest(url, headers, response);
26+
std::cout << response;
27+
28+
if (statusCode == HttpStatus::OK) {
29+
return response;
30+
}
31+
else {
32+
throw AppwriteException("Error fetching health. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
33+
}
34+
}
35+

tests/messaging/topics/getTopics

1.27 MB
Binary file not shown.

0 commit comments

Comments
 (0)