Sha256: 3f4621becff91d3151734575d7b7daf1984ec80e52c29fa471876fedccbc0dae

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'rubygems'
require 'sinatra'
require_relative '../lib/figo'

CLIENT_ID = "CaESKmC8MAhNpDe5rvmWnSkRE_7pkkVIIgMwclgzGcQY"
CLIENT_SECRET = "STdzfv0GXtEj_bwYn7AgCVszN1kKq5BdgEIKOM_fzybQ"
connection = Figo::Connection.new(CLIENT_ID, CLIENT_SECRET, "http://localhost:3000/callback")

configure do
  enable :sessions
  set :port, 3000
end

get '/callback*' do
  if params['state'] != "qweqwe"
    logger.info "qwe"
    raise Exception.new("Bogus redirect, wrong state")
  end

  token_hash = connection.obtain_access_token(params['code'])
  request.session['figo_token'] = token_hash['access_token']

  redirect to('/')
end

get '/logout' do
  request.session['figo_token'] = nil
  redirect to('/')
end

before '/' do
  logger.info request.path_info
  unless session[:figo_token] or request.path_info == "/callback" then
    redirect to(connection.login_url("qweqwe", "accounts=ro transactions=ro balance=ro user=ro"))
  end
end

get '/:account_id' do | account_id |
  session = Figo::Session.new(request.session['figo_token'])
  @accounts = session.accounts
  @current_account = session.get_account(account_id)
  @transactions = @current_account.transactions
  @user = session.user

  erb :index
end

get '/' do
  session = Figo::Session.new(request.session['figo_token'])
  @accounts = session.accounts
  @current_account = nil
  @transactions = session.transactions
  @user = session.user

  erb :index
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
figo-1.2.3 web_demo/app.rb
figo-1.2.1 web_demo/app.rb
figo-1.2.0 web_demo/app.rb