Class: OmniAuth::Strategies::IHealth
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::IHealth
- Defined in:
- lib/omniauth/strategies/ihealth.rb
Constant Summary collapse
- AVAILABLE_API_NAMES =
"OpenApiActivity OpenApiBG OpenApiBP OpenApiSleep OpenApiSpO2 OpenApiUserInfo OpenApiWeight"
- DEFAULT_API_NAMES =
"OpenApiUserInfo"
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #build_access_token ⇒ Object
- #raw_info ⇒ Object
- #token_params ⇒ Object
- #user_data ⇒ Object
Instance Method Details
#authorize_params ⇒ Object
23 24 25 26 27 28 |
# File 'lib/omniauth/strategies/ihealth.rb', line 23 def super.tap do |params| params[:response_type] = 'code' params[:APIName] = .scope end end |
#build_access_token ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omniauth/strategies/ihealth.rb', line 38 def build_access_token token_url_params = {:code => request.params['code'], :redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)) parsed_response = client.request(..token_method, client.token_url(token_url_params), parse: :json).parsed hash = { :access_token => parsed_response["AccessToken"], :expires_in => parsed_response["Expires"], :refresh_token => parsed_response["RefreshToken"], :user_id => parsed_response["UserID"], :api_name => parsed_response["APIName"], :client_para => parsed_response["client_para"] } ::OAuth2::AccessToken.from_hash(client, hash) end |
#raw_info ⇒ Object
60 61 62 63 64 65 |
# File 'lib/omniauth/strategies/ihealth.rb', line 60 def raw_info access_token.[:mode] = :query user_profile_params = {:client_id => client.id, :client_secret => client.secret, :access_token => access_token.token} user_profile_params.merge({:sc => .sc, :sv => .sv}) if .sc && .sv @raw_info ||= access_token.get("/openapiv2/user/#{access_token[:user_id]}.json/?#{user_profile_params.to_param}", parse: :json).parsed end |
#token_params ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/omniauth/strategies/ihealth.rb', line 30 def token_params super.tap do |params| params[:client_id] = client.id params[:client_secret] = client.secret params[:grant_type] = "authorization_code" end end |
#user_data ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omniauth/strategies/ihealth.rb', line 67 def user_data info = raw_info user_data ||= { :name => info["nickname"], :gender => info["gender"].downcase, :birthday => Time.at(info["dateofbirth"]).to_date.strftime("%Y-%m-%d"), :image => URI.unescape(info["logo"]), :nickname => info["nickname"], :height => calc_height(info["height"], info["HeightUnit"]), :weight => calc_weight(info["weight"], info["WeightUnit"]) } end |