话说,Top API SDK默认只给了四种语言的SDK,没有我大NodeJS,这可怎么行,于是封装了一个。

参考地址

GitHub: https://github.com/xiaoppp/TopAPI-Node

NPM: https://www.npmjs.com/package/topapi-node

TopAPI SDK for Node.js

Using Es6 promise, all api return promise.

Platform Compatibility

Using Promise, Generator features of ES6

When using node 0.11.x or greater, you must use the --harmony-generators flag or just --harmony to get access to generators.

When using node 0.10.x and lower or browsers without generator support, you must use gnode and/or regenerator.

io.js is supported out of the box, you can use co without flags or polyfills.

Install

$ npm install topapi-node

Usage

var Top = require("topapi-node");

var top = new Top({
appKey:"",
appSecret: "",
sessionKey: ""
}); var params = {
page_size: 200,
fields: "num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
} top.taobao_items_onsale_get(params).then(
(data) => {
console.log(data);
},
(err) => console.log(err)
)

Extend Top Apis

Since topAPI has huge APIs, and this only implements some of them, so you have two ways to extend that, both of them were fine.
Maybe the best way is contribute your code into lib/apis file. :) First way, you can extend the TOPAPI prototype Top.prototype.taobao_items_onsale_get = function(params) {
let self = this;
let method = "taobao.items.onsale.get";
return new Promise((resolve, reject) => {
self.postAPI(method, params).then(
(body) => {resolve(body.items_onsale_get_response);},
(err) => reject(err)
);
});
} Second way, postAPI to server let method = "taobao.items.onsale.get"; var params = {
page_size: 200,
fields: "num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
} top.postAPI(method, params).then(
(body) => {
console.log(body);
},
(err) => console.log(err)
)

Process Control

Suggest to use CO for process control

co(function*() {
let param = {
parent_id: 0,
picture_category_name: "test"
}; let category = yield top.taobao_picture_category_get(param); if (category) {
category = yield top.taobao_picture_category_add(param);
} return Promise.resolve(category);
}

License

(c) Fork Ltd. Licensed under the MIT license.

Using ES6 features Promise Array Function Generator

个人觉得目前 最好用的Taobao API的NodeJS封装的更多相关文章

  1. Atitit. C# java 的api 文件夹封装结构映射总结

    Atitit. C#  java 的api 文件夹封装结构映射总结 C# java ref System.Reflection System.Type. java.lang.ref concurren ...

  2. 基于V2EX API的nodejs组件.

    今天又学习到了新的知(zi)识(shi),来给自己做个笔录,也算在这酷热的天气里给自己写了一篇降温的‘膏药’,话就讲这么多了 ,start off...... 首先 ,依赖选择: /**设置为严格模式 ...

  3. 循序渐进VUE+Element 前端应用开发(13)--- 前端API接口的封装处理

    在前面随笔<循序渐进VUE+Element 前端应用开发(12)--- 整合ABP框架的前端登录处理>介绍了一个系统最初接触到的前端登录处理的实现,但往往对整个系统来说,一般会有很多业务对 ...

  4. 必应API接口nodejs版

    近期,在研究百度.必应.API等的url提交API时,发现有用Go语言做工具的大佬的分享 利用 API 自动向搜索引擎提交网址(Go语言版) - pyList. 其中提到bing API提交方法,并给 ...

  5. 依图语音API的C#封装以及调用进行语音转写的处理

    对于语音识别,一般有实时语音识别和语音文件的识别处理等方式,如在会议.培训等场景中,可以对录制的文件进行文字的转录,对于转录文字的成功率来说,如果能够转换90%以上的正确语音内容,肯定能减轻很多相关语 ...

  6. Get Region Information from IP Address with Taobao API

    通过淘宝的API "http://ip.taobao.com/service/getIpInfo.php?ip=*.*.*.*" 来获得你要查询的IP地址的国家,地区,城市,ISP ...

  7. 火币网api的nodejs实现

    var request = require('request'); var crypto = require('crypto'); var config = { api_url: 'https://a ...

  8. Android 音视频开发(五):使用 MediaExtractor 和 MediaMuxer API 解析和封装 mp4 文件

    一个音视频文件是由音频和视频组成的,我们可以通过MediaExtractor.MediaMuxer把音频或视频给单独抽取出来,抽取出来的音频和视频能单独播放: 一.MediaExtractor API ...

  9. $微信小程序开发实践点滴——Bmob基本REST API的python封装

    Refer:Bmob后端云REST API接口文档:http://docs.bmob.cn/data/Restful/a_faststart/doc/index.html 本文使用python对Bmo ...

随机推荐

  1. MySQL入门(一)

    最近一直都在搞新员工的培训材料,MySQL的培训PPT我居然写了100多页,我都佩服我自己的毅力了.不如现在把这些总结一下,慢慢写到博客里,供入门者参考. 一 关系型数据库 关系型数据库的理论提出于上 ...

  2. DGbroker三种保护模式的切换

    1.三种保护模式 – Maximum protection 在Maximum protection下, 可以保证从库和主库数据完全一样,做到zero data loss.事务同时在主从两边提交完成,才 ...

  3. 烂泥:Linux系统与windows系统文件同步

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 上篇文章中,我们介绍了有关Linux系统之间的文件同步,这篇文章我们来介绍下,有关Linux系统与windows系统,以及windows系统与windo ...

  4. 解决内网主机ping不通网关能ping内网

    有一台笔记本电脑可以自动获取IP,可以和内网其他主机互相PING通,就是PING 不通网关,只能上内网,不能上外网,IP换到其他主机上也可以上外网,说明路由器上没什么限制.路由器也查了,电脑也重装了, ...

  5. mysql 远程访问控制

    如需要让192.168.2.3的test用户可以访问本机所有数据库,mysql命令如下 mysql>GRANT ALL PRIVILEGES ON *.* TO 'test'@'192.168. ...

  6. Arch Linux sudo: PAM authentication error: Module is unknown [Solved!]

    问题描述: 我的 Arch Linux 已经用了快半年多,由于 Arch Linux 的滚挂问题,我从没有直接升级过系统.软件版本以及库自然落后了一些. 就在我准备需要用到 NFS 时,挂载网络文件系 ...

  7. 【HTML5】嵌入另一张HTML文档、通过插件嵌入内容、嵌入数字表现形式

    1.嵌入另一张HTML文档 iframe 元素允许在现有的HTML文档中嵌入另一张文档.下面代码展示了iframe元素的用法: <!DOCTYPE html> <html lang= ...

  8. [No00005D]如何高效利用GitHub

    原文地址:http://www.yangzhiping.com/tech/github.html 正是Github,让社会化编程成为现实.本文尝试谈谈GitHub的文化.技巧与影响. Q1:GitHu ...

  9. java 接口(上)

    1.接口中的方法都是抽象方法.而普通的抽象类里面不一定都是抽象方法.抽象类中必须有抽象方法,同时也可以有非抽象方法.继承抽象父类的子类中,如果依然有抽象方法,那么这个子类也是抽象类.即只要类中有抽象方 ...

  10. javascript一些小问题

    1.async 类型:Boolean 默认值: true.默认设置下,所有请求均为异步请求.如果需要发送同步请求,请将此选项设置为 false. 注意,同步请求将锁住浏览器,用户其它操作必须等待请求完 ...