Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Richter
committed
Jul 11, 2014
1 parent
5ddee28
commit 2336a3a
Showing
7 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require_relative "lib/figo" | ||
|
||
session = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ") | ||
|
||
# Print out list of account numbers and balances. | ||
session.accounts.each do |account| | ||
puts account.account_number | ||
puts account.balance.balance | ||
end | ||
|
||
# Print out the list of all transaction originators/recipients of a specific account. | ||
session.get_account("A1.1").transactions.each do |transaction| | ||
puts transaction.name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { padding-top: 70px; } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div class="container-fluid" role="main"> | ||
<h1><%= @current_account.nil? ? "Unified Inbox" : @current_account.name %></h1> | ||
|
||
<% if @current_account %> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading">Account Details</div> | ||
<div class="panel-body"> | ||
<ul class="list-group"> | ||
<li class="list-group-item">Owner: <%= @current_account.owner %></li> | ||
<li class="list-group-item">Account Number: <%= @current_account.account_number %></li> | ||
<li class="list-group-item">Bank Code: <%= @current_account.bank_code %></li> | ||
<li class="list-group-item">IBAN: <%= @current_account.iban %></li> | ||
<li class="list-group-item">Balance: <%= @current_account.balance.balance %> <%= @current_account.currency %></li> | ||
</ul> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<table class="table table-hover table-condensed"> | ||
<thead><tr> | ||
<th>Date</th> | ||
<th>Name</th> | ||
<th>Account Number</th> | ||
<th>Purpose</th> | ||
<th style="text-align: right;">Amount</th> | ||
</tr></thead> | ||
<tbody> | ||
<% if @transactions %> | ||
<% @transactions.each do |transaction| %> | ||
<tr> | ||
<td><%= transaction.value_date %></td> | ||
<td><%= transaction.name %></td> | ||
<td><%= transaction.account_number %></td> | ||
<td><%= transaction.purpose %></td> | ||
<td style="text-align: right; <% if transaction.amount < 0 %>color: red;<% end %>"><%= transaction.amount %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>figo web banking</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<!-- Bootstrap --> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | ||
|
||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | ||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | ||
<!--[if lt IE 9]> | ||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | ||
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> | ||
<![endif]--> | ||
|
||
<link href="/favicon.ico" rel="shortcut icon" /> | ||
<link href="/banking.css" rel="stylesheet" media="screen" /> | ||
|
||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="navbar navbar-default" role="navigation"> | ||
<div class="navbar-header"> | ||
<a class="navbar-brand" href="/">figo web banking</a> | ||
</div> | ||
<div class="navbar-collapse collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li <% if @current_account.nil? %> class="active"<% end %>><a href="/">Unified Inbox</a></li> | ||
<% @accounts.each do |account| %> | ||
<li <% if !@current_account.nil? and @current_account.account_id == account.account_id %>class="active" <% end %>><a href="/<%= account.account_id %>"><%= account.name %></a></li> | ||
<% end %> | ||
</ul> | ||
<p class="navbar-text navbar-right">Signed in as <a href="/logout" class="navbar-link"><%= @user.email %></a></p> | ||
</div><!--/.nav-collapse --> | ||
</div> | ||
|
||
<div> | ||
<%if @error then %> | ||
<div class="alert alert-error"><%=@error%></div> | ||
<% end %> | ||
<%= yield %> | ||
</div> | ||
|
||
</div> | ||
|
||
|
||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | ||
<!-- Include all compiled plugins (below), or include individual files as needed --> | ||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |