2020-12-31 08:47:51 +00:00
|
|
|
export class ApiClient {
|
|
|
|
constructor(baseUrl) {
|
|
|
|
this.baseUrl = baseUrl
|
|
|
|
}
|
|
|
|
|
2022-08-04 17:37:16 +00:00
|
|
|
listBookmarks(filters, options = {limit: 100, offset: 0, path: ''}) {
|
|
|
|
const query = [
|
|
|
|
`limit=${options.limit}`,
|
|
|
|
`offset=${options.offset}`,
|
|
|
|
]
|
|
|
|
Object.keys(filters).forEach(key => {
|
|
|
|
const value = filters[key]
|
|
|
|
if (value) {
|
|
|
|
query.push(`${key}=${encodeURIComponent(value)}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const queryString = query.join('&')
|
|
|
|
const url = `${this.baseUrl}bookmarks${options.path}/?${queryString}`
|
2021-03-28 22:43:50 +00:00
|
|
|
|
|
|
|
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}`
|
2021-02-14 17:00:22 +00:00
|
|
|
|
|
|
|
return fetch(url)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => data.results)
|
|
|
|
}
|
2020-12-31 08:47:51 +00:00
|
|
|
}
|