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

Commit

Permalink
feat: add methods for approving and rejecting follow requests
Browse files Browse the repository at this point in the history
  • Loading branch information
szdc committed Nov 16, 2018
1 parent e0a08d2 commit b2b8d6e
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ api.listReceivedFollowRequests({

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
26 changes: 26 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ export default class TikTokAPI {
{ 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
20 changes: 20 additions & 0 deletions src/types/follow.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ export interface ListReceivedFollowRequestsResponse extends ListResponseData, Ti
/** 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;
}
49 changes: 48 additions & 1 deletion 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, {
FollowResponse, ListReceivedFollowRequestsResponse,
ApproveFollowResponse,
FollowResponse,
ListReceivedFollowRequestsResponse,
RejectFollowResponse,
} from '../src';
import {
loadTestData,
Expand Down Expand Up @@ -84,3 +87,47 @@ describe('#listReceivedFollowRequests()', () => {
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
}
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 b2b8d6e

Please sign in to comment.