Permalink
Browse files

add item api

  • Loading branch information...
1 parent e7aa8a5 commit 8f57e78f38e5dbc8aa7366d14304e0ce93d17231 percy committed Mar 28, 2013
Showing with 135 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 .npmignore
  3. +23 −1 lib/core.js
  4. +106 −0 lib/item.js
  5. +3 −3 taobao.js
View
@@ -1,2 +1,3 @@
node_modules
test.js
+*.sublime*
View
@@ -1,2 +1,3 @@
node_modules
-test.js
+test.js
+*.sublime*
View
@@ -21,7 +21,7 @@ var cfg = {
session: ''
};
-module.exports = {
+var core = module.exports = {
error: apierror,
config: function(config) {
@@ -178,5 +178,27 @@ module.exports = {
} else {
throw apierror.ARGINVALID;
}
+ },
+
+ generateApi: function(apiArr) {
+ apiArr = apiArr || [];
+ var api = {},
+ dotReg = /\.([a-z])/ig,
+ upperRep = function(all, letter) {
+ return letter.toUpperCase();
+ };
+
+ _.each(apiArr, function(apiObj) {
+ var method = apiObj.method;
+ var methodName = method.replace(dotReg, upperRep);
+
+ api[methodName] = function (httpArgs, args, callback) {
+ var defArg = apiObj.defaultArg;
+ core.callDefaultArg(defArg, httpArgs, args, callback);
+ };
+ });
+
+
+ return api;
}
};
View
@@ -0,0 +1,106 @@
+var core = require('./core');
+
+module.exports = core.generateApi([
+ {
+ method: 'aftersale.get'
+ }, {
+ method: 'item.add'
+ }, {
+ method: 'item.anchor.get'
+ }, {
+ method: 'item.bseller.add'
+ }, {
+ method: 'item.cseller.add'
+ }, {
+ method: 'item.delete'
+ }, {
+ method: 'item.get'
+ }, {
+ method: 'item.img.delete'
+ }, {
+ method: 'item.img.upload'
+ }, {
+ method: 'item.joint.img'
+ }, {
+ method: 'item.joint.propimg'
+ }, {
+ method: 'item.price.update'
+ }, {
+ method: 'item.propimg.delete'
+ }, {
+ method: 'item.propimg.upload'
+ }, {
+ method: 'item.quantity.update'
+ }, {
+ method: 'item.recommend.add'
+ }, {
+ method: 'item.recommend.delete'
+ }, {
+ method: 'item.sku.add'
+ }, {
+ method: 'item.sku.delete'
+ }, {
+ method: 'item.sku.get'
+ }, {
+ method: 'item.sku.price.update'
+ }, {
+ method: 'item.sku.update'
+ }, {
+ method: 'item.skus.get'
+ }, {
+ method: 'item.templates.get'
+ }, {
+ method: 'item.update'
+ }, {
+ method: 'item.update.delisting'
+ }, {
+ method: 'item.update.listing'
+ }, {
+ method: 'items.custom.get'
+ }, {
+ method: 'item.inventory.get'
+ }, {
+ method: 'items.list.get'
+ }, {
+ method: 'items.onsale.get'
+ }, {
+ method: 'product.add'
+ }, {
+ method: 'product.get'
+ }, {
+ method: 'product.img.delete'
+ }, {
+ method: 'product.img.upload'
+ }, {
+ method: 'product.propimg.delete'
+ }, {
+ method: 'product.propimg.upload'
+ }, {
+ method: 'product.update'
+ }, {
+ method: 'products.get'
+ }, {
+ method: 'products.search'
+ }, {
+ method: 'skus.custom.get'
+ }, {
+ method: 'skus.quantity.update'
+ }, {
+ method: 'topats.items.all.get'
+ }, {
+ method: 'ump.promotion.get'
+ }, {
+ method: 'brandcat.control.get'
+ }, {
+ method: 'brandcat.salespro.get'
+ }, {
+ method: 'product.spec.add'
+ }, {
+ method: 'product.spec.get'
+ }, {
+ method: 'product.spec.pic.upload'
+ }, {
+ method: 'product.specs.get'
+ }
+]);
+
View
@@ -1,8 +1,8 @@
var _ = require('underscore'),
core = require('./lib/core'),
user = require('./lib/user'),
- itemcats = require('./lib/itemcats');
-
+ itemcats = require('./lib/itemcats'),
+ item = require('./lib/item');
module.exports = {
config: function (config) {
@@ -18,4 +18,4 @@ module.exports = {
core: core
};
-_.extend(module.exports, user, itemcats);
+_.extend(module.exports, user, itemcats, item);

0 comments on commit 8f57e78

Please sign in to comment.