Sha256: 01bf4d5c5794529c469667ea9c640161838eae783f5e416aec041546d264763d

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

Pu  ||= Iro::Purse
Str ||= Iro::Strategy
Po  ||= Iro::Position
O   ||= Iro::Option
Sto ||= Iro::Stock

class Schwab
  include HTTParty
  debug_output $stdout
end

class Iro::ApplicationController < Wco::ApplicationController
  layout 'iro/application'

  before_action :set_lists, except: %i| schwab_sync |

  def home
    authorize! :home, Iro
  end

  def schwab_sync
    authorize! :shwab_sync, Iro
    profile = Wco::Profile.find_by email: 'piousbox@gmail.com'

    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: 'refresh_token',
        refresh_token: profile.schwab_refresh_token
      },
    })
    out = out.parsed_response
    puts! out, 'out'

    attrs = {
      schwab_access_token:  out['access_token'],
      schwab_refresh_token: out['refresh_token'],
      schwab_id_token:      out['id_token'],
    }
    # puts! attrs, 'attrs'

    profile.update(attrs)
    profile.save!

    render json: { status: :ok }
  end

  ##
  ## private
  ##
  private

  def set_lists
    @purses = Iro::Purse.all
    @strategies = Iro::Strategy.all
    @strategies_list = Iro::Strategy.list
  end


end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.38 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.37 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.36 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.35 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.34 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.33 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.32 app/controllers/iro/application_controller.rb
iron_warbler-2.0.7.31 app/controllers/iro/application_controller.rb