-
Notifications
You must be signed in to change notification settings - Fork 0
/
twino.lua
109 lines (95 loc) · 3.23 KB
/
twino.lua
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
-- Inofficial Twino Extension (www.twino.eu) for MoneyMoneyApp
-- Scrapes balances from Twino and returns them as securities
--
-- Username: Username
-- Password: Password
--
-- Copyright (c) 2017 beanieboi
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
WebBanking{
version = 1.0,
url = "https://www.twino.eu/en",
description = "Fetch balances from Twino and list them as securities",
services= { "Twino Account" },
}
local currency = "EUR" -- fixme: Don't hardcode
local currencyName = "EUR" -- fixme: Don't hardcode
local connection
function SupportsBank (protocol, bankCode)
return protocol == ProtocolWebBanking and bankCode == "Twino Account"
end
function InitializeSession (protocol, bankCode, username, username2, password, username3)
connection = Connection()
content, charset, mimeType = connection:request("POST",
"https://www.twino.eu/ws/public/login", '{"name":"' .. username .. '", "password":"' .. password .. '"}', "application/json;charset=UTF-8")
if string.match(content, '"success":false') then
return LoginFailed
end
end
function ListAccounts (knownAccounts)
local account = {
name = "Twino Summary",
accountNumber = "Twino Summary",
currency = currency,
portfolio = true,
type = "AccountTypePortfolio"
}
return {account}
end
function RefreshAccount (account, since)
local s = {}
summary = AccountSummary()
local security = {
name = "Account",
price = tonumber(summary.accountValue),
quantity = 1,
purchasePrice = tonumber(summary.investments),
curreny = nil,
}
table.insert(s, security)
return {securities = s}
end
function EndSession ()
connection:get("https://www.twino.eu/logout")
return nil
end
function AccountSummary ()
local headers = {accept = "application/json"}
local content = connection:request(
"GET",
"https://www.twino.eu/ws/web/investor/my-account-summary",
"",
"application/json",
headers
)
return JSON(content):dictionary()
end
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end