-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
32 lines (25 loc) · 968 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { fetch } = require("undici");
const RESTManager = require("./managers/RESTManager");
const UserManager = require("./managers/UserManager");
const PostManager = require("./managers/PostManager");
class Client {
constructor(options) {
this.options = {}
this.options.token = options ? options.token : null;
this.options.secret = options ? options.secret : null;
this.options.base = options ? options.base : "https://graph.threads.net";
this.rest = new RESTManager(this);
this.users = new UserManager(this);
this.posts = new PostManager(this);
}
async refresh_token(token) {
return await this.rest.request(`/access_token/refresh_access_token?grant_type=th_refresh_token&access_token=${token}`);
}
async getToken(secret, token) {
const request = await this.rest.request(`/access_token?grant_type=th_exchange_token&client_secret=${secret}&access_token=${token}`);
this.token = request.access_token;
}
}
module.exports = {
Client,
};