Class: KAuth::Consumer
- Inherits:
-
Object
- Object
- KAuth::Consumer
- Defined in:
- lib/kuaipan/kauth/consumer.rb
Constant Summary collapse
- CA_FILES =
determine the certificate authority path to verify SSL certs
%w(/etc/ssl/certs/ca-certificates.crt /usr/share/curl/curl-ca-bundle.crt /etc/ssl/certs/ca-bundle.trust.crt)
- CA_FILE =
nil
Instance Attribute Summary collapse
-
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
-
#oauth_token_secret ⇒ Object
Returns the value of attribute oauth_token_secret.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #get_no_ssl(path, opts = {}) ⇒ Object
- #get_request_token(oauth_callback = nil) ⇒ Object
- #get_ssl(path, opts = {}) ⇒ Object
-
#initialize(ctoken, csecret, opts = {}) ⇒ Consumer
constructor
A new instance of Consumer.
- #post(path, file, opts = {}) ⇒ Object
- #set_atoken(oauth_verifier) ⇒ Object
Constructor Details
#initialize(ctoken, csecret, opts = {}) ⇒ Consumer
Returns a new instance of Consumer.
24 25 26 27 28 29 30 31 32 |
# File 'lib/kuaipan/kauth/consumer.rb', line 24 def initialize(ctoken, csecret, opts={}) @oauth_consumer_secret = csecret @base_url = opts.delete(:site) @rtoken_path = opts.delete(:rtoken_path) @atoken_path = opts.delete(:atoken_path) @options = {oauth_signature_method: 'HMAC-SHA1', oauth_version: '1.0', oauth_consumer_key: ctoken}.merge(opts) end |
Instance Attribute Details
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
12 13 14 |
# File 'lib/kuaipan/kauth/consumer.rb', line 12 def oauth_token @oauth_token end |
#oauth_token_secret ⇒ Object
Returns the value of attribute oauth_token_secret.
12 13 14 |
# File 'lib/kuaipan/kauth/consumer.rb', line 12 def oauth_token_secret @oauth_token_secret end |
#user_id ⇒ Object
Returns the value of attribute user_id.
12 13 14 |
# File 'lib/kuaipan/kauth/consumer.rb', line 12 def user_id @user_id end |
Instance Method Details
#get_no_ssl(path, opts = {}) ⇒ Object
66 67 68 69 |
# File 'lib/kuaipan/kauth/consumer.rb', line 66 def get_no_ssl(path, opts={}) opts.merge!({oauth_token: @oauth_token}) get('http://', "/#{ @options[:oauth_version].to_i.to_s }/#{ path }", opts) end |
#get_request_token(oauth_callback = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kuaipan/kauth/consumer.rb', line 34 def get_request_token(oauth_callback=nil) opts = {} if oauth_callback opts[:oauth_callback] = oauth_callback end res = get('https://', @rtoken_path, opts) body = res.body hash = JSON.parse(body) hash.each do |pair| instance_variable_set('@' + pair[0], pair[1]) end hash['oauth_token'] end |
#get_ssl(path, opts = {}) ⇒ Object
61 62 63 64 |
# File 'lib/kuaipan/kauth/consumer.rb', line 61 def get_ssl(path, opts={}) opts.merge!({oauth_token: @oauth_token}) get('https://', "/#{ @options[:oauth_version].to_i.to_s }/#{ path }", opts) end |
#post(path, file, opts = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/kuaipan/kauth/consumer.rb', line 71 def post(path, file, opts={}) opts.merge!({oauth_token: @oauth_token}) base_url_str = opts[:site] ? opts.delete(:site) : @base_url url = "#{ base_url_str }#{ @options[:oauth_version].to_i.to_s }/#{ path }" params = get_params('POST', url, opts) uri = URI(url) uri.query = URI.encode_www_form(params) RestClient.post(uri.to_s, :my_file => file) end |
#set_atoken(oauth_verifier) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kuaipan/kauth/consumer.rb', line 49 def set_atoken(oauth_verifier) res = get('https://', @atoken_path, {oauth_token: @oauth_token, oauth_verifier: oauth_verifier}) body = res.body hash = JSON.parse(body) hash.each do |pair| instance_variable_set("@#{ pair[0] }" , pair[1]) end end |