top.js

0.0.8 • Public • Published

top.js

Build Status

Taobao Open Platform API for node.js.

Use as a library

Install

npm install top.js

Usage

var topClient = require('top.js').createClient({
    app_key: 'Your Key'
  , app_secret: 'Your Secret'
  , debug: true
})

topClient.query('taobao.item.get', {
    fields: 'num_iid'
  , num_iid: 16289288120
}, function(err, o) {
  if (err) console.error(err)
  else console.log(o)
})

Use Proxy (nodejs >= 0.11 with node --harmony)

topClient.proxy().taobao().item().get({
    fields: 'num_iid'
  , num_iid: 16289288120
}).done(function(err, o) {
  if (err) console.error(err)
  else console.log(o)
})

A cache middleware for connect / express

var redis = require('redis').createClient()
var app = require('express')()

app.use(require('top.js').createClient({
    app_key: 'Your Key'
  , app_secret: 'Your Secret'
}).express({
    get: function(hash, cb) {
      redis.get(hash, cb)
    }
  , set: function(hash, data, cb) {
      redis.multi().set(hash, data).expire(hash, 3600 * 24).exec(cb)
    }
}))

app.get('/item/:id', funtion(req, res) {
  res.top('taobao.taobaoke.items.detail.get', {
      fields: 'click_url'
    , num_iids: req.params.id
  }, function(err, data) {
    if (err) return res.send(500, err.toString())
    res.send(data)
  })
})

Use as a command-line tool

Install

$ npm install top.js -g

Usage

Put TOP_APP_KEY and TOP_APP_SECRET in your environment variables

export TOP_APP_KEY={your key}
export TOP_APP_SECRET={your secret}

First try

$ top-cli --api taobao.item.get --fields cid --num_iid=19731060339
{
    item: { cid: 50006846 }
}

Even for array like arguments

$ top-cli --api taobao.item.get --fields cid --fields num_iid --num_iid=19731060339
{
    item: { cid: 50006846, num_iid: 19731060339 }
}

If you need plain json data for piping purpose or something, use --plain

$ top-cli --plain --api taobao.item.get --fields cid --fields num_iid --num_iid=19731060339
{"item":{"cid":50006846,"num_iid":19731060339}}

LICENSE

Copyright (c) 2012-2013 Frank Xu

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i top.js

Weekly Downloads

0

Version

0.0.8

License

none

Last publish

Collaborators

  • yyfrankyy