33
44import httpx
55
6+ from .config import API_HOST , API_VERSION
7+
68
79class APIClient :
810 """Client for interacting with the Extend API.
@@ -17,8 +19,6 @@ class APIClient:
1719 cards = await client.get_virtual_cards()
1820 ```
1921 """
20- BASE_URL = "https://apiv2.paywithextend.com"
21- API_VERSION = "application/vnd.paywithextend.v2021-03-12+json"
2222
2323 _shared_instance : Optional ["APIClient" ] = None
2424
@@ -33,7 +33,7 @@ def __init__(self, api_key: str, api_secret: str):
3333 self .headers = {
3434 "x-extend-api-key" : api_key ,
3535 "Authorization" : f"Basic { auth_value } " ,
36- "Accept" : self . API_VERSION
36+ "Accept" : API_VERSION
3737 }
3838
3939 @classmethod
@@ -70,7 +70,8 @@ async def get(self, url: str, params: Optional[Dict] = None) -> Any:
7070 response = await client .get (
7171 self .build_full_url (url ),
7272 headers = self .headers ,
73- params = params
73+ params = params ,
74+ timeout = httpx .Timeout (30 )
7475 )
7576 response .raise_for_status ()
7677 return response .json ()
@@ -79,7 +80,7 @@ async def post(self, url: str, data: Dict) -> Any:
7980 """Make a POST request to the Extend API.
8081
8182 Args:
82- url (str): The API endpoint path (e.g., "virtualcards")
83+ url (str): The API endpoint path (e.g., "/ virtualcards")
8384 data (Dict): The JSON payload to send in the request body
8485
8586 Returns:
@@ -93,7 +94,8 @@ async def post(self, url: str, data: Dict) -> Any:
9394 response = await client .post (
9495 self .build_full_url (url ),
9596 headers = self .headers ,
96- json = data
97+ json = data ,
98+ timeout = httpx .Timeout (30 )
9799 )
98100 response .raise_for_status ()
99101 return response .json ()
@@ -102,7 +104,7 @@ async def put(self, url: str, data: Dict) -> Any:
102104 """Make a PUT request to the Extend API.
103105
104106 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}")
106108 data (Dict): The JSON payload to send in the request body
107109
108110 Returns:
@@ -116,10 +118,11 @@ async def put(self, url: str, data: Dict) -> Any:
116118 response = await client .put (
117119 self .build_full_url (url ),
118120 headers = self .headers ,
119- json = data
121+ json = data ,
122+ timeout = httpx .Timeout (30 )
120123 )
121124 response .raise_for_status ()
122125 return response .json ()
123126
124127 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