topsdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in topsdk.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ --------------------------------------------------------------------
2
+
3
+ = Overview
4
+
5
+ The plugin enable easy integration with the [Taobao Open Platform]: http://open.taobao.com/doc/api_list.htm?id=102
6
+
7
+ == Installation and configuration
8
+
9
+ Create a config/taobao.yml
10
+
11
+ development:
12
+ api_key: your_api_key
13
+ secret_key: your_secret_key
14
+ format: json
15
+ host: sandbox
16
+
17
+ test:
18
+ api_key:
19
+ secret_key:
20
+ format: xml
21
+ host: sandbox
22
+
23
+ production:
24
+ api_key:
25
+ secret_key:
26
+ format: json
27
+ host: sandbox
28
+
29
+
30
+ == Usage
31
+
32
+ params = {
33
+ :session => 'your_session',
34
+ :method =>'taobao.trades.sold.get',
35
+ :fields => 'tid,seller_nick,status,payment,trade_memo,seller_memo',
36
+ :buyer_nick => 'zhangsan',
37
+ :start_created => '2010-09-27 00:00:00',
38
+ :end_date => '2011-09-27 23:00:00',
39
+ :page_size => 2
40
+ }
41
+ Topsdk.get_with(params)
42
+ # => {"trades"=>{"trade"=>[{"payment"=>"212.00", "seller_nick"=>"zhangsan", "status"=>"WAIT_BUYER_PAY", "tid"=>112344931158}, {"payment"=>"11.00", "seller_nick"=>"zhangsan", "status"=>"WAIT_SELLER_SEND_GOODS", "tid"=>112474782358}]}, "total_results"=>117}
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ begin
3
+ require 'nestful'
4
+ rescue LoadError
5
+ puts "The Nestful gem is not available.\nIf you ran this command from a git checkout " \
6
+ "of Rails, please make sure nestful is installed. \n "
7
+ exit
8
+ end
9
+ require 'digest/md5'
10
+
11
+ module Topsdk
12
+ class Client
13
+ DEBUG = false
14
+
15
+ def initialize(params={}, options = {})
16
+ @options = {
17
+ :headers => { 'User-Agent' => USER_AGENT },
18
+ :timeout => REQUEST_TIMEOUT,
19
+ :method => :get,
20
+ :format => ENV['TAOBAO_OUTPUT_FORMAT'].to_sym,
21
+ :params => {
22
+ :app_key => ENV['TAOBAO_APP_KEY'],
23
+ :format => ENV['TAOBAO_OUTPUT_FORMAT'],
24
+ :v => API_VERSION,
25
+ :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
26
+ },
27
+ }
28
+ # 合併請求參數
29
+ @options.merge!(options.clone) unless options.empty?
30
+ # 合併淘寶參數
31
+ @options[:params].merge!(params.clone) unless params.empty?
32
+ # 請淘寶求簽名
33
+ str = ENV['TAOBAO_APP_SECRET'] + @options[:params].sort.flatten.join
34
+ @options[:params][:sign] = Digest::MD5.hexdigest(str).upcase!
35
+ end
36
+
37
+ def result
38
+ # trade_memo_update_response
39
+ response_key = @options[:params][:method][7..-1].gsub(/\./, '_') + "_response"
40
+ # trade
41
+ root_key = response_key.split('_')[0]
42
+ res = Nestful::Request.new(ENV['TAOBAO_REST_ENDPOINT'], @options).execute
43
+ case ENV['TAOBAO_OUTPUT_FORMAT']
44
+ when 'xml'
45
+ res['msg'] || res
46
+ when 'json'
47
+ res[response_key] || res['error_response']['msg']
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Topsdk
2
+ VERSION = "0.0.1"
3
+ end
data/lib/topsdk.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "topsdk/version"
2
+ require "topsdk/client"
3
+
4
+ module Topsdk
5
+ class << self
6
+ def get_with(joined_params = {})
7
+ Client.new(joined_params).result
8
+ end
9
+
10
+ def post_with(joined_params = {})
11
+ Client = Service.new(joined_params).result
12
+ end
13
+ end
14
+ end
data/topsdk.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "topsdk/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "topsdk"
7
+ s.version = Topsdk::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Howl王"]
10
+ s.email = ["howl.wong@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = "Taobao API client"
13
+ s.description = %q{Simple Taobao API client for Ruby}
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+
18
+ s.rubyforge_project = "topsdk"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_runtime_dependency "nestful"
26
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: topsdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Howl王
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nestful
16
+ requirement: &70258300447040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70258300447040
25
+ description: Simple Taobao API client for Ruby
26
+ email:
27
+ - howl.wong@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files:
31
+ - README.rdoc
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/topsdk.rb
38
+ - lib/topsdk/client.rb
39
+ - lib/topsdk/version.rb
40
+ - topsdk.gemspec
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: topsdk
61
+ rubygems_version: 1.8.10
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Taobao API client
65
+ test_files: []