Skip to content

Commit 3f5aeec

Browse files
committed
tinker_python#29 Cleaned up share_lib. Added type hints, fixed broken code an cleaned up in general.
1 parent dcaac3e commit 3f5aeec

File tree

1 file changed

+29
-92
lines changed

1 file changed

+29
-92
lines changed

tinker/libs/share_lib.py

Lines changed: 29 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import argparse
22
import os
33
import sys
4+
from typing import Union, List
45

5-
from bunq.sdk.context import ApiEnvironmentType
6-
from bunq.sdk.exception import BunqException
7-
from bunq.sdk.model.generated import endpoint
8-
from bunq.sdk.model.generated import object_
6+
from bunq import ApiEnvironmentType
7+
from bunq.sdk.exception.bunq_exception import BunqException
8+
from bunq.sdk.model.generated.endpoint import UserPerson, UserCompany, UserLight, MonetaryAccountBank, Card
9+
from bunq.sdk.model.generated.object_ import Pointer, LabelMonetaryAccount
910

1011

1112
class ShareLib(object):
@@ -56,11 +57,7 @@ def parse_all_option(cls):
5657
return parser.parse_args()
5758

5859
@classmethod
59-
def determine_environment_type_from_all_option(cls, all_option):
60-
"""
61-
:rtype: ApiEnvironmentType
62-
"""
63-
60+
def determine_environment_type_from_all_option(cls, all_option) -> ApiEnvironmentType:
6461
if all_option.production:
6562
cls.environment_type = ApiEnvironmentType.PRODUCTION
6663
else:
@@ -69,11 +66,7 @@ def determine_environment_type_from_all_option(cls, all_option):
6966
return cls.environment_type
7067

7168
@classmethod
72-
def determine_amount_from_all_option_or_std_in(cls, all_option):
73-
"""
74-
:rtype: str
75-
"""
76-
69+
def determine_amount_from_all_option_or_std_in(cls, all_option) -> str:
7770
if all_option.amount:
7871
return all_option.amount
7972
else:
@@ -82,11 +75,7 @@ def determine_amount_from_all_option_or_std_in(cls, all_option):
8275
return sys.stdin.readline().strip()
8376

8477
@classmethod
85-
def determine_description_from_all_option_or_std_in(cls, all_option):
86-
"""
87-
:rtype: str
88-
"""
89-
78+
def determine_description_from_all_option_or_std_in(cls, all_option) -> str:
9079
if all_option.description:
9180
return all_option.description
9281
else:
@@ -95,11 +84,7 @@ def determine_description_from_all_option_or_std_in(cls, all_option):
9584
return sys.stdin.readline().strip()
9685

9786
@classmethod
98-
def determine_recipient_from_all_option_or_std_in(cls, all_option):
99-
"""
100-
:rtype: str
101-
102-
"""
87+
def determine_recipient_from_all_option_or_std_in(cls, all_option) -> str:
10388
if all_option.recipient:
10489
return all_option.recipient
10590
else:
@@ -112,11 +97,7 @@ def determine_recipient_from_all_option_or_std_in(cls, all_option):
11297
return sys.stdin.readline().strip()
11398

11499
@classmethod
115-
def determine_card_id_from_all_option_or_std_in(cls, all_option):
116-
"""
117-
:rtype: str
118-
"""
119-
100+
def determine_card_id_from_all_option_or_std_in(cls, all_option) -> str:
120101
if all_option.card_id:
121102
return all_option.card_id
122103
else:
@@ -125,11 +106,7 @@ def determine_card_id_from_all_option_or_std_in(cls, all_option):
125106
return sys.stdin.readline().strip()
126107

127108
@classmethod
128-
def determine_account_id_from_all_option_or_std_in(cls, all_option):
129-
"""
130-
:rtype: str
131-
"""
132-
109+
def determine_account_id_from_all_option_or_std_in(cls, all_option) -> str:
133110
if all_option.account_id:
134111
return all_option.account_id
135112
else:
@@ -138,11 +115,7 @@ def determine_account_id_from_all_option_or_std_in(cls, all_option):
138115
return sys.stdin.readline().strip()
139116

140117
@classmethod
141-
def determine_callback_url_from_all_option_or_std_in(cls, all_option):
142-
"""
143-
:rtype: str
144-
"""
145-
118+
def determine_callback_url_from_all_option_or_std_in(cls, all_option) -> str:
146119
if all_option.callback_url:
147120
return all_option.callback_url
148121
else:
@@ -151,11 +124,7 @@ def determine_callback_url_from_all_option_or_std_in(cls, all_option):
151124
pass
152125

153126
@classmethod
154-
def determine_name_from_all_option_or_std_in(cls, all_option):
155-
"""
156-
:rtype: str
157-
"""
158-
127+
def determine_name_from_all_option_or_std_in(cls, all_option) -> str:
159128
if all_option.name:
160129
return all_option.name
161130
else:
@@ -190,12 +159,7 @@ def print_header(cls):
190159
""")
191160

192161
@classmethod
193-
def print_user(cls, user):
194-
"""
195-
196-
:param user: UserPerson|UserCompany|UserLight
197-
"""
198-
162+
def print_user(cls, user: Union[UserPerson, UserCompany, UserLight]):
199163
print(cls._ECHO_USER)
200164
print(f'''
201165
┌───────────────────┬────────────────────────────────────────────────────
@@ -205,22 +169,14 @@ def print_user(cls, user):
205169
└───────────────────┴────────────────────────────────────────────────────''')
206170

207171
@classmethod
208-
def print_all_monetary_account_bank(cls, all_monetary_account_bank):
209-
"""
210-
:type all_monetary_account_bank: list[endpoint.MonetaryAccountBank]
211-
"""
212-
172+
def print_all_monetary_account_bank(cls, all_monetary_account_bank: List[MonetaryAccountBank]):
213173
print(cls._ECHO_MONETARY_ACCOUNT)
214174

215175
for monetary_account_bank in all_monetary_account_bank:
216176
cls.print_monetary_account_bank(monetary_account_bank)
217177

218178
@classmethod
219-
def print_monetary_account_bank(cls, monetary_account_bank):
220-
"""
221-
:param monetary_account_bank: MonetaryAccountBank
222-
"""
223-
179+
def print_monetary_account_bank(cls, monetary_account_bank: MonetaryAccountBank):
224180
pointer_iban = cls.get_first_pointer_iban(monetary_account_bank)
225181

226182
print(f'''
@@ -239,11 +195,7 @@ def print_monetary_account_bank(cls, monetary_account_bank):
239195
f' └───────────────────┴────────────────────────────────────────────────────')
240196

241197
@classmethod
242-
def get_first_pointer_iban(cls, monetary_account_bank):
243-
"""
244-
:rtype: object_.Pointer
245-
"""
246-
198+
def get_first_pointer_iban(cls, monetary_account_bank) -> Pointer:
247199
for alias in monetary_account_bank.alias:
248200
if alias.type_ == cls._POINTER_TYPE_IBAN:
249201
return alias
@@ -253,7 +205,7 @@ def get_first_pointer_iban(cls, monetary_account_bank):
253205
@classmethod
254206
def print_all_payment(cls, all_payment):
255207
"""
256-
:type all_payment: list[endpoint.Payment]
208+
:type all_payment: list[Payment]
257209
"""
258210

259211
print(cls._ECHO_PAYMENT)
@@ -264,7 +216,7 @@ def print_all_payment(cls, all_payment):
264216
@classmethod
265217
def print_payment(cls, payment):
266218
"""
267-
:type payment: endpoint.Payment
219+
:type payment: Payment
268220
"""
269221

270222
print(f'''
@@ -281,7 +233,7 @@ def print_payment(cls, payment):
281233
@classmethod
282234
def print_all_request(cls, all_request):
283235
"""
284-
:type all_request: list[endpoint.RequestInquiry]
236+
:type all_request: list[RequestInquiry]
285237
"""
286238

287239
print(cls._ECHO_REQUEST)
@@ -292,7 +244,7 @@ def print_all_request(cls, all_request):
292244
@classmethod
293245
def print_request(cls, request):
294246
"""
295-
:type request: endpoint.RequestInquiry
247+
:type request: RequestInquiry
296248
"""
297249

298250
print(f'''
@@ -311,8 +263,8 @@ def print_request(cls, request):
311263
@classmethod
312264
def print_all_card(cls, all_card, all_monetary_account):
313265
"""
314-
:param all_card: list(endpoint.Card)
315-
:param all_monetary_account: list[endpoint.MonetaryAccountBank]
266+
:param all_card: list(Card)
267+
:param all_monetary_account: list[MonetaryAccountBank]
316268
"""
317269

318270
print(cls._ECHO_CARD)
@@ -321,12 +273,7 @@ def print_all_card(cls, all_card, all_monetary_account):
321273
cls.print_card(card, all_monetary_account)
322274

323275
@classmethod
324-
def print_card(cls, card, all_monetary_account):
325-
"""
326-
:type card: endpoint.Card
327-
:type all_monetary_account: list[endpoint.MonetaryAccountBank]
328-
"""
329-
276+
def print_card(cls, card: Card, all_monetary_account: List[MonetaryAccountBank]):
330277
if card.label_monetary_account_current is None:
331278
linked_account = 'No account linked yet.'
332279
else:
@@ -335,7 +282,7 @@ def print_card(cls, card, all_monetary_account):
335282
all_monetary_account
336283
)
337284
linked_account = f'{monetary_account.description} ' \
338-
f'({card.label_monetary_account_current.label_monetary_account.iban})'
285+
f'({card.label_monetary_account_current.label_monetary_account.iban})'
339286

340287
print(f'''
341288
┌───────────────────┬────────────────────────────────────────────────────
@@ -351,13 +298,8 @@ def print_card(cls, card, all_monetary_account):
351298
└───────────────────┴────────────────────────────────────────────────────''')
352299

353300
@classmethod
354-
def get_monetary_account_from_label(cls, label_monetary_account_current,
355-
all_monetary_account):
356-
"""
357-
:type label_monetary_account_current: object_.LabelMonetaryAccount
358-
:type all_monetary_account: list[endpoint.MonetaryAccountBank]
359-
"""
360-
301+
def get_monetary_account_from_label(cls, label_monetary_account_current: LabelMonetaryAccount,
302+
all_monetary_account: List[MonetaryAccountBank]):
361303
iban_label = label_monetary_account_current.iban
362304

363305
for monetary_account in all_monetary_account:
@@ -370,13 +312,8 @@ def get_monetary_account_from_label(cls, label_monetary_account_current,
370312
return None
371313

372314
@staticmethod
373-
def print_all_user_alias(all_user_alias):
374-
"""
375-
:type all_user_alias: list[object_.Pointer]
376-
"""
377-
378-
print("\n" + " You can use these login credentials to login in to "
379-
"the bunq sandbox app.")
315+
def print_all_user_alias(all_user_alias: List[Pointer]):
316+
print("\n" + " You can use these login credentials to login in to the bunq sandbox app.")
380317

381318
for alias in all_user_alias:
382319
print(f'''

0 commit comments

Comments
 (0)