Skip to content

Latest commit

 

History

History
83 lines (53 loc) · 2.48 KB

README.markdown

File metadata and controls

83 lines (53 loc) · 2.48 KB

About TaobaoFu

TaobaoFu is a Ruby gem (also can be a Rails plugin, supports Rails 3.0.0 or above) as an unofficial Ruby SDK for the Taobao Open Platform(http://open.taobao.com/).

Compatibility

TaobaoFu is developed against Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2

Installation

Get the TaobaoFu gem from rubygems.org:

gem install taobao_fu --pre

Or install it as a Rails plugin:

rails plugin install git://github.com/why404/taobao_fu.git

For Rails applications add the gem dependency to your Gemfile:

gem "crack"
gem "patron"    # Optional, if you set the :use_curl option is true in config/taobao.yml 
gem "taobao_fu" # not required if you installed it as a Rails plugin.

Setup of access the TOP API is handled by using automatic configuration with a config/taobao.yml. You can generate a taobao.yml via the following command:

rails generate taobao_fu config

An example configuration is as follows, with the default values showing: config/taobao.yml:

defaults: &defaults
  app_key:          # YOUR_APP_KEY
  secret_key:       # YOUR_APP_SECRET_TOKEN
  taobaoke_pid:     # YOUR_TAOBAOKE_PID
  taobaoke_nick:    # YOUR_TAOBAOKE_NICKNAME

development:
  <<: *defaults
  is_sandbox: false # If true, it will work under the sandbox environment(tbsandbox.com, not taobao.com).
  use_curl: false   # If true, it will use gem "patron" as the REST client.

test:
  <<: *defaults
  is_sandbox: ture
  use_curl: false

production:
  <<: *defaults
  is_sandbox: false
  use_curl: true

Example

Here is an example shows you how to get some information of a commodity from taobao.com by using the TaobaoFu.get method.

> cd your_rails_app
> rails console
> TaobaoFu.get(:method => 'taobao.item.get', 
               :nick   => 'simul官方旗舰店', 
               :iid    => '3b54462a34e2ed84c330dc3e5fb4a94f', 
               :fields => 'title, price')

There are four methods mapping HTTP verbs(GET/POST/PUT/DELETE).

TaobaoFu.get    #(Available)
TaobaoFu.post
TaobaoFu.update
TaobaoFu.delete

There is also an additional method is using for switching between sandbox and production environment of TOP. For instance:

TaobaoFu.switch_to(TaobaoFu::SANDBOX) # switching to sandbox(tbsandbox.com)
TaobaoFu.switch_to(TaobaoFu::PRODBOX) # back to production environment(taobao.com)

License

Copyright (c) 2010 why404(why404#gmail), released under the MIT license.