Skip to content

Commit

Permalink
Sinatra + Turbo + Nordigen part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
andruby committed Sep 29, 2024
1 parent a6ca827 commit a20315f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

source "https://rubygems.org"

gem "dotenv"
# env vars
gem "dotenv", "~> 3.1.0"

# Used for payments
gem "gocardless_pro", '~> 3.0.0'
gem "gocardless_pro", "~> 3.0.0"

# Used for open banking dating
gem "nordigen-ruby", '~> 2.2.0'
gem "nordigen-ruby", "~> 2.2.0"

# http server
gem "sinatra", "~> 4.0.0"
gem "rackup"
25 changes: 24 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
base64 (0.2.0)
dotenv (3.1.4)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
Expand All @@ -12,20 +13,42 @@ GEM
faraday (>= 2, < 3)
json (2.7.2)
logger (1.6.1)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
net-http (0.4.1)
uri
nordigen-ruby (2.2.0)
faraday (~> 2.5)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
ruby2_keywords (0.0.5)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
tilt (2.4.0)
uri (0.13.1)
webrick (1.8.2)

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES
dotenv
dotenv (~> 3.1.0)
gocardless_pro (~> 3.0.0)
nordigen-ruby (~> 2.2.0)
rackup
sinatra (~> 4.0.0)

BUNDLED WITH
2.5.17
25 changes: 25 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Sinatra app to demo Bank transactions to AI advice
require "bundler"
Bundler.require
Dotenv.load

require 'erb'

get '/' do
erb :index
end

get '/institutions' do
@institutions = nordigen_client.institution.get_institutions("BE")
erb :institutions
end

def nordigen_client
client = Nordigen::NordigenClient.new(
secret_id: ENV["GOCARDLESS_SECRET_ID"],
secret_key: ENV["GOCARDLESS_SECRET_KEY"],
)
token_data = client.generate_token()
client.set_token(token_data["access"])
client
end
34 changes: 34 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<script type="module">
import * as Turbo from 'https://cdn.jsdelivr.net/npm/@hotwired/[email protected]/+esm';
</script>
<style>
.turbo-progress-bar {
height: 10px;
background-color: green;
}
</style>
<title>Wireframe - Contact</title>
</head>
<body>
<header>
<nav>
<a href="/">Home</a>
<a href="/contact">Contact</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<h1>Pick your bank</h1>
<turbo-frame id="institutions" src="/institutions">
loading...
</turbo-frame>
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions views/institutions.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<turbo-frame id="institutions">
<select>
<% @institutions.each do |institution| %>
<option value="<%= institution["id"]%>"><%= institution["name"] %></option>
<% end %>
</select>
</turbo-frame>

0 comments on commit a20315f

Please sign in to comment.