Class: TaobaoSDK::Session
- Inherits:
-
Object
- Object
- TaobaoSDK::Session
- Defined in:
- lib/taobaoSDK/session.rb
Constant Summary collapse
- REQUEST_TIMEOUT =
10
- API_VERSION =
'2.0'
- USER_AGENT =
"taobaoSDK-v#{VERSION}"
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
-
.session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
-
.authorize_hash ⇒ Object
authorize hash.
-
.authorize_url ⇒ Object
获取taobao oauth authorize url.
-
.invoke(params) ⇒ Object
Return response in object format.
-
.load(config_file) ⇒ Object
Load a yml config, and initialize http session yml config file content should be:.
-
.token(code) ⇒ Object
获取token params授权码 return hash 解析返回参数后的hash.
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/taobaoSDK/session.rb', line 13 def config @config end |
.session ⇒ Object
Returns the value of attribute session.
13 14 15 |
# File 'lib/taobaoSDK/session.rb', line 13 def session @session end |
Class Method Details
.authorize_hash ⇒ Object
authorize hash
43 44 45 46 47 48 49 50 51 |
# File 'lib/taobaoSDK/session.rb', line 43 def { "response_type" => 'code', "client_id" => config['api_key'], "redirect_uri" => config['authorize_redirect_uri'], "state" => 1212, "view" => 'web' } end |
.authorize_url ⇒ Object
获取taobao oauth authorize url
39 40 41 |
# File 'lib/taobaoSDK/session.rb', line 39 def "#{config['authorize']}?response_type=code&client_id=#{config['app_key']}&redirect_uri=#{config['authorize_redirect_uri']}&state=1212&view=web" end |
.invoke(params) ⇒ Object
Return response in object format
29 30 31 32 33 34 35 36 37 |
# File 'lib/taobaoSDK/session.rb', line 29 def invoke(params) params = merge_params(params) response_body = RestClient.post(config['endpoint'],params).body res = parse_result(response_body) if res.is_a? TaobaoSDK::ErrorResponse raise res.msg end res end |
.load(config_file) ⇒ Object
Load a yml config, and initialize http session yml config file content should be:
app_key: "YOUR APP KEY"
secret_key: "YOUR SECRET KEY"
endpoint: "TAOBAO GATEWAY API URL"
22 23 24 25 26 |
# File 'lib/taobaoSDK/session.rb', line 22 def load(config_file) @config = YAML.load_file(config_file) @config = config[::Rails.env] if defined? ::Rails check_config_and_export_to_env end |
.token(code) ⇒ Object
获取token params授权码 return hash 解析返回参数后的hash
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/taobaoSDK/session.rb', line 55 def token(code) params = { :grant_type => "authorization_code", :code => code, :client_id => config["app_key"], :client_secret => config["secret_key"], :redirect_uri => config['token_redirect_uri'], :view => 'web' } JSON(RestClient.post(config['token'],params).body) end |