Skip to content

Commit daad14f

Browse files
Update user context after auto request, extracted method. (#10)
1 parent 1b60f7d commit daad14f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tinker/libs/bunq_lib.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
from os.path import isfile
33
import socket
4+
from time import sleep
45

56
import requests
67
from bunq.sdk.client import Pagination
@@ -35,6 +36,7 @@ class BunqLib(object):
3536
_REQUEST_SPENDING_MONEY_AMOUNT = '500.0'
3637
_REQUEST_SPENDING_MONEY_RECIPIENT = 'sugardaddy@bunq.com'
3738
_REQUEST_SPENDING_MONEY_DESCRIPTION = 'Requesting some spending money.'
39+
_REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS = 1
3840

3941
_ZERO_BALANCE = 0.0
4042

@@ -47,7 +49,7 @@ def __init__(self, env):
4749
self.env = env
4850
self.setup_context()
4951
self.setup_current_user()
50-
self.request_spending_money_if_needed()
52+
self.__request_spending_money_if_needed()
5153

5254
def setup_context(self):
5355
if isfile(self.determine_bunq_conf_filename()):
@@ -242,12 +244,17 @@ def generate_new_sandbox_user(self):
242244

243245
raise BunqException(self._ERROR_COULD_NOT_CREATE_NEW_SANDBOX_USER)
244246

245-
def request_spending_money_if_needed(self):
246-
if self.env == ApiEnvironmentType.SANDBOX \
247-
and float(BunqContext.user_context().primary_monetary_account.balance.value) <= self._ZERO_BALANCE:
247+
def __request_spending_money_if_needed(self):
248+
if self.__should_request_spending_money():
248249
endpoint.RequestInquiry.create(
249250
amount_inquired=Amount(self._REQUEST_SPENDING_MONEY_AMOUNT, self._CURRENCY_EUR),
250251
counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, self._REQUEST_SPENDING_MONEY_RECIPIENT),
251252
description=self._REQUEST_SPENDING_MONEY_DESCRIPTION,
252253
allow_bunqme=False
253254
)
255+
sleep(self._REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS)
256+
BunqContext.user_context().refresh_user_context()
257+
258+
def __should_request_spending_money(self):
259+
return self.env == ApiEnvironmentType.SANDBOX \
260+
and float(BunqContext.user_context().primary_monetary_account.balance.value) <= self._ZERO_BALANCE

0 commit comments

Comments
 (0)