Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions satisfactory_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ def _post(self, function, data=None, files=None):

payload = {'function': function, 'data': data} if data else {'function': function}

response = requests.post(url, json=payload, headers=headers, files=files, verify=False)
response = requests.post(url, json=payload, headers=headers, files=files, verify=False, stream=True)
if response.status_code != 200 and response.status_code != 204:
raise APIError(f"API error: {response.text}")

if response.status_code == 204:
return {}
if response.json().get('errorCode'):
raise APIError(response.json().get('errorMessage'))
return response.json().get('data')

# if response is not json, return the text
print(response.headers.get('Content-Type'))
# use switch
match response.headers.get('Content-Type'):
case 'application/json;charset=utf-8':
if response.json().get('errorCode'):
raise APIError(response.json().get('errorMessage'))
return response.json().get('data')
case 'application/octet-stream':
return response.content
case _:
return response.text

def health_check(self, client_custom_data='') -> (
Response):
Expand Down Expand Up @@ -510,7 +520,7 @@ def download_save_game(self, save_name: str) -> Response:
Returns
-------
Response
A Response indicating the success of the download operation.
A Response indicating the success and the save game in bytes.
"""
response = self._post('DownloadSaveGame', {
'SaveName': save_name
Expand Down
4 changes: 2 additions & 2 deletions satisfactory_api_client/data/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Response:
----------
success : bool
Whether the request was successful.
data : dict
data : dict | str
The data returned from the API.
"""
success: bool
data: dict
data: dict | bytes
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='satisfactory_api_client',
version='0.1.7',
version='0.1.8',
packages=find_packages(exclude=['tests', 'examples']),
install_requires=[
"python-dotenv~=1.0.1",
Expand Down
Loading