2023-08-21 21:12:00 +00:00
|
|
|
export class ApiClient {
|
|
|
|
constructor(baseUrl) {
|
|
|
|
this.baseUrl = baseUrl;
|
|
|
|
}
|
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
listBookmarks(search, options = { limit: 100, offset: 0, path: "" }) {
|
2023-08-21 21:12:00 +00:00
|
|
|
const query = [`limit=${options.limit}`, `offset=${options.offset}`];
|
2023-09-01 20:48:21 +00:00
|
|
|
Object.keys(search).forEach((key) => {
|
|
|
|
const value = search[key];
|
2023-08-21 21:12:00 +00:00
|
|
|
if (value) {
|
|
|
|
query.push(`${key}=${encodeURIComponent(value)}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const queryString = query.join("&");
|
|
|
|
const url = `${this.baseUrl}bookmarks${options.path}/?${queryString}`;
|
|
|
|
|
|
|
|
return fetch(url)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => data.results);
|
|
|
|
}
|
|
|
|
|
|
|
|
getTags(options = { limit: 100, offset: 0 }) {
|
|
|
|
const url = `${this.baseUrl}tags/?limit=${options.limit}&offset=${options.offset}`;
|
|
|
|
|
|
|
|
return fetch(url)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => data.results);
|
|
|
|
}
|
|
|
|
}
|