Class: Iro::ApiController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Iro::ApiController
- Defined in:
- app/controllers/iro/api_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#oauth2_redirect ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/iro/api_controller.rb', line 12 def oauth2_redirect out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", { headers: { "Content-Type": "application/x-www-form-urlencoded", }, basic_auth: { username: SCHWAB_DATA[:key], password: SCHWAB_DATA[:secret] }, body: { grant_type: 'authorization_code', code: params[:code].sub('%40', '@'), redirect_uri: SCHWAB_DATA[:redirect_url], }, }) out = out.parsed_response attrs = { schwab_access_token: out['access_token'], schwab_refresh_token: out['refresh_token'], schwab_id_token: out['id_token'], } # puts! attrs, 'attrs' profile = Wco::Profile.find_by email: 'piousbox@gmail.com' profile.update(attrs) profile.save! render json: { status: :ok } end |
#schwab_exec_redirect ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/iro/api_controller.rb', line 40 def schwab_exec_redirect out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", { headers: { "Content-Type": "application/x-www-form-urlencoded", }, basic_auth: { username: SCHWAB_EXEC[:key], password: SCHWAB_EXEC[:secret] }, body: { grant_type: 'authorization_code', code: params[:code].sub('%40', '@'), redirect_uri: SCHWAB_EXEC[:redirect_url], }, }) out = out.parsed_response attrs = { schwab_exec_access_token: out['access_token'], schwab_exec_refresh_token: out['refresh_token'], schwab_exec_id_token: out['id_token'], } # puts! attrs, 'attrs' profile = Wco::Profile.find_by email: 'piousbox@gmail.com' profile.update(attrs) profile.save! render json: { status: :ok } end |