Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Merge b4e21f3 into cd1cb5b
Browse files Browse the repository at this point in the history
  • Loading branch information
szdc committed Nov 16, 2018
2 parents cd1cb5b + b4e21f3 commit dfab65c
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 1 deletion.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const api = new TikTokAPI(params, { signURL });
* [.listFollowing(params)](#listfollowingparams)
* [.follow(id)](#followid)
* [.unfollow(id)](#unfollowid)
* [.listReceivedFollowRequests(params)](#listreceivedfollowrequestsparams)
* [.approveFollowRequest(id)](#approvefollowrequestid)
* [.rejectFollowRequest(id)](#rejectfollowrequestid)
* [.likePost(id)](#likepostid)
* [.unlikePost(id)](#unlikepostid)
* [.listComments(params)](#listcommentsparams)
Expand Down Expand Up @@ -209,6 +212,57 @@ api.unfollow('<user_id>')

See the [follow types](src/types/follow.d.ts) for the response data.

#### .listReceivedFollowRequests(params)

Lists the users that have requested to follow the logged in user.

```javascript
api.listReceivedFollowRequests({
max_time: Math.floor(new Date().getTime() / 1000),
count: 10,
})
.then(res => console.log(res.data.request_users))
.catch(console.log);

// Outputs:
// [{ unique_id: 'user1' }, { unique_id: 'user2' }, ...]

```

See the [follow types](src/types/follow.d.ts) for the complete request/response objects.

#### .approveFollowRequest(id)

Approves a user's request to follow you.

```javascript
api.approveFollowRequest('<user_id>')
.then(res => console.log(res.data.approve_status))
.catch(console.log);

// Outputs:
// 0

```

See the [follow types](src/types/follow.d.ts) for the response data.

#### .rejectFollowRequest(id)

Rejects a user's request to follow you.

```javascript
api.rejectFollowRequest('<user_id>')
.then(res => console.log(res.data.reject_status))
.catch(console.log);

// Outputs:
// 0

```

See the [follow types](src/types/follow.d.ts) for the response data.

#### .likePost(id)

Likes a post.
Expand Down
38 changes: 38 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,44 @@ export default class TikTokAPI {
},
})

/**
* Lists the users who have requested to follow the logged in user.
*
* @param {ListReceivedFollowRequestsRequest} params
* @returns {AxiosPromise<ListReceivedFollowRequestsResponse | BaseResponseData>}
*/
listReceivedFollowRequests = (params: API.ListReceivedFollowRequestsRequest) =>
this.request.get<API.ListReceivedFollowRequestsResponse | API.BaseResponseData>(
'aweme/v1/user/following/request/list/',
{ params: withDefaultListParams(params) },
)

/**
* Approves a request from a user to follow you.
*
* @param userId
* @returns {AxiosPromise<ApproveFollowResponse | BaseResponseData>}
*/
approveFollowRequest = (userId: string) =>
this.request.get<API.ApproveFollowResponse | API.BaseResponseData>('aweme/v1/commit/follow/request/approve/', {
params: <API.ApproveFollowRequest>{
from_user_id: userId,
},
})

/**
* Rejects a request from a user to follow you.
*
* @param userId
* @returns {AxiosPromise<RejectFollowResponse | BaseResponseData>}
*/
rejectFollowRequest = (userId: string) =>
this.request.get<API.RejectFollowResponse | API.BaseResponseData>('aweme/v1/commit/follow/request/reject/', {
params: <API.RejectFollowRequest>{
from_user_id: userId,
},
})

/**
* Likes a post.
*
Expand Down
37 changes: 36 additions & 1 deletion src/types/follow.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { BaseResponseData } from './request';
import { CommonUserDetails } from './user';
import {
BaseResponseData,
ListRequestParams,
ListResponseData,
TimeOffsetRequestParams,
TimeOffsetResponseParams,
} from './request';

export interface FollowRequest extends BaseResponseData {
/** The id of the user to follow */
Expand All @@ -15,3 +22,31 @@ export interface FollowResponse extends BaseResponseData {
/** 0 if not watching, 1 if watching */
watch_status: 0 | 1;
}

export interface ListReceivedFollowRequestsRequest extends ListRequestParams, TimeOffsetRequestParams {
}

export interface ListReceivedFollowRequestsResponse extends ListResponseData, TimeOffsetResponseParams {
/** A list of users who have requested to follow you */
request_users: CommonUserDetails[];
}

export interface ApproveFollowRequest {
/** The id of the user to approve */
from_user_id: string;
}

export interface ApproveFollowResponse extends BaseResponseData {
/** 0 if the user was successfully approved */
approve_status: number;
}

export interface RejectFollowRequest {
/** The id of the user to reject */
from_user_id: string;
}

export interface RejectFollowResponse extends BaseResponseData {
/** 0 if the user was successfully rejected */
reject_status: number;
}
73 changes: 73 additions & 0 deletions test/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { assert } from 'chai';
import { describe, it } from 'mocha';

import TikTokAPI, {
ApproveFollowResponse,
FollowResponse,
ListReceivedFollowRequestsResponse,
RejectFollowResponse,
} from '../src';
import {
loadTestData,
Expand Down Expand Up @@ -58,3 +61,73 @@ describe('#unfollow()', () => {
assert.deepStrictEqual(res.data, expected);
});
});

describe('#listReceivedFollowRequests()', () => {
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/user/following/request/list/\?.*'))
.reply(200, loadTestData('listReceivedFollowRequests.json'), {});

const res = await api.listReceivedFollowRequests({ count: 10, max_time: 1000000000 });
const expected: ListReceivedFollowRequestsResponse = {
extra: {
fatal_item_ids: [],
logid: '20180101000000000000000000000000',
now: 1000000000000,
},
request_users: [],
has_more: false,
max_time: 1000000000,
min_time: 1000000001,
status_code: 0,
total: 1,
};
assert.deepStrictEqual(res.data, expected);
});
});

describe('#approveFollowRequest()', () => {
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/commit/follow/request/approve/\?.*'))
.reply(200, loadTestData('approveFollowRequest.json'), {});

const res = await api.approveFollowRequest(userId);
const expected: ApproveFollowResponse = {
extra: {
fatal_item_ids: [],
logid: '20180101000000000000000000000000',
now: 1000000000000,
},
approve_status: 0,
status_code: 0,
};
assert.deepStrictEqual(res.data, expected);
});
});

describe('#rejectFollowRequest()', () => {
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/commit/follow/request/reject/\?.*'))
.reply(200, loadTestData('rejectFollowRequest.json'), {});

const res = await api.rejectFollowRequest(userId);
const expected: RejectFollowResponse = {
extra: {
fatal_item_ids: [],
logid: '20180101000000000000000000000000',
now: 1000000000000,
},
reject_status: 0,
status_code: 0,
};
assert.deepStrictEqual(res.data, expected);
});
});
9 changes: 9 additions & 0 deletions test/testdata/approveFollowRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extra": {
"fatal_item_ids": [],
"logid": "20180101000000000000000000000000",
"now": 1000000000000
},
"approve_status": 0,
"status_code": 0
}
13 changes: 13 additions & 0 deletions test/testdata/listReceivedFollowRequests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extra": {
"fatal_item_ids": [],
"logid": "20180101000000000000000000000000",
"now": 1000000000000
},
"request_users": [],
"has_more": false,
"max_time": 1000000000,
"min_time": 1000000001,
"status_code": 0,
"total": 1
}
9 changes: 9 additions & 0 deletions test/testdata/rejectFollowRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extra": {
"fatal_item_ids": [],
"logid": "20180101000000000000000000000000",
"now": 1000000000000
},
"reject_status": 0,
"status_code": 0
}

0 comments on commit dfab65c

Please sign in to comment.