This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method to retrieve information about stickers (#86)
- Loading branch information
Showing
7 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
BaseResponseData, | ||
Media, | ||
} from './request'; | ||
|
||
export interface GetStickersRequest { | ||
/** A list of sticker ids to get information about */ | ||
sticker_ids: string; | ||
} | ||
|
||
export interface GetStickersResponse extends BaseResponseData { | ||
sticker_infos: Sticker[]; | ||
} | ||
|
||
export interface Sticker { | ||
/** ??? */ | ||
children: []; | ||
|
||
/** A description of the sticker */ | ||
desc: string; | ||
|
||
/** The ID of the sticker */ | ||
effect_id: string; | ||
|
||
/** The icon associated with the sticker */ | ||
icon_url: Media; | ||
|
||
/** The ID of the sticker */ | ||
id: string; | ||
|
||
/** True if the current user has favorited the sticker */ | ||
is_favorite: boolean; | ||
|
||
/** The name of the sticker */ | ||
name: string; | ||
|
||
/** The ID the user that owns the sticker (empty if owned by the Effect Assistant) */ | ||
owner_id: string; | ||
|
||
/** The nickname of the owner, e.g. "Effect Assistant" */ | ||
owner_nickname: string; | ||
|
||
/** ??? */ | ||
tags: any[]; | ||
|
||
/** The total number of posts using this sticker */ | ||
user_count: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import TikTokAPI, { GetStickersResponse } from '../src'; | ||
import { | ||
loadTestData, | ||
mockConfig, | ||
mockParams, | ||
} from './util'; | ||
|
||
describe('#getSticker()', () => { | ||
it('a successful response should match the interface', async () => { | ||
const api = new TikTokAPI(mockParams, mockConfig); | ||
const mock = new MockAdapter(api.request); | ||
|
||
mock | ||
.onGet(new RegExp('aweme/v1/sticker/detail/\?.*')) | ||
.reply(200, loadTestData('getSticker.json'), {}); | ||
|
||
const res = await api.getSticker('100000'); | ||
const expected: GetStickersResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
sticker_infos: [ | ||
{ | ||
children: [], | ||
desc: '', | ||
effect_id: '100000', | ||
icon_url: { | ||
url_list: [ | ||
'http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/111111', | ||
], | ||
}, | ||
id: '100000', | ||
is_favorite: false, | ||
name: 'sticker1', | ||
owner_id: '', | ||
owner_nickname: 'Effect Assistant', | ||
tags: [], | ||
user_count: 10000, | ||
}, | ||
], | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); | ||
|
||
describe('#getStickers()', () => { | ||
it('a successful response should match the interface', async () => { | ||
const api = new TikTokAPI(mockParams, mockConfig); | ||
const mock = new MockAdapter(api.request); | ||
|
||
mock | ||
.onGet(new RegExp('aweme/v1/sticker/detail/\?.*')) | ||
.reply(200, loadTestData('getStickers.json'), {}); | ||
|
||
const res = await api.getStickers(['100000', '100001']); | ||
const expected: GetStickersResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
sticker_infos: [ | ||
{ | ||
children: [], | ||
desc: '', | ||
effect_id: '100000', | ||
icon_url: { | ||
url_list: [ | ||
'http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/111111', | ||
], | ||
}, | ||
id: '100000', | ||
is_favorite: false, | ||
name: 'sticker1', | ||
owner_id: '', | ||
owner_nickname: 'Effect Assistant', | ||
tags: [], | ||
user_count: 10000, | ||
}, | ||
{ | ||
children: [], | ||
desc: '', | ||
effect_id: '100001', | ||
icon_url: { | ||
url_list: [ | ||
'http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/222222', | ||
], | ||
}, | ||
id: '100001', | ||
is_favorite: false, | ||
name: 'sticker2', | ||
owner_id: '', | ||
owner_nickname: 'Effect Assistant', | ||
tags: [], | ||
user_count: 10001, | ||
}, | ||
], | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"sticker_infos": [ | ||
{ | ||
"children": [], | ||
"desc": "", | ||
"effect_id": "100000", | ||
"icon_url": { | ||
"url_list": [ | ||
"http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/111111" | ||
] | ||
}, | ||
"id": "100000", | ||
"is_favorite": false, | ||
"name": "sticker1", | ||
"owner_id": "", | ||
"owner_nickname": "Effect Assistant", | ||
"tags": [], | ||
"user_count": 10000 | ||
} | ||
], | ||
"status_code": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"sticker_infos": [ | ||
{ | ||
"children": [], | ||
"desc": "", | ||
"effect_id": "100000", | ||
"icon_url": { | ||
"url_list": [ | ||
"http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/111111" | ||
] | ||
}, | ||
"id": "100000", | ||
"is_favorite": false, | ||
"name": "sticker1", | ||
"owner_id": "", | ||
"owner_nickname": "Effect Assistant", | ||
"tags": [], | ||
"user_count": 10000 | ||
}, | ||
{ | ||
"children": [], | ||
"desc": "", | ||
"effect_id": "100001", | ||
"icon_url": { | ||
"url_list": [ | ||
"http://sf-tk-sg.ibytedtos.com/obj/ies.fe.effect.alisg/222222" | ||
] | ||
}, | ||
"id": "100001", | ||
"is_favorite": false, | ||
"name": "sticker2", | ||
"owner_id": "", | ||
"owner_nickname": "Effect Assistant", | ||
"tags": [], | ||
"user_count": 10001 | ||
} | ||
], | ||
"status_code": 0 | ||
} |