Skip to content

Commit

Permalink
Add pagination to posts fetch (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlafl authored Jul 12, 2023
1 parent 87f2144 commit aa921f8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ await client.feeds.notificationseen()
<br />

### client.posts.fetch
In the parameters pass the id of the post you want to get information about
In the parameters pass the id of the post you want to get information about, and an optional pagination token from the previous request.
```js
await client.posts.fetch("aAaAAAaaa")
await client.posts.fetch("aAaAAAaaa", "aAaAAAaaa")
```
### client.posts.likers
In the parameters pass the id of the post whose likes you want to get
Expand Down
4 changes: 2 additions & 2 deletions src/managers/PostManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const RESTManager = require("./RESTManager");

class PostManager extends RESTManager {
async fetch(post) {
return await this.request(`/api/v1/text_feed/${post}/replies`);
async fetch(post, paging_token) {
return await this.request(`/api/v1/text_feed/${post}/replies/` + (paging_token ? `?paging_token=${encodeURIComponent(paging_token)}` : ""));
}

async likers(post, user) {
Expand Down
4 changes: 2 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare module "@threadsjs/threads.js/src/managers/RESTManager.js" {
import { Client } from "@threadsjs/threads.js";
export default class RESTManager {
public constructor(client: Client);
request(url: string, options: object): Promise<any>;
request(url: string, options?: object): Promise<any>;
}
}

Expand Down Expand Up @@ -31,7 +31,7 @@ declare module "@threadsjs/threads.js/src/managers/PostManager.js" {
}

export default class PostManager extends RESTManager {
fetch(post: string) : Promise<any>;
fetch(post: string, paging_token?: string) : Promise<any>;
likers(post: string, user: string | number) : Promise<any>;
create(contents: string, user: string | number) : Promise<any>;
reply(contents: string, user: string | number, post: string): Promise<any>;
Expand Down

0 comments on commit aa921f8

Please sign in to comment.