Skip to content

Commit 28f13c8

Browse files
feat: Improve Docs, fix level logger to INFO and remove _get_response_data
1 parent 15862f9 commit 28f13c8

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "api-to-dataframe"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
description = "A package to convert API responses to pandas dataframe"
55
authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
66
readme = "README.md"

src/api_to_dataframe/controller/client_builder.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def __init__( # pylint: disable=too-many-arguments
1919
Args:
2020
endpoint (str): The API endpoint to connect to.
2121
headers (dict, optional): The headers to use for the API request. Defaults to None.
22-
retry_strategy (Strategies, optional): Defaults to Strategies.NoRetryStrategy.
22+
retry_strategy (Strategies, optional): Defaults to Strategies.NO_RETRY_STRATEGY.
2323
retries (int): The number of times to retry a failed request. Defaults to 3.
2424
initial_delay (int): The delay between retries in seconds. Defaults to 1.
25-
connection_timeout (int): The timeout for the connection in seconds. Defaults to 2.
25+
connection_timeout (int): The timeout for the connection in seconds. Defaults to 1.
2626
2727
Raises:
2828
ValueError: If endpoint is an empty string.
@@ -58,8 +58,12 @@ def get_api_data(self):
5858
"""
5959
Retrieves data from the API using the defined endpoint and retry strategy.
6060
61+
This function sends a request to the API using the endpoint, headers, and
62+
connection timeout specified in the instance attributes. It uses the
63+
defined retry strategy to handle potential failures and retries.
64+
6165
Returns:
62-
dict: The response from the API.
66+
dict: The JSON response from the API as a dictionary.
6367
"""
6468
response = GetData.get_response(
6569
endpoint=self.endpoint,
@@ -69,16 +73,21 @@ def get_api_data(self):
6973

7074
return response.json()
7175

72-
def _get_raw_api_data(self):
73-
response = GetData.get_response(
74-
endpoint=self.endpoint,
75-
headers=self.headers,
76-
connection_timeout=self.connection_timeout,
77-
)
78-
return response
79-
8076
@staticmethod
8177
def api_to_dataframe(response: dict):
78+
"""
79+
Converts an API response to a DataFrame.
80+
81+
This function takes a dictionary response from an API,
82+
uses the `to_dataframe` function from the `GetData` class
83+
to convert it into a DataFrame, and logs the operation as successful.
84+
85+
Args:
86+
response (dict): The dictionary containing the API response.
87+
88+
Returns:
89+
DataFrame: A pandas DataFrame containing the data from the API response.
90+
"""
8291
df = GetData.to_dataframe(response)
8392
log("serialized to dataframe: OK", LogLevel.INFO)
8493
return df

src/api_to_dataframe/utils/logger.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ class LogLevel(Enum):
1111
# Configure logging once at the start of your program
1212
logging.basicConfig(
1313
encoding="utf-8",
14-
format="%(asctime)s :: %(levelname)s :: %(message)s",
14+
format="%(asctime)s :: api-to-dataframe[%(levelname)s] :: %(message)s",
1515
datefmt="%Y-%m-%d %H:%M:%S %Z",
16-
level=logging.DEBUG,
16+
level=logging.INFO,
1717
)
1818

1919

2020
def log(message: str, level: LogLevel):
2121
logger = logging.getLogger("api-to-dataframe")
2222
logger.log(level.value, message)
23-

tests/test_controller_client_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def test_constructor_with_param(client_setup): # pylint: disable=redefined-oute
6666

6767
def test_response_to_json(client_setup): # pylint: disable=redefined-outer-name
6868
new_client = client_setup
69-
response = new_client._get_raw_api_data() # pylint: disable=protected-access
70-
assert isinstance(response, requests.Response)
69+
response = new_client.get_api_data() # pylint: disable=protected-access
70+
assert isinstance(response, dict)
7171

7272

7373
def test_to_dataframe(response_setup): # pylint: disable=redefined-outer-name

0 commit comments

Comments
 (0)