Class: Qq::Oauth
- Inherits:
-
Object
- Object
- Qq::Oauth
- Defined in:
- lib/qq/oauth.rb
Constant Summary collapse
- API_URL =
"https://graph.qq.com/"
Class Method Summary collapse
Instance Method Summary collapse
- #get(path, parameters = {}) ⇒ Object
-
#initialize(access_token, openid) ⇒ Oauth
constructor
A new instance of Oauth.
- #post(path, parameters = {}) ⇒ Object
Constructor Details
#initialize(access_token, openid) ⇒ Oauth
Returns a new instance of Oauth.
8 9 10 11 12 13 14 |
# File 'lib/qq/oauth.rb', line 8 def initialize(access_token,openid) filename = "#{Rails.root}/config/service.yml" config = YAML.load(File.open(filename))[Rails.env] @app_key = config['qq_connect']['app_id'] @access_token = access_token @openid = openid end |
Class Method Details
.parse_signed_request(signed_request) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/qq/oauth.rb', line 31 def self.parse_signed_request(signed_request) encoded_sig, payload = signed_request.split(".") sig = Base64.decode64_url(encoded_sig) begin data = JSON.parse(Base64.decode64_url(payload)) rescue Exception => e return nil end return nil if data["algorithm"].upcase != "HMAC-SHA256" expected_sig = OpenSSL::HMAC.digest("sha256", Config.app_secret, payload) (sig != expected_sig) ? nil : data end |
Instance Method Details
#get(path, parameters = {}) ⇒ Object
16 17 18 19 |
# File 'lib/qq/oauth.rb', line 16 def get(path, parameters = {}) parameters.merge!(openid: @openid,access_token: @access_token,oauth_consumer_key: @app_key) JSON.parse RestClient.get(api_url(path), :params => parameters) end |
#post(path, parameters = {}) ⇒ Object
21 22 23 24 |
# File 'lib/qq/oauth.rb', line 21 def post(path, parameters = {}) parameters.merge!(openid: @openid,access_token: @access_token,oauth_consumer_key: @app_key) JSON.parse RestClient.post(api_url(path), parameters) end |