Skip to content

Commit 4da13b1

Browse files
committed
Add authRefresh and checkHealth methods; enhance README with API coverage and usage examples
1 parent c3a2525 commit 4da13b1

3 files changed

Lines changed: 651 additions & 82 deletions

File tree

PocketbaseExtended.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,57 @@ PBResponse PocketbaseExtended::authWithPassword(const char* identity, const char
8484
return resp;
8585
}
8686

87+
PBResponse PocketbaseExtended::authRefresh() {
88+
if (_collection.length() == 0) {
89+
PBResponse r; r.ok = false; r.statusCode = 0;
90+
r.error = "No collection set. Call collection() first.";
91+
return r;
92+
}
93+
if (_authToken.length() == 0) {
94+
PBResponse r; r.ok = false; r.statusCode = 0;
95+
r.error = "No token to refresh. Call authWithPassword() first.";
96+
return r;
97+
}
98+
99+
String url = _baseUrl + "collections/" + _collection + "/auth-refresh";
100+
PBResponse resp = _request("POST", url);
101+
102+
// Auto-update stored token on success
103+
if (resp.ok) {
104+
int idx = resp.body.indexOf("\"token\":\"");
105+
if (idx != -1) {
106+
idx += 9;
107+
int end = resp.body.indexOf("\"", idx);
108+
if (end != -1) {
109+
_authToken = resp.body.substring(idx, end);
110+
}
111+
}
112+
}
113+
114+
return resp;
115+
}
116+
117+
// ---------------------------------------------------------------------------
118+
// Health
119+
// ---------------------------------------------------------------------------
120+
121+
PBResponse PocketbaseExtended::checkHealth() {
122+
String url = _baseUrl + "health";
123+
return _request("GET", url);
124+
}
125+
126+
// ---------------------------------------------------------------------------
127+
// Files
128+
// ---------------------------------------------------------------------------
129+
130+
String PocketbaseExtended::getFileUrl(const char* recordId,
131+
const char* filename,
132+
const char* thumb) {
133+
String url = _baseUrl + "files/" + _collection + "/" + recordId + "/" + filename;
134+
url = _appendParam(url, "thumb", thumb);
135+
return url;
136+
}
137+
87138
// ---------------------------------------------------------------------------
88139
// Private helpers
89140
// ---------------------------------------------------------------------------
@@ -123,8 +174,8 @@ PBResponse PocketbaseExtended::_request(const char* method, const String& url, c
123174
resp.error = "";
124175

125176
if (_collection.length() == 0 &&
126-
url.indexOf("/auth-with-password") == -1 &&
127-
url.indexOf("/collections/") == -1) {
177+
url.indexOf("/collections/") == -1 &&
178+
url.indexOf("/health") == -1) {
128179
resp.error = "No collection set.";
129180
return resp;
130181
}

0 commit comments

Comments
 (0)