bdomarket.response¶
ApiResponse
¶
Represents a standardized API response, encapsulating success status, HTTP status code, message, and content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
success
|
bool
|
Indicates if the response was successful. |
False
|
status_code
|
int
|
The HTTP status code of the response. |
None
|
message
|
str
|
A message describing the response. |
'No message provided'
|
content
|
Any
|
The content of the response, can be dict, str, or bytes for images. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Indicates if the response was successful. |
status_code |
int
|
The HTTP status code of the response. |
message |
str
|
A message describing the response. |
content |
Any
|
The content of the response. |
url |
str
|
The URL of the response. |
headers |
str
|
The headers of the response. |
__str__()
¶
String representation of the ApiResponse object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string containing the success status, status code, message, and content of the response. |
save_image(path)
¶
Save the image content to a file if it's binary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The file path where the image should be saved. |
required |
save_to_file(path, mode='w')
¶
Save the ApiResponse content to a file. Handles JSON or binary image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The file path where the content should be saved. |
required |
show_image()
¶
Display the image if content is binary using PIL.