splitwise
Version:
A TypeScript SDK for the Splitwise API.
41 lines • 1.42 kB
JavaScript
import { BaseResource } from './base.js';
export class Friends extends BaseResource {
async list(overrides) {
return this.http.get('/get_friends', {
unwrapKey: 'friends',
...overrides,
});
}
async get(params, overrides) {
return this.http.get(`/get_friend/${params.id}`, {
unwrapKey: 'friend',
...overrides,
});
}
async create(params, overrides) {
// Verified empirically: the API returns { friend: {...} } (singular),
// matching the OpenAPI spec. v1 incorrectly assumed `friends: [...]`.
return this.http.post('/create_friend', {
body: { ...params },
unwrapKey: 'friend',
...overrides,
});
}
async createMultiple(params, overrides) {
// Per OpenAPI the wire format is `users[]` (not `friends[]`) and the
// response is wrapped in `users`.
return this.http.post('/create_friends', {
body: { users: params.friends },
unwrapKey: 'users',
...overrides,
});
}
/**
* Deletes a friendship. Throws SplitwiseConstraintError if the API refuses
* (most commonly because the friendship has unsettled debts).
*/
async delete(params, overrides) {
await this.http.post(`/delete_friend/${params.id}`, overrides);
}
}
//# sourceMappingURL=friends.js.map