mirror of
				https://github.com/Eledio/superfaktura-client.git
				synced 2025-10-31 16:11:20 +01:00 
			
		
		
		
	superfaktura_api: allow get request response body in pdf, not only in json
This commit is contained in:
		| @@ -32,11 +32,14 @@ from typing import Dict | |||||||
| import requests | import requests | ||||||
| from dotenv import load_dotenv  # type: ignore | from dotenv import load_dotenv  # type: ignore | ||||||
|  |  | ||||||
|  | from superfaktura.enumerations.data_format import DataFormat | ||||||
|  |  | ||||||
|  |  | ||||||
| class SuperFakturaAPIException(Exception): | class SuperFakturaAPIException(Exception): | ||||||
|     """Exception for errors when working with the SuperFaktura API.""" |     """Exception for errors when working with the SuperFaktura API.""" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class SuperFakturaAPIMissingCredentialsException(Exception): | class SuperFakturaAPIMissingCredentialsException(Exception): | ||||||
|     """Exception for missing login credentials.""" |     """Exception for missing login credentials.""" | ||||||
|  |  | ||||||
| @@ -62,7 +65,7 @@ class SuperFakturaAPI: | |||||||
|             f"{_api_company_id}" |             f"{_api_company_id}" | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     def get(self, endpoint: str, timeout: int = 5) -> Dict: |     def get(self, endpoint: str, data_format: DataFormat = DataFormat.JSON, timeout: int = 5) -> Dict: | ||||||
|         """ |         """ | ||||||
|         Retrieves data from the SuperFaktura API. |         Retrieves data from the SuperFaktura API. | ||||||
|  |  | ||||||
| @@ -90,10 +93,14 @@ class SuperFakturaAPI: | |||||||
|         url = f"{self._api_url}/{endpoint}" |         url = f"{self._api_url}/{endpoint}" | ||||||
|         req = requests.get(url=url, headers=self._auth_header, timeout=timeout) |         req = requests.get(url=url, headers=self._auth_header, timeout=timeout) | ||||||
|         if req.status_code == 200: |         if req.status_code == 200: | ||||||
|             return req.json() |             if data_format == DataFormat.JSON: | ||||||
|         raise SuperFakturaAPIException( |                 return req.json() | ||||||
|             f"Get status code: {req.status_code}; {req.json()}" |             elif data_format == DataFormat.PDF: | ||||||
|         ) |                 return {"pdf": req.content}  # returns a dict with the PDF content | ||||||
|  |         else: | ||||||
|  | 	        raise SuperFakturaAPIException( | ||||||
|  | 	            f"Get status code: {req.status_code}; {req.json()}" | ||||||
|  | 	        ) | ||||||
|  |  | ||||||
|     def post(self, endpoint: str, data: str, timeout: int = 5) -> Dict: |     def post(self, endpoint: str, data: str, timeout: int = 5) -> Dict: | ||||||
|         """ |         """ | ||||||
| @@ -130,6 +137,7 @@ class SuperFakturaAPI: | |||||||
|         ) |         ) | ||||||
|         if req.status_code == 200: |         if req.status_code == 200: | ||||||
|             return req.json() |             return req.json() | ||||||
|         raise SuperFakturaAPIException( |         else: | ||||||
|             f"Post status code: {req.status_code}; {req.json()}" |             raise SuperFakturaAPIException( | ||||||
|         ) |                 f"Post status code: {req.status_code}; {req.json()}" | ||||||
|  |             ) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user