class OmniAuth::YoyowMiddleware
Attributes
resource[R]
Public Class Methods
new(url)
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 11 def initialize(url) unless url.start_with?('http') url = 'http://' + url end @resource = Faraday.new(url) end
Public Instance Methods
_get(url, params={})
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 43 def _get(url, params={}) begin resp = resource.get url, params json = MultiJson.load resp.body, :symbolize_keys => true raise MiddlewareRequestError.new(json[:message]) if json[:code] != 0 json[:data] rescue MiddlewareRequestError => e puts "Error occurs while accessing yoyow middleware: " puts e.message raise e end end
get_account(uid)
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 24 def get_account(uid) _get '/api/v1/getAccount', uid: uid end
get_auth_url(callback_url)
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 18 def get_auth_url(callback_url) resp = get_platform_sign auth_data = resp.slice(:sign, :time, :platform).merge({state: callback_url}) auth_url = [resp[:url], '?', URI.encode_www_form(auth_data)].join('') end
get_platform_sign()
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 28 def get_platform_sign _get '/auth/sign' end
verify_auth(yyw_id, time, sign)
click to toggle source
# File lib/omniauth/yoyow-middleware.rb, line 32 def verify_auth(yyw_id, time, sign) return false if yyw_id.nil? or time.nil? or sign.nil? data = _get('/auth/verify', { yoyow: yyw_id, time: time, sign: sign }) data[:verify] end