New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

taobao-openapi

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

taobao-openapi - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

src/index.js

113

index.js

@@ -1,112 +0,1 @@

var _ = require("underscore");
var request = require("request");
var md5 = require("md5");
var moment = require("moment");
var qs = require('querystring');
module.exports = Taobao;
/**
* default configuration
*/
var cfg = {
debug: false,
https: false,
path: '/router/rest',
httpRealHost: 'http://gw.api.taobao.com',
httpSandHost: 'http://gw.api.tbsandbox.com',
httpsRealHost: 'https://eco.taobao.com',
httpsSandHost: 'https://gw.api.tbsandbox.com'
};
/**
* api client constructor
*
* @param {Object} config
* @constructor
*/
function Taobao(config) {
this.config = {};
_.extend(this.config, cfg, config);
}
/**
* reset the config
*
* @param {Object} config
*/
Taobao.prototype.config = function (config) {
_.extend(this.config, config);
};
/**
* get request
*
* @param {String} method
* @param {Object} [config]
* @param {Object} args
* @param {Function} callback
*/
Taobao.prototype.get = function () {
//arguments
var method = "";
var config = {};
var args = {};
var callback;
if (arguments.length == 3) {
method = arguments[0];
args = arguments[1];
callback = arguments[2];
} else if (arguments.length == 4) {
method = arguments[0];
config = arguments[1] || {};
args = arguments[2];
callback = arguments[3];
}
_.extend(args, {method: method});
var format_args = formatArgs(args, this.config);
var host = this.config.debug ?
(this.config.https ? this.config.httpsSandHost : this.config.httpSandPath) :
(this.config.https ? this.config.httpsRealHost : this.config.httpRealHost);
var uri = host + this.config.path + "?" + format_args;
var option = {
method: "GET",
uri: uri
};
request(option, function (error, response, body) {
if (error) {
return callback(error);
}
callback(null, body);
});
};
function formatArgs(args, config) {
args.timestamp = moment().format("YYYY-MM-DD HH:mm:ss");
args.format = "json";
args.v = "2.0";
args.sign_method = "md5";
args.app_key = config.app_key;
args.sign = signArgs(args, config);
return qs.stringify(args);
}
function signArgs(args, config) {
var argsArr = [];
for (var arg in args) {
argsArr.push(arg + args[arg]);
}
return md5(config.app_secret + argsArr.sort().join('') + config.app_secret).toUpperCase();
}
module.exports = require("./src");
{
"name": "taobao-openapi",
"version": "0.1.0",
"version": "0.2.0",
"description": "package for taobao open api",

@@ -5,0 +5,0 @@ "main": "index.js",

# taobao-openapi
api client for taobao open platform
淘宝开放平台SDK,用于node平台
# Install
npm install taobao-openapi --save
# Examlpe
var Taobao = require("taobao-openapi");
var top = new Taobao({
app_key: "yourAppKey",
app_secret: "yourAppSecret"
});
top.get("taobao.shop.get", {
nick: "nickname",
fields: "sid,cid,nick,title,desc,shop_score"
}, function(err, body){
if(err){
return console.log(err);
}
console.log(body);
});
top.post("taobao.shop.get", {
nick: "nickname",
fields: "sid,cid,nick,title,desc,shop_score"
}, function(err, body){
if(err){
return console.log(err);
}
console.log(body);
});
# API
get请求:
top.get(method, [config], args, callback)
method:api接口名称
config:可选,配置对象,只对当前请求有效
args:接口参数
callback:回调函数,包含错误参数err和响应body
top.post(method, [config], args, callback)
method:api接口名称
config:可选,配置对象,只对当前请求有效
args:接口参数
callback:回调函数,包含错误参数err和响应body
# Features
1、configure
配置全局参数
top.configure({
session: "yourSession"
});
### 目前有效参数:
| attribute | description | default |
| -------------|:-------------:| -----: |
| session | session | null |
| debug | 是否开启沙箱 | false |
| https | https请求 | false |
目前只支持json响应格式,不支持xml格式;
目前只支持MD5加密方法;
欢迎fork!

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc