Skip to content

Commit 59a1cf1

Browse files
committed
アクセストークン,タグ関連の関数を追加
1 parent e6dc9da commit 59a1cf1

File tree

1 file changed

+121
-9
lines changed

1 file changed

+121
-9
lines changed

src/qiita.ts

Lines changed: 121 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export namespace Qiita {
225225

226226
}
227227

228+
228229
export class Qiita {
229230

230231
private token = '';
@@ -366,6 +367,39 @@ export class Qiita {
366367
return this.get(`${this.endpoint}${this.version}/items/${itemId}/likes`);
367368
}
368369

370+
/**
371+
* 与えられた認証情報をもとに新しいアクセストークンを発行します。
372+
* @param clientId 登録されたAPIクライアントを特定するためのID
373+
* @param clientSecret 登録されたAPIクライアントを認証するための秘密鍵
374+
* @param code リダイレクト用のURLに付与された、アクセストークンと交換するための文字列
375+
* @return アクセストークン
376+
*/
377+
public fetchAccessToken = (clientId: string, clientSecret: string, code: string): Promise<Qiita.AccessToken> => {
378+
return this.post(`${this.endpoint}${this.version}/access_tokens`, {
379+
client_id: clientId,
380+
client_secret: clientSecret,
381+
code,
382+
});
383+
}
384+
385+
/**
386+
* 指定されたアクセストークンを失効させ、それ以降利用できないようにします。
387+
* @param token アクセストークン
388+
* @return 空のオブジェクト
389+
*/
390+
public deleteAccessToken = (token: string): Promise<{}> => {
391+
return this.delete(`${this.endpoint}${this.version}/access_tokens/${token}`);
392+
}
393+
394+
/**
395+
* コメントを削除します。
396+
* @param commentId コメントのID
397+
* @return 空のオブジェクト
398+
*/
399+
public deleteComment = (commentId: string): Promise<{}> => {
400+
return this.delete(`${this.endpoint}${this.version}/comments/${commentId}`);
401+
}
402+
369403
/**
370404
* コメントを取得します。
371405
* @param commentId コメントのID
@@ -384,15 +418,6 @@ export class Qiita {
384418
return this.patch(`${this.endpoint}${this.version}/comments/${commentId}`, { body });
385419
}
386420

387-
/**
388-
* コメントを削除します。
389-
* @param commentId コメントのID
390-
* @return 空のオブジェクト
391-
*/
392-
public deleteComment = (commentId: string): Promise<{}> => {
393-
return this.delete(`${this.endpoint}${this.version}/comments/${commentId}`);
394-
}
395-
396421
/**
397422
* 投稿に付けられたコメント一覧を投稿日時の降順で取得します。
398423
* @param itemId 投稿のID
@@ -430,4 +455,91 @@ export class Qiita {
430455
public createCommentToProject = (projectId: string, body: string): Promise<Qiita.Comment[]> => {
431456
return this.post(`${this.endpoint}${this.version}/items/${projectId}/comments`, { body });
432457
}
458+
459+
/**
460+
* 投稿にタグを追加します。Qiita:Teamでのみ有効です。
461+
* @param itemId 投稿のID
462+
* @param name タグを特定するための一意な名前
463+
* @param versions (説明なし)
464+
*/
465+
public addTaggingToItem = (itemId: string, name: string, versions: string[]): Promise<Qiita.Tagging> => {
466+
return this.post(`${this.endpoint}${this.version}/items/${itemId}/taggings`, { name, versions });
467+
}
468+
469+
/**
470+
* 投稿から指定されたタグを取り除きます。Qiita:Teamでのみ有効です。
471+
* @param itemId 投稿のID
472+
* @param taggingId タギングのID
473+
* @return 空のオブジェクト
474+
*/
475+
public removeTaggingFromItem = (itemId, taggingId): Promise<{}> => {
476+
return this.delete(`${this.endpoint}${this.version}/items/${itemId}/taggings/${taggingId}`);
477+
}
478+
479+
/**
480+
* タグ一覧を作成日時の降順で返します。
481+
* @param page ページ番号 (1から100まで)
482+
* @param perPage 1ページあたりに含まれる要素数 (1から100まで)
483+
* @param sort 並び順 (countで投稿数順、nameで名前順)
484+
* @return タグ一覧
485+
*/
486+
public fetchTags = (page: string, perPage: string, sort: string): Promise<Qiita.Tag[]> => {
487+
return this.get(`${this.endpoint}${this.version}/tags`, {
488+
page,
489+
per_page: perPage,
490+
sort,
491+
});
492+
}
493+
494+
/**
495+
* タグを取得します。
496+
* @param tagId タグのID
497+
* @return タグ
498+
*/
499+
public fetchTag = (tagId: string): Promise<Qiita.Tag> => {
500+
return this.get(`${this.endpoint}${this.version}/tags/${tagId}`);
501+
}
502+
503+
/**
504+
* ユーザがフォローしているタグ一覧をフォロー日時の降順で返します。
505+
* @param userId ユーザーID
506+
* @param page ページ番号 (1から100まで)
507+
* @param perPage 1ページあたりに含まれる要素数 (1から100まで)
508+
* @return タグ一覧
509+
*/
510+
public fetchFollowingTags = (userId: string, page: string, perPage: string): Promise<Qiita.Tag[]> => {
511+
return this.get(`${this.endpoint}${this.version}/${userId}/following_tags`, {
512+
page,
513+
per_page: perPage,
514+
});
515+
}
516+
517+
/**
518+
* タグをフォローします。
519+
* @param tagId タグのID
520+
* @return 空のオブジェクト
521+
*/
522+
public unfollowTag = (tagId: string): Promise<{}> => {
523+
return this.delete(`${this.endpoint}${this.version}/tags/${tagId}/following`);
524+
}
525+
526+
/**
527+
* タグをフォローしているかどうかを調べます。
528+
* @param tagId タグのID
529+
* @return タグ
530+
*/
531+
public fetchIfFollowingTag = (tagId: string): Promise<Qiita.Tag> => {
532+
return this.get(`${this.endpoint}${this.version}/tags/${tagId}/following`);
533+
}
534+
535+
/**
536+
* タグをフォローします。
537+
* @param tagId タグのID
538+
* @return 空のオブジェクト
539+
*/
540+
public followTag = (tagId: string): Promise<Qiita.Tag> => {
541+
return this.put(`${this.endpoint}${this.version}/tags/${tagId}/following`);
542+
}
543+
544+
433545
}

0 commit comments

Comments
 (0)