Skip to content

Commit f0ce2f2

Browse files
authored
feat: listProviders function (#122)
* listProviders function * Update Messaging.hpp
1 parent f948069 commit f0ce2f2

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ getMessages: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/getMessages.cpp
254254
createMessage: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp
255255
@mkdir -p ./$(TESTS_DIR)
256256
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/createMessage $(SRCS) $(EXAMPLES_DIR)/messaging/messages/createMessage.cpp $(LDFLAGS)
257+
listProviders: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviders.cpp
258+
@mkdir -p ./$(TESTS_DIR)
259+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listProviders $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviders.cpp $(LDFLAGS)
257260
listMessageLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp
258261
@mkdir -p ./$(TESTS_DIR)
259262
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listMessageLogs $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listMessageLogs.cpp $(LDFLAGS)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
int main() {
4+
std::string projectId = "68853010003a3f4fc106";
5+
std::string apiKey = "";
6+
Appwrite appwrite(projectId, apiKey);
7+
Queries queries;
8+
queries.queryLimit(50);
9+
try {
10+
std::string response = appwrite.getMessaging().listProviders(queries);
11+
std::cout << "providers fetched! \nResponse: " << response << std::endl;
12+
} catch (const AppwriteException &ex) {
13+
std::cerr << "Exception: " << ex.what() << std::endl;
14+
}
15+
return 0;
16+
}

include/classes/Messaging.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ class Messaging {
173173
const std::string &body,
174174
const std::vector<std::string> &topicId = {},
175175
const std::vector<std::string> &userId = {});
176+
177+
/**
178+
* @brief List all providers.
179+
* @param queries Optional query filters
180+
* @return JSON string of providers list
181+
*/
182+
std::string listProviders(Queries &queries);
176183

177184
/**
178185
* @brief List all message logs with optional filters.

src/services/Messaging.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,20 @@ std::string Messaging::updatePush(const std::string &messageId,
530530
}
531531
}
532532

533+
std::string Messaging::listProviders(Queries &queries) {
534+
std::string url = Config::API_BASE_URL + "/messaging/providers";
535+
std::vector<std::string> headers = Config::getHeaders(projectId);
536+
headers.push_back("X-Appwrite-Key: " + apiKey);
537+
std::string response;
538+
int statusCode = Utils::getRequest(url, headers, response);
539+
if (statusCode == HttpStatus::OK) {
540+
return response;
541+
} else {
542+
throw AppwriteException("Error listing providers . Status code: " +
543+
std::to_string(statusCode) +
544+
"\nResponse: " + response);
545+
}
546+
}
533547

534548
std::string Messaging::listMessageLogs(const std::string &messageId,
535549
Queries &queries) {

0 commit comments

Comments
 (0)