topsdk 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-19 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nestful
16
- requirement: &70275679541760 !ruby/object:Gem::Requirement
16
+ requirement: &70238391476300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70275679541760
24
+ version_requirements: *70238391476300
25
25
  description: Simple Taobao API client for Ruby
26
26
  email:
27
27
  - howl.wong@gmail.com
@@ -30,16 +30,7 @@ extensions: []
30
30
  extra_rdoc_files:
31
31
  - README.rdoc
32
32
  files:
33
- - .gitignore
34
- - Gemfile
35
33
  - README.rdoc
36
- - Rakefile
37
- - init.rb
38
- - lib/config/taobao.yml
39
- - lib/topsdk.rb
40
- - lib/topsdk/client.rb
41
- - lib/topsdk/version.rb
42
- - topsdk.gemspec
43
34
  homepage: ''
44
35
  licenses: []
45
36
  post_install_message:
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in topsdk.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'topsdk'
@@ -1,24 +0,0 @@
1
- prod: &prod
2
- api_key: 12012322
3
- secret_key: 42ab2d12a5bea25d1bc06ccd23123121daf
4
- auth_url: https://oauth.taobao.com/authorize
5
- token_url: https://oauth.taobao.com/token
6
- rest_url: http://gw.api.taobao.com/router/rest
7
- callback_url: http://yourdomain.com/auth/callback
8
-
9
- sandbox: &sandbox
10
- <<: *prod
11
- secret_key: sandbox9ffd79873a7ae0e01fefed97c
12
- auth_url: https://oauth.tbsandbox.com/authorize
13
- token_url: https://oauth.tbsandbox.com/token
14
- rest_url: http://gw.api.tbsandbox.com/router/rest
15
- callback_url: http://0.0.0.0:3000/auth/callback
16
-
17
- development:
18
- <<: *sandbox
19
-
20
- test:
21
- <<: *sandbox
22
-
23
- production:
24
- <<: *prod
data/lib/topsdk/client.rb DELETED
@@ -1,67 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'nestful'
3
- require 'digest/md5'
4
- require 'pp'
5
-
6
- module Topsdk
7
- class Client
8
- DEBUG = false
9
-
10
- def initialize(params={})
11
- @params = { # 淘宝参数
12
- :app_key => ENV['TAOBAO_APP_KEY'],
13
- :format => :json,
14
- :v => '2.0',
15
- :timestamp => timestamp
16
- }
17
- @params.merge!(params.clone) unless params.empty? # 參數合併
18
- @params[:sign] = generate_sign(@params)
19
- pp @params if DEBUG
20
- end
21
-
22
- def get(url=ENV['TAOBAO_REST_URL'])
23
- request = Nestful::Request.new(url, ({:method => :get, :format => :json, :params => @params}))
24
- @result = request.execute
25
- parse
26
- end
27
-
28
- def post(url=ENV['TAOBAO_REST_URL'])
29
- request = Nestful::Request.new(url, ({:method => :post, :format => :form, :params => @params}))
30
- pp request.to_s
31
- pp @params.to_s
32
- @result = request.execute
33
- @result = JSON.parse(@result)
34
- parse
35
- end
36
-
37
- def parse # 簡單解析一下
38
- return false unless @result.is_a?(Hash)
39
- case
40
- when @result.has_key?(response_key)
41
- pp response_key if DEBUG
42
- result = @result[response_key]
43
- when @result.has_key?('error_response')
44
- @result['error_response']['msg']
45
- else
46
- @result
47
- end
48
- end
49
-
50
- def generate_sign(params={})
51
- rand = ENV['TAOBAO_APP_SECRET'] + params.sort.flatten.join
52
- Digest::MD5.hexdigest(rand).upcase! # 數字簽名
53
- end
54
-
55
- def response_key # 操作結果鍵
56
- @params[:method][7..-1].gsub(/\./, '_') + "_response" unless @params[:method].nil?
57
- end
58
-
59
- def root_key # 獲取對象的鍵
60
- response_key.split('_')[0] unless @params[:method].nil?
61
- end
62
-
63
- def timestamp # 时间戳
64
- Time.now.strftime("%Y-%m-%d %H:%M:%S")
65
- end
66
- end
67
- end
@@ -1,3 +0,0 @@
1
- module Topsdk
2
- VERSION = '0.0.3'
3
- end
data/lib/topsdk.rb DELETED
@@ -1,62 +0,0 @@
1
- require 'topsdk/version'
2
- require 'topsdk/client'
3
-
4
- RAILS_ENV = PADRINO_ENV if defined?(PADRINO_ENV)
5
-
6
- # 賦值
7
- def apply_settings
8
- @settings = YAML.load_file(config_file)
9
- @settings = defined?(RAILS_ENV) ? @settings[RAILS_ENV] : @settings['development']
10
- ENV['TAOBAO_APP_KEY'] = @settings['api_key'].to_s
11
- ENV['TAOBAO_APP_SECRET'] = @settings['secret_key']
12
- ENV['TAOBAO_AUTH_URL'] = @settings['auth_url']
13
- ENV['TAOBAO_TOKEN_URL'] = @settings['token_url']
14
- ENV['CALLBACK_URL'] = @settings['callback_url']
15
- ENV['TAOBAO_REST_URL'] = @settings['rest_url']
16
- end
17
-
18
- def config_file
19
- # 解析配置文件
20
- yml_file = File.expand_path(File.join('.', 'config', 'taobao.yml'))
21
- unless File.exist?(yml_file)
22
- File.expand_path(File.join('config', 'taobao.yml'), File.dirname(__FILE__))
23
- else
24
- yml_file
25
- end
26
- end
27
-
28
- apply_settings
29
-
30
- module Topsdk
31
- class << self
32
-
33
- def get_with(joined_params = {})
34
- Client.new(joined_params).get
35
- end
36
-
37
- def post_with(joined_params = {})
38
- Client.new(joined_params).post
39
- end
40
-
41
- def authorize_url
42
- "#{ENV['TAOBAO_AUTH_URL']}?response_type=code&client_id=#{ENV['TAOBAO_APP_KEY']}&redirect_uri=#{ENV['CALLBACK_URL']}"
43
- end
44
-
45
- def token(code)
46
- joined_params = token_params(code)
47
- res = Client.new(joined_params).post(ENV['TAOBAO_TOKEN_URL'])
48
- res['access_token']
49
- end
50
-
51
- def token_params(code)
52
- { # 淘宝参数
53
- :grant_type => 'authorization_code',
54
- :code => code,
55
- :client_id => ENV['TAOBAO_APP_KEY'],
56
- :client_secret => ENV['TAOBAO_APP_SECRET'],
57
- :redirect_uri => ENV['CALLBACK_URL'],
58
- }
59
- end
60
-
61
- end
62
- end
data/topsdk.gemspec DELETED
@@ -1,26 +0,0 @@
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