Skip to content

Commit

Permalink
feat: Add method to retrieve savings account balance
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo Arena Câmara <[email protected]>
  • Loading branch information
roarena authored and andreroggeri committed Sep 9, 2022
1 parent 22f457b commit d733a7a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pynubank/nubank.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def get_account_balance(self):
data = self._make_graphql_request('account_balance')
return data['data']['viewer']['savingsAccount']['currentSavingsBalance']['netAmount']

@requires_auth_mode(AuthMode.APP)
def get_account_savings_balance(self):
data = self._make_graphql_request('account_savings')
return data['data']['viewer']['productFeatures']['buckets']['screens']['home']

@requires_auth_mode(AuthMode.APP)
def get_account_investments_details(self):
data = self._make_graphql_request('account_investments')
Expand Down
21 changes: 21 additions & 0 deletions pynubank/queries/account_savings.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query bucketsHomeInfo {
viewer {
productFeatures {
buckets {
screens {
home {
mainBalance {
netAmount
}
balancesList {
label
maturityDate
netAmount
href
}
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions pynubank/utils/mock_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self):
'pix_receipt_screen')
self._results[GHOSTFLAME_URL, str(prepare_request_body('account_feed_paginated'))] = self._read_data(
'account_feed_paginated')
self._results[(GHOSTFLAME_URL, str(prepare_request_body('account_savings')))] = self._read_data(
'account_savings')

def add_mock_url(self, url: str, graphql_object: str, response_json_name: str):
self._results[(url, graphql_object)] = self._read_data(response_json_name)
Expand Down
31 changes: 31 additions & 0 deletions pynubank/utils/mocked_responses/account_savings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"data": {
"viewer": {
"productFeatures": {
"buckets": {
"screens": {
"home": {
"mainBalance": {
"netAmount": 37.0
},
"balancesList": [
{
"label": "Disponível a qualquer momento",
"maturityDate": "None",
"netAmount": 35.0,
"href": "nuapp://flutter/savings/buckets/daily-liquidity"
},
{
"label": "Disponível em 01/07/2023",
"maturityDate": "None",
"netAmount": 35.0,
"href": "nuapp://flutter/savings/buckets/daily-liquidity"
}
]
}
}
}
}
}
}
}
13 changes: 11 additions & 2 deletions tests/test_nubank_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,17 @@ def test_creditcard_methods_should_allow_web_authentication(method_name, method_
method(**method_args)


def test_creditcard_methods_should_allow_app_authentication():
pass
def test_get_account_savings_balance():
nubank_client = Nubank(client=MockHttpClient())
nubank_client.authenticate_with_cert('1234', 'hunter12', 'some-file.p12')

savings_balance = nubank_client.get_account_savings_balance()
savings_balance_list = savings_balance['balancesList']

assert savings_balance['mainBalance']['netAmount'] == 37.0
assert len(savings_balance_list) == 2
for balance in savings_balance_list:
assert balance['netAmount'] == 35.0


def test_get_pix_details():
Expand Down

0 comments on commit d733a7a

Please sign in to comment.