Skip to content
Browse files

updated README

  • Loading branch information...
1 parent ef3e7da commit 333cf1276bcf9094741da37e1e890f3cde140d2d @awhy awhy committed Apr 19, 2010
View
76 README
@@ -1,76 +0,0 @@
-Intro
-======
-
-TaobaoFu is a Rails plugin as an unofficial Ruby SDK for the Taobao Open Platform.
-
-
-Dependencies
-=======
-
-Currently, this TOP-SDK dependents on several plugins/gems. Before you run the plugin, you need to install them first.
-
- >> ruby script/plugin install git://github.com/adamwiggins/rest-client.git # for the development environment.
- >> ruby script/plugin install git://github.com/jnunemaker/crack.git
-
-If you are using git with your Rails project, maybe you need to install them as git submodules:
-
- >> git submodule add git://github.com/adamwiggins/rest-client.git vendor/plugins/rest-client
- >> git submodule add git://github.com/jnunemaker/crack.git vendor/plugins/crack
- >> git submodule init
- >> git submodule update
-
-Recommend you use gem Patron instead of the rest-client if your Rails app is runing on a Unix/Linux/MacOSX machine. Patron is a more powerful and stable Ruby HTTP client based on libcurl. For more details about Patron, see http://github.com/toland/patron .
-
- >> sudo gem install patron
-
-After installed patron, you need to modify the config/taobao.yml file, ensure the :enable_curl option is true(default is false in the development environment).
-
-
-Install
-=======
-
-Well, assuming you have already installed rest-client(or Patron) and Crack, It's time to install our plugin.
-
- >> ruby script/plugin install git://github.com/404/taobao_fu.git
- >> ruby script/generate taobao # This command will create a TOP configuration file named taobao.yml under the config/ directory.
-
-It's the same as the previous operation that you can install it as a git submodule.
-
-
-Usage
-=======
-
-You need to configure config/taobao.yml first.
-
-There are four methods mapping HTTP GET/POST/PUT/DELETE verbs.
-
-Taobao.get #(Available)
-Taobao.post
-Taobao.update
-Taobao.delete
-
-
-Example
-=======
-
-This example used a real TOP account and ran under the production environment, so it can access the online database of taobao.com. See config/taobao.yml for more details.
-
- > cd your_rails_app
- > ruby script/console
- >> Taobao.get(:method => 'taobao.item.get',
- :nick => 'simul官方旗舰店',
- :iid => '3b54462a34e2ed84c330dc3e5fb4a94f',
- :fields => 'title, price')
-
-
-Future
-=======
-
-Add more and more methods, like Taobao::Item.get, etc.
-Full Chinese documentation support.
-
-
-Copyright
-=======
-
-Copyright (c) 2009 why404, released under the MIT license.
View
2 README.markdown
@@ -50,7 +50,7 @@ config/taobao.yml:
production:
<<: *defaults
- is_sandbox: true
+ is_sandbox: false
use_curl: true
View
8 generators/taobao/USAGE
@@ -1,8 +0,0 @@
-Description:
- Creates the Taobao configuration file.
-
-Example:
-
- ./script/generate taobao
-
-This command will create a TOP configuration file named taobao.yml under the config/ directory.
View
11 generators/taobao/taobao_generator.rb
@@ -1,11 +0,0 @@
-class TaobaoGenerator < Rails::Generator::Base
-
- def manifest
- record do |m|
- m.directory 'config'
- m.file 'taobao.yml', 'config/taobao.yml'
- end
- end
-
-end
-
View
20 generators/taobao/templates/taobao.yml
@@ -1,20 +0,0 @@
-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, then you should install gem "patron" first and bundle it in your rails application.
-
-test:
- <<: *defaults
- is_sandbox: ture
- use_curl: false
-
-production:
- <<: *defaults
- is_sandbox: true
- use_curl: true
View
2 lib/generators/templates/taobao.yml
@@ -16,5 +16,5 @@ test:
production:
<<: *defaults
- is_sandbox: true
+ is_sandbox: false
use_curl: true
View
103 lib/taobao.rb
@@ -1,103 +0,0 @@
-begin
- require "crack"
-rescue LoadError
- puts "The Crack gem is not available.\nIf you ran this command from a git checkout " \
- "of Rails, please make sure crack is installed. \n "
- exit
-end
-# require "patron"
-require "digest/md5"
-require "yaml"
-require "uri"
-require 'rest_client'
-
-module Taobao
-
- SANDBOX = 'http://gw.api.tbsandbox.com/router/rest?'
- PRODBOX = 'http://gw.api.taobao.com/router/rest?'
- USER_AGENT = 'why404-taobao_fu/0.0.1'
- REQUEST_TIMEOUT = 10
- API_VERSION = 1.0
- OUTPUT_FORMAT = 'json'
-
- class << self
- def load(config_file)
- if FileTest::exists?(config_file)
- @settings = YAML.load_file(config_file)
- @settings = @settings[RAILS_ENV] if defined? RAILS_ENV
- apply_settings
- end
- end
-
- def apply_settings
- ENV['TAOBAO_API_KEY'] = @settings['api_key'].to_s
- ENV['TAOBAO_SECRET_KEY'] = @settings['secret_key']
- ENV['TAOBAOKE_PID'] = @settings['taobaoke_pid']
- @base_url = @settings['is_sandbox'] ? SANDBOX : PRODBOX
-
- initialize_session if @settings['use_curl']
- end
-
- def initialize_session
- @sess = Patron::Session.new
- @sess.base_url = @base_url
- @sess.headers['User-Agent'] = USER_AGENT
- @sess.timeout = REQUEST_TIMEOUT
- end
-
- def switch_to(sandbox_or_prodbox)
- @base_url = sandbox_or_prodbox
- @sess.base_url = @base_url if @sess
- end
-
- def get(options = {})
- if @sess
- @response = @sess.get(generate_query_string(sorted_params(options))).body
- else
- @response = TaobaoFu::Rest.get(@base_url, generate_query_vars(sorted_params(options)))
- end
- parse_result @response
- end
-
- # http://toland.github.com/patron/
- def post(options = {})
- end
-
- def update(options = {})
- end
-
- def delete(options = {})
- end
-
- def sorted_params(options)
- {
- :app_key => @settings['app_key'],
- :format => OUTPUT_FORMAT,
- :v => API_VERSION,
- :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S")
- }.merge!(options)
- end
-
- def generate_query_vars(params)
- params[:sign] = generate_sign(params.sort_by { |k,v| k.to_s }.flatten.join)
- params
- end
-
- def generate_query_string(params)
- params_array = params.sort_by { |k,v| k.to_s }
- sign_token = generate_sign(params_array.flatten.join)
- total_param = params_array.map { |key, value| key.to_s+"="+value.to_s } + ["sign=#{sign_token}"]
- URI.escape(total_param.join("&"))
- end
-
- def generate_sign(param_string)
- Digest::MD5.hexdigest(@settings['secret_key'] + param_string).upcase
- end
-
- def parse_result(data)
- Crack::JSON.parse(data)['rsp'] || Crack::JSON.parse(data)['error_rsp']
- end
-
- end
-
-end
View
4 tasks/taobao_tasks.rake
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :taobao do
-# # Task goes here
-# end
View
8 test/taobao_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class TaobaoTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
3 test/test_helper.rb
@@ -1,3 +0,0 @@
-require 'rubygems'
-require 'active_support'
-require 'active_support/test_case'

0 comments on commit 333cf12

Please sign in to comment.
Something went wrong with that request. Please try again.