-
Notifications
You must be signed in to change notification settings - Fork 7
/
avatar.js
49 lines (48 loc) · 1.46 KB
/
avatar.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const axios = require('axios')
const env = require('./env')
module.exports = class AvatarApi {
constructor(url, clientId, clientSecret) {
this.baseUrl = url;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
async getToken(code) {
const response = await axios({
method: 'post',
url: `${this.baseUrl}/api/v0/token`,
data: {
client_id: this.clientId,
client_secret: this.clientSecret,
code: code,
grant_type: "authorization_code"
}
})
return response.data.access_token;
}
async getProfile(token) {
const response = await axios({
method: 'get',
url: `${this.baseUrl}/api/v0/profile`,
headers: { 'Authorization': 'Bearer ' + token }
})
return response.data
}
async generate(token, text) {
await axios({
method: 'post',
url: `${this.baseUrl}/api/v0/generate`,
headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' },
data: {
text: text
}
})
}
async getGenerated(token) {
const response = await axios({
method: 'get',
url: `${this.baseUrl}/api/v0/generated`,
headers: { 'Authorization': 'Bearer ' + token }
})
return response.data.results
}
}