Skip to content

Commit

Permalink
特性✨(custom): columns
Browse files Browse the repository at this point in the history
增加 Items
- 初始化方式修改为单例模式
  • Loading branch information
bubao committed Aug 25, 2022
1 parent 794a426 commit 7383762
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 43 deletions.
29 changes: 15 additions & 14 deletions src/api/Columns/Articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author: bubao
* @Date: 2020-07-21 18:21:28
* @LastEditors: bubao
* @LastEditTime: 2020-07-21 22:33:42
* @LastEditTime: 2022-08-25 10:49:17
*/
const Base = require("../Base");
const API = require("../../config/api/index");
Expand All @@ -25,19 +25,6 @@ class Articles extends Base {
*/
constructor (columnsId) {
super();
if (columnsId) {
this.init(columnsId);
}
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Articles
*/
init (columnsId) {
this.ReqOps = {
...this.ReqOps,
...{
Expand All @@ -49,6 +36,20 @@ class Articles extends Base {
this.columnsId = columnsId;
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Articles
*/
static init (columnsId) {
if (!this.instance) {
this.instance = new Articles(columnsId);
}
return this.instance;
}

/**
* @description 知乎专栏信息
* @author bubao
Expand Down
40 changes: 19 additions & 21 deletions src/api/Columns/Followers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author: bubao
* @Date: 2020-07-21 18:40:15
* @LastEditors: bubao
* @LastEditTime: 2020-09-15 15:56:32
* @LastEditTime: 2022-08-25 11:13:28
*/
const Base = require("../Base");
const API = require("../../config/api/index");
Expand All @@ -22,37 +22,35 @@ class Followers extends Base {
* @author bubao
* @date 2020-07-21
* @param {string} columnsId 专栏id
* @param {headers} ReqOps request options
* @memberof Articles
* @memberof Followers
*/
constructor (columnsId, ReqOps = {}) {
constructor (columnsId) {
super();
if (columnsId) {
this.init(columnsId, ReqOps);
}
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId 专栏id
* @param {headers} ReqOps request options
* @memberof Articles
*/
init (columnsId, ReqOps = {}) {
this.ReqOps = {
...this.ReqOps,
...{
json: true,
uri: API.columns.followers({ columnsId })
},
...ReqOps
uri: API.columns.Followers({ columnsId })
}
};
this._next = this.ReqOps.uri;
this.columnsId = columnsId;
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Followers
*/
static init (columnsId) {
if (!this.instance) {
this.instance = new Followers(columnsId);
}
return this.instance;
}

/**
* @description 知乎专栏信息
* @author bubao
Expand Down
66 changes: 66 additions & 0 deletions src/api/Columns/Items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @Description:
* @Author: bubao
* @Date: 2022-08-25 10:43:14
* @LastEditors: bubao
* @LastEditTime: 2022-08-25 11:07:12
*/

const Base = require("../Base");
const API = require("../../config/api/index");
const { info } = require("./single");
/**
* @description 知乎专栏文章
* @author bubao
* @date 2020-07-21
* @class Items
* @extends {Base}
*/
class Items extends Base {
/**
*Creates an instance of Items.
* @author bubao
* @date 2020-07-21
* @param {string} columnsId 专栏id
* @memberof Items
*/
constructor (columnsId) {
super();
this.ReqOps = {
...this.ReqOps,
...{
json: true,
uri: API.columns.items({ columnsId })
}
};
this._next = this.ReqOps.uri;
this.columnsId = columnsId;
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Items
*/
static init (columnsId) {
if (!this.instance) {
this.instance = new Items(columnsId);
}
return this.instance;
}

/**
* @description 知乎专栏信息
* @author bubao
* @date 2020-07-21
* @returns
* @memberof Items
*/
info () {
return info(this.columnsId);
}
}

module.exports = Items;
4 changes: 3 additions & 1 deletion src/api/Columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
* @Author: bubao
* @Date: 2018-02-13 15:09:44
* @LastEditors: bubao
* @LastEditTime: 2020-07-21 23:02:23
* @LastEditTime: 2022-08-25 11:14:20
*/

const Articles = require("./Articles");
const Followers = require("./Followers");
const Items = require("./Items");
const { info, coauthors } = require("./single");

module.exports = {
info,
Articles,
Items,
Followers,
coauthors
};
3 changes: 2 additions & 1 deletion src/config/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: bubao
* @Date: 2018-05-17 12:27:02
* @LastEditors: bubao
* @LastEditTime: 2020-09-15 15:54:56
* @LastEditTime: 2022-08-25 10:44:04
*/

const zhihu = "https://www.zhihu.com";
Expand Down Expand Up @@ -176,6 +176,7 @@ module.exports = {
},

columns: {
items: ({ columnsId }) => `${zhihu}/api/v4/columns/${columnsId}/items`,
/**
* 基本信息
* @param {{columnsId:string}}
Expand Down
11 changes: 5 additions & 6 deletions test/Columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
* @author: bubao
* @Date: 2020-07-20 05:57:38
* @LastEditors: bubao
* @LastEditTime: 2022-08-25 10:20:02
* @LastEditTime: 2022-08-25 11:11:55
*/
const { Columns } = require("../src/api");
const Items = require("../src/api/Columns/Items");
const { console } = require("../src/config/commonModules");

const columns = Columns.init();

// /**
// * 获取专栏基础信息
// */
Expand Down Expand Up @@ -66,10 +64,11 @@ const columns = Columns.init();
// test("YJango");

async function test (columnsID) {
const columns = Items.init(columnsID);
/**
* 获取专栏基础信息
*/
const Info = await columns.info(columnsID);
const Info = await columns.info();
if (Info.error) {
return Info.error;
}
Expand All @@ -87,7 +86,7 @@ async function test (columnsID) {
/**
* 获取文章简介
*/
const items = await columns.items(columnsID, next);
const items = await columns.next();
if (items.error) {
break;
}
Expand Down

0 comments on commit 7383762

Please sign in to comment.