3
3
4
4
import httpx
5
5
6
+ from .config import API_HOST , API_VERSION
7
+
6
8
7
9
class APIClient :
8
10
"""Client for interacting with the Extend API.
@@ -17,8 +19,6 @@ class APIClient:
17
19
cards = await client.get_virtual_cards()
18
20
```
19
21
"""
20
- BASE_URL = "https://apiv2.paywithextend.com"
21
- API_VERSION = "application/vnd.paywithextend.v2021-03-12+json"
22
22
23
23
_shared_instance : Optional ["APIClient" ] = None
24
24
@@ -33,7 +33,7 @@ def __init__(self, api_key: str, api_secret: str):
33
33
self .headers = {
34
34
"x-extend-api-key" : api_key ,
35
35
"Authorization" : f"Basic { auth_value } " ,
36
- "Accept" : self . API_VERSION
36
+ "Accept" : API_VERSION
37
37
}
38
38
39
39
@classmethod
@@ -70,7 +70,8 @@ async def get(self, url: str, params: Optional[Dict] = None) -> Any:
70
70
response = await client .get (
71
71
self .build_full_url (url ),
72
72
headers = self .headers ,
73
- params = params
73
+ params = params ,
74
+ timeout = httpx .Timeout (30 )
74
75
)
75
76
response .raise_for_status ()
76
77
return response .json ()
@@ -79,7 +80,7 @@ async def post(self, url: str, data: Dict) -> Any:
79
80
"""Make a POST request to the Extend API.
80
81
81
82
Args:
82
- url (str): The API endpoint path (e.g., "virtualcards")
83
+ url (str): The API endpoint path (e.g., "/ virtualcards")
83
84
data (Dict): The JSON payload to send in the request body
84
85
85
86
Returns:
@@ -93,7 +94,8 @@ async def post(self, url: str, data: Dict) -> Any:
93
94
response = await client .post (
94
95
self .build_full_url (url ),
95
96
headers = self .headers ,
96
- json = data
97
+ json = data ,
98
+ timeout = httpx .Timeout (30 )
97
99
)
98
100
response .raise_for_status ()
99
101
return response .json ()
@@ -102,7 +104,7 @@ async def put(self, url: str, data: Dict) -> Any:
102
104
"""Make a PUT request to the Extend API.
103
105
104
106
Args:
105
- url (str): The API endpoint path (e.g., "virtualcards/{card_id}")
107
+ url (str): The API endpoint path (e.g., "/ virtualcards/{card_id}")
106
108
data (Dict): The JSON payload to send in the request body
107
109
108
110
Returns:
@@ -116,10 +118,11 @@ async def put(self, url: str, data: Dict) -> Any:
116
118
response = await client .put (
117
119
self .build_full_url (url ),
118
120
headers = self .headers ,
119
- json = data
121
+ json = data ,
122
+ timeout = httpx .Timeout (30 )
120
123
)
121
124
response .raise_for_status ()
122
125
return response .json ()
123
126
124
127
def build_full_url (self , url : Optional [str ]):
125
- return f"{ self . BASE_URL } { url or '' } "
128
+ return f"https:// { API_HOST } { url or '' } "
0 commit comments