Skip to content

Commit

Permalink
add follow create/delete API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Nov 16, 2020
1 parent e1dd435 commit 2ce5206
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const memberNames = [
'^(streak|cumulative)_months',
'^live_only$',
'^localization_(names|descriptions)',
'^allow_notifications$',
// HTTP
'^Accept$'
];
Expand Down
46 changes: 46 additions & 0 deletions packages/twitch/src/API/Helix/User/HelixUserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,52 @@ export class HelixUserApi extends BaseApi {
);
}

/**
* Creates a new follow from a user to another user.
*
* @param fromUser The user to create the follow for.
* @param toUser The user to follow.
* @param allowNotifications Whether email or push notifications are allowed to be created.
*
* The user `fromUser` still needs to have this enabled in their settings as well.
*/
async createFollow(
fromUser: UserIdResolvable,
toUser: UserIdResolvable,
allowNotifications?: boolean
): Promise<void> {
await this._client.callApi({
type: TwitchApiCallType.Helix,
url: 'users/follows',
method: 'POST',
scope: 'user:edit:follows',
jsonBody: {
from_id: extractUserId(fromUser),
to_id: extractUserId(toUser),
allow_notifications: allowNotifications
}
});
}

/**
* Removes a follow from a user to another user.
*
* @param fromUser The user to remove the follow for.
* @param toUser The user to unfollow.
*/
async deleteFollow(fromUser: UserIdResolvable, toUser: UserIdResolvable): Promise<void> {
await this._client.callApi({
type: TwitchApiCallType.Helix,
url: 'users/follows',
method: 'DELETE',
scope: 'user:edit:follows',
jsonBody: {
from_id: extractUserId(fromUser),
to_id: extractUserId(toUser)
}
});
}

private static _makeFollowsQuery(filter: HelixFollowFilter) {
const query: Record<string, string | undefined> = {};
let hasUserIdParam = false;
Expand Down

0 comments on commit 2ce5206

Please sign in to comment.