Skip to content

Commit

Permalink
✨ get comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shawjia committed Oct 17, 2018
1 parent d632f23 commit 5726ef7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ country 为可选,如果不传,当 86 处理

返回单篇文章详情

### articles(aid, size = 200, prev = 0)

返回专栏文章评论

### audios(cid, size = 1000)

返回音频列表
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const links = {
intro: `${host}/column/intro`,
articles: `${host}/column/articles`,
article: `${host}/article`,
comments: `${host}/comments`,
audios: `${host}/column/audios`,
};
const CN_CODE = '86';
Expand Down Expand Up @@ -104,6 +105,13 @@ class Geektime {
return request(links.article, { id }, cookie);
}

// 文章评论
async comments(aid, size = 200, prev = 0) {
const cookie = await this.getCookie();

return request(links.comments, { aid, size, prev }, cookie);
}

// 音频列表
async audios(cid, size = 1000) {
const cookie = await this.getCookie();
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ test('client.article(14271)', async (t) => {
t.true(res.article_title.startsWith('95 | 高效学习'));
});

test('client.comments(14271)', async (t) => {
const res = await client.comments(articleId, 1);

t.true(res.list.length > 0);
});

test('client.audios(48)', async (t) => {
const res = await client.audios(cid);

Expand Down

0 comments on commit 5726ef7

Please sign in to comment.