Skip to content

Commit 59c3751

Browse files
authored
List provider logs (#134)
* list provider logs function * removing unnecessary data from list provider logs function
1 parent 503ca60 commit 59c3751

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp
280280
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS)
281281

282282

283+
listProviderLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviderLogs.cpp
284+
@mkdir -p ./$(TESTS_DIR)
285+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listProviderLogs $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listProviderLogs.cpp $(LDFLAGS)
286+
283287
# Messaging - Topics
284288
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp
285289
@mkdir -p ./$(TESTS_DIR)
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+
int main() {
4+
std::string projectId = "68853010003a3f4fc106";
5+
std::string apiKey = "";
6+
std::string providerId = "68bf146d003761d36496";
7+
Appwrite appwrite(projectId, apiKey);
8+
Queries queries;
9+
queries.queryLimit(50);
10+
try {
11+
std::string response =
12+
appwrite.getMessaging().listProviderLogs(providerId, queries);
13+
std::cout << "provider logs fetched! \nResponse: " << response
14+
<< std::endl;
15+
} catch (const AppwriteException &ex) {
16+
std::cerr << "Exception: " << ex.what() << std::endl;
17+
}
18+
return 0;
19+
}

include/classes/Messaging.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,16 @@ class Messaging {
181181
*/
182182
std::string listProviders(Queries &queries);
183183

184-
/**
184+
/**
185+
* @brief List all provider logs.
186+
* @param providerId ID of the provider
187+
* @param queries Optional query filters
188+
* @return JSON string of provider logs list
189+
*/
190+
std::string listProviderLogs(const std::string &providerId,
191+
Queries &queries);
192+
193+
/**
185194
* @brief Create a new Firebase Cloud Messaging provider.
186195
* @param providerId A unique Id for the provider.
187196
* @param name provider name.

src/services/Messaging.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@ std::string Messaging::updatePush(const std::string &messageId,
565565
}
566566
}
567567

568+
std::string Messaging::listProviderLogs(const std::string &providerId,
569+
Queries &queries) {
570+
if (providerId.empty()) {
571+
throw AppwriteException("Missing required parameter: providerId");
572+
}
573+
std::string url =
574+
Config::API_BASE_URL + "/messaging/providers/" + providerId + "/logs";
575+
std::vector<std::string> headers = Config::getHeaders(projectId);
576+
headers.push_back("X-Appwrite-Key: " + apiKey);
577+
std::string response;
578+
int statusCode = Utils::getRequest(url, headers, response);
579+
if (statusCode == HttpStatus::OK) {
580+
return response;
581+
} else {
582+
throw AppwriteException("Error listing providers logs. Status code: " +
583+
std::to_string(statusCode) +
584+
"\nResponse: " + response);
585+
}
586+
}
587+
568588
std::string Messaging::createFcmProvider(std::string &providerId,
569589
std::string name,
570590
std::string service_account_json,
@@ -716,3 +736,4 @@ std::string Messaging::listTargets(const std::string &messageId,
716736
}
717737
}
718738

739+

0 commit comments

Comments
 (0)