Merge pull request #7 from StevanFreeborn/stevanfreeborn/fix/stop-mutating-client-headers

fix: stop mutating client headers
This commit is contained in:
Stevan Freeborn
2024-12-18 18:00:01 -06:00
committed by GitHub
+32 -20
View File
@@ -15,6 +15,7 @@ class OnspringClient:
baseUrl (`str`): The url that should be used as the base for all requests made by the client. baseUrl (`str`): The url that should be used as the base for all requests made by the client.
headers (`dict`): Contains key value pairs of the headers necessary for all requests made by the client including the necessary api key. headers (`dict`): Contains key value pairs of the headers necessary for all requests made by the client including the necessary api key.
""" """
def __init__(self, url: str, key: str): def __init__(self, url: str, key: str):
self.baseUrl = url self.baseUrl = url
self.headers = { self.headers = {
@@ -183,7 +184,8 @@ class OnspringClient:
endpoint = GetAppsByIdsEndpoint(self.baseUrl) endpoint = GetAppsByIdsEndpoint(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
# make sure appIds can be serialized to json string # make sure appIds can be serialized to json string
if not isinstance(appIds, (list, tuple)): if not isinstance(appIds, (list, tuple)):
@@ -196,7 +198,7 @@ class OnspringClient:
response = requests.request( response = requests.request(
'POST', 'POST',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=appIds) data=appIds)
if response.status_code == 401: if response.status_code == 401:
@@ -344,7 +346,8 @@ class OnspringClient:
endpoint = GetFieldsByIdsEndpoint(self.baseUrl) endpoint = GetFieldsByIdsEndpoint(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
# make sure fieldIds can be serialized to json string # make sure fieldIds can be serialized to json string
if not isinstance(fieldIds, (list, tuple)): if not isinstance(fieldIds, (list, tuple)):
@@ -357,7 +360,7 @@ class OnspringClient:
response = requests.request( response = requests.request(
'POST', 'POST',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=fieldIds) data=fieldIds)
if response.status_code == 401: if response.status_code == 401:
@@ -752,7 +755,6 @@ class OnspringClient:
data, data,
raw=response) raw=response)
return ApiResponse( return ApiResponse(
response.status_code, response.status_code,
raw=response) raw=response)
@@ -773,7 +775,8 @@ class OnspringClient:
files = [ files = [
( (
'File', 'File',
(saveFileRequest.fileName, open(saveFileRequest.filePath,'rb'),saveFileRequest.contentType) (saveFileRequest.fileName, open(
saveFileRequest.filePath, 'rb'), saveFileRequest.contentType)
) )
] ]
@@ -842,9 +845,11 @@ class OnspringClient:
An ApiResponse (`Models.ApiResponse`) containing the results of the request. An ApiResponse (`Models.ApiResponse`) containing the results of the request.
""" """
endpoint = AddOrUpdateListItemEndpoint(self.baseUrl, listItemRequest.listId) endpoint = AddOrUpdateListItemEndpoint(
self.baseUrl, listItemRequest.listId)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
del listItemRequest.__dict__['listId'] del listItemRequest.__dict__['listId']
@@ -853,7 +858,7 @@ class OnspringClient:
response = requests.request( response = requests.request(
'PUT', 'PUT',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=requestData) data=requestData)
if response.status_code == 401: if response.status_code == 401:
@@ -966,7 +971,8 @@ class OnspringClient:
An ApiResponse (`Models.ApiResponse`) containing the results of the request. An ApiResponse (`Models.ApiResponse`) containing the results of the request.
""" """
endpoint = GetRecordsByAppIdEndpoint(self.baseUrl, getRecordsByAppRequest.appId) endpoint = GetRecordsByAppIdEndpoint(
self.baseUrl, getRecordsByAppRequest.appId)
params = getRecordsByAppRequest.__dict__ params = getRecordsByAppRequest.__dict__
del params['appId'] del params['appId']
@@ -1060,7 +1066,8 @@ class OnspringClient:
An ApiResponse (`Models.ApiResponse`) containing the results of the request. An ApiResponse (`Models.ApiResponse`) containing the results of the request.
""" """
endpoint = GetRecordByIdEndpoint(self.baseUrl, getRecordByIdRequest.appId, getRecordByIdRequest.recordId) endpoint = GetRecordByIdEndpoint(
self.baseUrl, getRecordByIdRequest.appId, getRecordByIdRequest.recordId)
params = getRecordByIdRequest.__dict__ params = getRecordByIdRequest.__dict__
del params['appId'] del params['appId']
@@ -1193,14 +1200,15 @@ class OnspringClient:
endpoint = GetRecordsByIdsEndpoint(self.baseUrl) endpoint = GetRecordsByIdsEndpoint(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
requestData = json.dumps(getBatchRecordsRequest.__dict__) requestData = json.dumps(getBatchRecordsRequest.__dict__)
response = requests.request( response = requests.request(
'POST', 'POST',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=requestData) data=requestData)
if response.status_code == 400: if response.status_code == 400:
@@ -1284,7 +1292,8 @@ class OnspringClient:
endpoint = QueryRecordsEndpoint(self.baseUrl) endpoint = QueryRecordsEndpoint(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
requestData = queryRecordsRequest.__dict__ requestData = queryRecordsRequest.__dict__
@@ -1297,7 +1306,7 @@ class OnspringClient:
response = requests.request( response = requests.request(
'POST', 'POST',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=requestData, data=requestData,
params=params) params=params)
@@ -1385,7 +1394,8 @@ class OnspringClient:
endpoint = AddOrUpdateRecordEndpoint(self.baseUrl) endpoint = AddOrUpdateRecordEndpoint(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
fieldsDict = {} fieldsDict = {}
@@ -1399,7 +1409,7 @@ class OnspringClient:
response = requests.request( response = requests.request(
'PUT', 'PUT',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=requestData) data=requestData)
if response.status_code == 400: if response.status_code == 400:
@@ -1461,14 +1471,15 @@ class OnspringClient:
endpoint = DeleteRecordsByIds(self.baseUrl) endpoint = DeleteRecordsByIds(self.baseUrl)
self.headers['Content-Type'] = 'application/json' headers = self.headers.copy()
headers['Content-Type'] = 'application/json'
requestData = json.dumps(deleteBatchRecordsRequest.__dict__) requestData = json.dumps(deleteBatchRecordsRequest.__dict__)
response = requests.request( response = requests.request(
'POST', 'POST',
endpoint, endpoint,
headers=self.headers, headers=headers,
data=requestData) data=requestData)
if response.status_code == 400: if response.status_code == 400:
@@ -1525,7 +1536,8 @@ class OnspringClient:
An ApiResponse (`Models.ApiResponse`) containing the results of the request. An ApiResponse (`Models.ApiResponse`) containing the results of the request.
""" """
endpoint = GetReportByIdEndpoint(self.baseUrl, getReportByIdRequest.reportId) endpoint = GetReportByIdEndpoint(
self.baseUrl, getReportByIdRequest.reportId)
params = getReportByIdRequest.__dict__ params = getReportByIdRequest.__dict__
del params['reportId'] del params['reportId']