Skip to content

Commit f0095a7

Browse files
committed
feat: refactor clients
1 parent 953ff9d commit f0095a7

File tree

9 files changed

+123
-37
lines changed

9 files changed

+123
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ venv/
22
__pycache__/
33
*.pyc
44
*.pyo
5+
.env

poetry.lock

Lines changed: 87 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ idna = "3.10"
2626
urllib3 = "2.2.3"
2727
pycardano = "^0.12.3"
2828

29-
[tool.poetry.dev-dependencies]
29+
[tool.poetry.group.dev.dependencies]
3030
pytest = "^8.2.0"
3131
pytest-xdist = "^3.5.0"
3232
pytest-cov = "^5.0.0"

src/deltadefi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .clients import ApiClient
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# flake8: noqa
2-
from .api_config import *
32
from .auth import *
43
from .validation import *

src/deltadefi/api_resources/api_config.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/deltadefi/clients/clients.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# flake8: noqa: E501
2-
from typing import Optional
3-
42
from sidan_gin import HDWallet
53

6-
from deltadefi.api_resources.api_config import ApiConfig
74
from deltadefi.api_resources.auth import ApiHeaders
85
from deltadefi.clients.accounts import Accounts
96
from deltadefi.clients.markets import Markets
@@ -19,9 +16,11 @@ class ApiClient:
1916

2017
def __init__(
2118
self,
22-
config: ApiConfig,
23-
wallet: HDWallet,
24-
base_url: Optional[str] = None,
19+
network: str = "preprod",
20+
jwt: str = None,
21+
api_key: str = None,
22+
wallet: HDWallet = None,
23+
base_url: str = None,
2524
):
2625
"""
2726
Initialize the ApiClient.
@@ -36,18 +35,20 @@ def __init__(
3635
"Content-Type": "application/json",
3736
}
3837

39-
if config.get("network"):
40-
self.network_id = 1 if config["network"] == "mainnet" else 0
41-
base_url = (
42-
"https://api-dev.deltadefi.io"
43-
if config["network"] == "mainnet"
44-
else "https://api-dev.deltadefi.io" # TODO: input production link once available
45-
)
46-
if config.get("jwt"):
47-
headers["Authorization"] = config["jwt"]
48-
if config.get("apiKey"):
49-
headers["X-API-KEY"] = config["apiKey"]
50-
if config.get("signingKey"):
38+
if network == "mainnet":
39+
self.network_id = 1
40+
base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
41+
else:
42+
self.network_id = 0
43+
base_url = "https://api-dev.deltadefi.io"
44+
45+
if jwt is not None:
46+
headers["Authorization"] = jwt
47+
48+
if api_key is not None:
49+
headers["X-API-KEY"] = api_key
50+
51+
if wallet is not None:
5152
self.wallet = wallet.signing_key
5253

5354
self.accounts = Accounts(self)

test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
import sys
3+
4+
# Add the src directory to the Python path
5+
sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
6+
7+
8+
from deltadefi import ApiClient
9+
10+
api = ApiClient(api_key="b13abb5bb86b96da341b59bc66612cc5")
11+
account_balance = api.accounts.getAccountBalance()
12+
13+
print(account_balance)

tests/clients/test_accounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestAccounts(unittest.TestCase):
1111

1212
def test_sign_in(self):
1313
# Arrange
14-
api = ApiClient(config={}, wallet=None, base_url="http://localhost:8080")
14+
api = ApiClient()
1515
sign_in_data: SignInRequest = {
1616
"wallet_address": "addr_test1qqzgg5pcaeyea69uptl9da5g7fajm4m0yvxndx9f4lxpkehqgezy0s04rtdwlc0tlvxafpdrfxnsg7ww68ge3j7l0lnszsw2wt",
1717
"auth_key": "test",

0 commit comments

Comments
 (0)