@@ -36,6 +36,17 @@ def __init__(
3636 self ._api_token = api_token
3737 self ._base_url = base_url
3838
39+ async def _make_api_request (self , json_payload : dict ) -> dict :
40+ """Make a request to Fogbugz API with common formatting"""
41+ # Fogbugz requires multipart/form-data with stringified JSON
42+ files = {"request" : (None , json .dumps (json_payload ), _JSON_CONTENT_TYPE )}
43+
44+ url = f"{ self ._base_url } /f/api/0/jsonapi"
45+
46+ response = await self ._client .post (url , files = files )
47+ response .raise_for_status ()
48+ return response .json ()
49+
3950 async def create_case (self , data : FogbugzCaseCreate ) -> str :
4051 """Create a new case in Fogbugz"""
4152 json_payload = {
@@ -46,14 +57,7 @@ async def create_case(self, data: FogbugzCaseCreate) -> str:
4657 "sEvent" : data .description ,
4758 }
4859
49- # Fogbugz requires multipart/form-data with stringified JSON
50- files = {"request" : (None , json .dumps (json_payload ), _JSON_CONTENT_TYPE )}
51-
52- url = f"{ self ._base_url } /f/api/0/jsonapi"
53-
54- response = await self ._client .post (url , files = files )
55- response .raise_for_status ()
56- response_data = response .json ()
60+ response_data = await self ._make_api_request (json_payload )
5761
5862 # Fogbugz API returns case ID in the response
5963 case_id = response_data .get ("data" , {}).get ("case" , {}).get ("ixBug" , None )
@@ -71,14 +75,7 @@ async def resolve_case(self, case_id: str) -> None:
7175 "ixBug" : case_id ,
7276 }
7377
74- # Fogbugz requires multipart/form-data with stringified JSON
75- files = {"request" : (None , json .dumps (json_payload ), _JSON_CONTENT_TYPE )}
76-
77- url = f"{ self ._base_url } /f/api/0/jsonapi"
78-
79- response = await self ._client .post (url , files = files )
80- response .raise_for_status ()
81- response_data = response .json ()
78+ response_data = await self ._make_api_request (json_payload )
8279
8380 # Check if the operation was successful
8481 if response_data .get ("error" ):
@@ -95,14 +92,7 @@ async def get_case_status(self, case_id: str) -> str:
9592 "cols" : "sStatus" ,
9693 }
9794
98- # Fogbugz requires multipart/form-data with stringified JSON
99- files = {"request" : (None , json .dumps (json_payload ), _JSON_CONTENT_TYPE )}
100-
101- url = f"{ self ._base_url } /f/api/0/jsonapi"
102-
103- response = await self ._client .post (url , files = files )
104- response .raise_for_status ()
105- response_data = response .json ()
95+ response_data = await self ._make_api_request (json_payload )
10696
10797 # Check if the operation was successful
10898 if response_data .get ("error" ):
@@ -156,14 +146,7 @@ async def reopen_case(self, case_id: str, assigned_fogbugz_person_id: str) -> No
156146 "ixPersonAssignedTo" : assigned_fogbugz_person_id ,
157147 }
158148
159- # Fogbugz requires multipart/form-data with stringified JSON
160- files = {"request" : (None , json .dumps (json_payload ), _JSON_CONTENT_TYPE )}
161-
162- url = f"{ self ._base_url } /f/api/0/jsonapi"
163-
164- response = await self ._client .post (url , files = files )
165- response .raise_for_status ()
166- response_data = response .json ()
149+ response_data = await self ._make_api_request (json_payload )
167150
168151 # Check if the operation was successful
169152 if response_data .get ("error" ):
0 commit comments