diff --git a/CHANGELOG.md b/CHANGELOG.md index 21438e3..de2782d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ Given a version number MAJOR.MINOR.PATCH, increment: - request methods ### Changed - core version +### Fixed +- request prefix param ## [2.25.1] - 2024-04-01 ### Fixed diff --git a/README.md b/README.md index 87cf228..9f27bce 100644 --- a/README.md +++ b/README.md @@ -2605,7 +2605,7 @@ import starkbank example_id = "5155165527080960" request = starkbank.request.get( path=f"/invoice/{example_id}" -) +).json() print(request) ``` @@ -2618,7 +2618,7 @@ import starkbank example_id = "5699165527090460" request = starkbank.request.get( path=f"/invoice/log/{example_id}", -) +).json() print(request) ``` @@ -2631,7 +2631,7 @@ import starkbank request = starkbank.request.get( path="/invoice", query={"limit": 10, "status": "paid"}, -) +).json() for item in request["invoices"]: print(item) @@ -2645,7 +2645,7 @@ import starkbank request = starkbank.request.get( path="/invoice/log", query={"limit": 10, "status": "paid"}, -) +).json() for item in request["invoices"]: print(item) @@ -2659,7 +2659,7 @@ import starkbank example_id = "5155165527080960" pdf = starkbank.request.get( path=f"/invoice/{example_id}/pdf", -) +).content with open("request.pdf", "wb") as file: file.write(pdf) ``` @@ -2692,7 +2692,7 @@ data={ request = starkbank.request.post( path="/invoice", body=data, -) +).json() print(request) ``` @@ -2708,7 +2708,7 @@ example_id = "5155165527080960" request = starkbank.request.patch( path=f"/invoice/{example_id}", body={"amount": 0}, -) +).json() print(request) ``` @@ -2731,7 +2731,7 @@ data = { request = starkbank.request.put( path="/split-profile", body=data, -) +).json() print(request) ``` ## DELETE @@ -2745,7 +2745,7 @@ import starkbank example_id = "5155165527080960" request = starkbank.request.delete( path=f"/transfer/{example_id}", -) +).json() print(request) ``` # Handling errors diff --git a/requirements.txt b/requirements.txt index fc01935..2901b82 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -starkcore==0.3.2 +starkcore==0.3.3 diff --git a/starkbank/__init__.py b/starkbank/__init__.py index d070873..2567703 100644 --- a/starkbank/__init__.py +++ b/starkbank/__init__.py @@ -3,6 +3,7 @@ user = None language = "en-US" timeout = 15 +request_methods_prefix = "Joker" from starkcore import Organization, Project diff --git a/starkbank/request/__request.py b/starkbank/request/__request.py index 22fa28f..f4f1630 100644 --- a/starkbank/request/__request.py +++ b/starkbank/request/__request.py @@ -1,4 +1,5 @@ from ..utils import rest +from starkbank import request_methods_prefix def get(path, query=None, user=None): @@ -16,7 +17,8 @@ def get(path, query=None, user=None): return rest.get_raw( path=path, query=query, - user=user + user=user, + prefix=request_methods_prefix ) @@ -37,7 +39,8 @@ def post(path, body=None, query=None, user=None): path=path, payload=body, query=query, - user=user + user=user, + prefix=request_methods_prefix ) @@ -56,7 +59,8 @@ def patch(path, body=None, user=None): return rest.patch_raw( path=path, payload=body, - user=user + user=user, + prefix=request_methods_prefix ) @@ -76,7 +80,8 @@ def put(path, body=None, user=None): return rest.put_raw( path=path, payload=body, - user=user + user=user, + prefix=request_methods_prefix ) @@ -96,5 +101,6 @@ def delete(path, body=None, user=None): return rest.delete_raw( path=path, payload=body, - user=user + user=user, + prefix=request_methods_prefix ) diff --git a/tests/sdk/test_request.py b/tests/sdk/test_request.py index 4f712fd..80586fc 100644 --- a/tests/sdk/test_request.py +++ b/tests/sdk/test_request.py @@ -15,22 +15,22 @@ def test_get(self): example_id = starkbank.request.get( path=f'/invoice/', query={"limit": 1, "status": "paid"}, - )["invoices"][0]["id"] + ).json()["invoices"][0]["id"] request = starkbank.request.get( path=f'/invoice/{example_id}', user=exampleProject - ) + ).json() self.assertEqual(request["invoice"]["id"], example_id) def test_get_pdf(self): example_id = starkbank.request.get( path=f'/invoice/', query={"limit": 10, "status": "paid"} - )["invoices"][0]["id"] + ).json()["invoices"][0]["id"] pdf = starkbank.request.get( path=f'/invoice/{example_id}/pdf', - ) + ).content self.assertGreater(len(pdf), 1000) @@ -38,23 +38,22 @@ def test_get_qrcode(self): example_id = starkbank.request.get( path=f'/invoice/', query={"limit": 10, "status": "paid"} - )["invoices"][0]["id"] + ).json()["invoices"][0]["id"] qrcode = starkbank.request.get( path=f'/invoice/{example_id}/qrcode', query={"size": 15}, - ) + ).content self.assertGreater(len(qrcode), 1000) def test_get_reversal_receipt(self): example_id = starkbank.request.get( path=f'/deposit/log/', query={"limit": 1, "types": "reversed"} - ) - example_id = example_id["logs"][0]["id"] + ).json()["logs"][0]["id"] reversal_pdf = starkbank.request.get( path=f'/deposit/log/{example_id}/pdf/', - ) + ).content self.assertGreater(len(reversal_pdf), 1000) def test_get_page(self): @@ -68,7 +67,7 @@ def test_get_page(self): "before": before.strftime("%Y-%m-%d"), "status": "paid" } - ) + ).json() for item in request["invoices"]: self.assertTrue(after.date() <= datetime.strptime(item["created"], "%Y-%m-%dT%H:%M:%S.%f%z").date() <= (before + timedelta(hours=3)).date()) self.assertEqual(10, len(request["invoices"])) @@ -89,7 +88,7 @@ def test_get_pagination(self): "status": "paid", "cursor": cursor } - ) + ).json() cursor = request["cursor"] total_items += len(request["invoices"]) for item in request["invoices"]: @@ -114,7 +113,7 @@ def test_post(self): request = starkbank.request.post( path=f'/invoice/', body=data, - ) + ).json() print(request) @@ -124,18 +123,18 @@ def test_patch(self): initial_state = starkbank.request.get( path=f'/invoice/', query={"limit": 1, "status": "paid"} - ) + ).json() example_id = initial_state["invoices"][0]["id"] amount = initial_state["invoices"][0]["amount"] starkbank.request.patch( path=f'/invoice/{example_id}/', body={"amount": amount - amount}, - ) + ).json() final_state = starkbank.request.get( path=f'/invoice/{example_id}', - ) + ).json() self.assertEqual(final_state["invoice"]["amount"],0) @@ -155,7 +154,7 @@ def test_put(self): body=data, ) - result = starkbank.request.get(path=f'/split-profile/') + result = starkbank.request.get(path=f'/split-profile/').json() self.assertEqual(result["profiles"][0]["delay"], 0) self.assertEqual(result["profiles"][0]["interval"], "day") @@ -185,15 +184,15 @@ def test_delete(self): create = starkbank.request.post( path=f'/transfer/', body=data, - ) + ).json() starkbank.request.delete( path=f'/transfer/{create["transfers"][0]["id"]}', - ) + ).json() final_status = starkbank.request.get( path=f'/transfer/{create["transfers"][0]["id"]}', - )["transfer"]["status"] + ).json()["transfer"]["status"] self.assertEqual(final_status, 'canceled')