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 methods for listing the For You and Following feeds
- Loading branch information
Showing
8 changed files
with
217 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum FeedType { | ||
ForYou, | ||
Following, | ||
} | ||
|
||
export enum PullType { | ||
/** The feed was loaded by default, e.g. by clicking the tab or loading the app */ | ||
Default, | ||
|
||
/** The feed was explicitly refreshed by the user, e.g. by swiping down */ | ||
Refresh, | ||
|
||
/** More posts were requested by the user, e.g. by swiping up */ | ||
LoadMore, | ||
} |
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,44 @@ | ||
import { | ||
CursorOffsetRequestParams, | ||
CursorOffsetResponseParams, | ||
ListRequestParams, | ||
ListResponseData, | ||
} from './request'; | ||
import { Post } from './post'; | ||
import { FeedType, PullType } from '../feed'; | ||
|
||
export interface ListFeedRequest extends ListRequestParams, CursorOffsetRequestParams { | ||
/** The type of feed to load */ | ||
type: FeedType; | ||
|
||
/** Your device's current volume level on a scale of 0 to 1, e.g. 0.5 */ | ||
volume: number; | ||
|
||
/** How the feed was requested */ | ||
pull_type: PullType; | ||
|
||
/** ??? - empty */ | ||
req_from?: string; | ||
|
||
/** ??? - 0 */ | ||
is_cold_start?: 0 | 1; | ||
|
||
/** ??? */ | ||
gaid?: string; | ||
|
||
/** A user agent for your device */ | ||
ad_user_agent?: string; | ||
} | ||
|
||
export interface ListFeedResponse extends ListResponseData, CursorOffsetResponseParams { | ||
/** A list of posts in the feed */ | ||
aweme_list: Post[]; | ||
} | ||
|
||
export interface ListForYouFeedResponse extends ListFeedResponse { | ||
/** ??? - 1 */ | ||
home_model: number; | ||
|
||
/** ??? - 1 */ | ||
refresh_clear: 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
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,58 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import TikTokAPI, { ListFeedResponse, ListForYouFeedResponse } from '../src'; | ||
import { | ||
loadTestData, | ||
mockConfig, | ||
mockParams, | ||
} from './util'; | ||
|
||
describe('#listForYouFeed()', () => { | ||
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/feed/\?.*')) | ||
.reply(200, loadTestData('listForYouFeed.json'), {}); | ||
|
||
const res = await api.listForYouFeed(); | ||
const expected: ListForYouFeedResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
aweme_list: [], | ||
max_cursor: 0, | ||
min_cursor: 0, | ||
has_more: 1, | ||
home_model: 1, | ||
refresh_clear: 1, | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); | ||
|
||
describe('#listFollowingFeed()', () => { | ||
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/feed/\?.*')) | ||
.reply(200, loadTestData('listFollowingFeed.json'), {}); | ||
|
||
const res = await api.listFollowingFeed(); | ||
const expected: ListFeedResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
aweme_list: [], | ||
max_cursor: 0, | ||
min_cursor: 0, | ||
has_more: 1, | ||
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,10 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"aweme_list": [], | ||
"has_more": 1, | ||
"max_cursor": 0, | ||
"min_cursor": 0, | ||
"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,12 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"aweme_list": [], | ||
"has_more": 1, | ||
"max_cursor": 0, | ||
"min_cursor": 0, | ||
"home_model": 1, | ||
"refresh_clear": 1, | ||
"status_code": 0 | ||
} |