forked from plaid/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
56 lines (46 loc) · 1.5 KB
/
Copy pathapp.rb
File metadata and controls
56 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'date'
require 'sinatra'
require 'plaid'
set :public_folder, File.dirname(__FILE__) + '/public'
client = Plaid::Client.new(env: :sandbox,
client_id: ENV['PLAID_CLIENT_ID'],
secret: ENV['PLAID_SECRET'],
public_key: ENV['PLAID_PUBLIC_KEY'])
access_token = nil
get '/' do
erb :index
end
post '/set_access_token' do
access_token = params['access_token']
puts 'access token: #{access_token}'
{ error: false }.to_json
end
post '/get_access_token' do
exchange_token_response = client.item.public_token.exchange(params['public_token'])
access_token = exchange_token_response['access_token']
puts 'access token: #{access_token}'
exchange_token_response.to_json
end
get '/accounts' do
auth_response = client.auth.get(access_token)
content_type :json
auth_response.to_json
end
get '/item' do
item_response = client.item.get(access_token)
institution_response = client.institutions.get_by_id(item_response['item']['institution_id'])
content_type :json
{ item: item_response['item'], institution: institution_response['institution'] }.to_json
end
get '/transactions' do
now = Date.today
thirty_days_ago = (now - 30)
transactions_response = client.transactions.get(access_token, thirty_days_ago, now)
content_type :json
transactions_response.to_json
end
get '/create_public_token' do
public_token_response = client.item.public_token.exchange(access_token)
content_type :json
public_token_response.to_json
end