api-to-dataframe 0.1.0__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: api-to-dataframe
3
- Version: 0.1.0
3
+ Version: 1.0.0
4
4
  Summary: A package to convert API responses to pandas dataframe
5
5
  License: MIT
6
6
  Author: IvanildoBarauna
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "api-to-dataframe"
3
- version = "0.1.0"
3
+ version = "1.0.0"
4
4
  description = "A package to convert API responses to pandas dataframe"
5
5
  authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
6
6
  readme = "README.md"
@@ -0,0 +1,2 @@
1
+ from api_to_dataframe.controller.client_builder import ClientBuilder
2
+ from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
@@ -0,0 +1,9 @@
1
+ from enum import Enum
2
+
3
+
4
+ class RetryStrategies(Enum):
5
+ NoRetryStrategy = 0
6
+ LinearStrategy = 1
7
+ ExponentialStrategy = 2
8
+ CustomStrategy = 3
9
+
@@ -0,0 +1,20 @@
1
+ from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
2
+ from api_to_dataframe.models.get_data import GetData
3
+
4
+
5
+ class ClientBuilder:
6
+ def __init__(self, endpoint: str, retry_strategy: RetryStrategies = RetryStrategies.NoRetryStrategy):
7
+ if endpoint == "":
8
+ raise ValueError("::: endpoint param is mandatory :::")
9
+ else:
10
+ self.endpoint = endpoint
11
+ self.retry_strategy = retry_strategy
12
+
13
+ def get_api_data(self):
14
+ response = GetData.get_response(self.endpoint, self.retry_strategy)
15
+ return response
16
+
17
+ @staticmethod
18
+ def api_to_dataframe(response: dict):
19
+ df = GetData.to_dataframe(response)
20
+ return df
@@ -0,0 +1,24 @@
1
+ import requests
2
+ import pandas as pd
3
+
4
+ from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
5
+
6
+
7
+ class GetData:
8
+ @staticmethod
9
+ def get_response(endpoint: str, RetryStrategies: RetryStrategies):
10
+ response = requests.get(endpoint)
11
+
12
+ if response.ok:
13
+ return response.json()
14
+ else:
15
+ raise ConnectionError(response.status_code)
16
+
17
+ @staticmethod
18
+ def to_dataframe(response):
19
+ df = pd.DataFrame(response)
20
+ if df.empty:
21
+ raise ValueError("::: DataFrame is empty :::")
22
+ else:
23
+ return df
24
+
@@ -0,0 +1,15 @@
1
+ from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
2
+
3
+
4
+ class Retainer:
5
+ @staticmethod
6
+ def strategy(retry_strategy: RetryStrategies = RetryStrategies.NoRetryStrategy):
7
+ if retry_strategy == RetryStrategies.NoRetryStrategy:
8
+ print("::: NoRetryStrategy :::")
9
+ elif retry_strategy == RetryStrategies.LinearStrategy:
10
+ print("::: LinearStrategy :::")
11
+ elif retry_strategy == RetryStrategies.ExponentialStrategy:
12
+ print("::: ExponentialStrategy :::")
13
+ elif retry_strategy == RetryStrategies.CustomStrategy:
14
+ print("::: CustomStrategy :::")
15
+
@@ -1 +0,0 @@
1
- from api_to_dataframe.main import ClientBuilder
@@ -1,22 +0,0 @@
1
- import requests
2
- import pandas as pd
3
-
4
-
5
- class ClientBuilder:
6
- def __init__(self, endpoint: str):
7
- if endpoint == "":
8
- raise ValueError("::: endpoint param is mandatory :::")
9
- else:
10
- self.endpoint = endpoint
11
-
12
- def _response_to_json(self):
13
- response = requests.get(self.endpoint)
14
-
15
- if response.ok:
16
- return response.json()
17
- else:
18
- raise ConnectionError(response.status_code)
19
-
20
- def to_dataframe(self):
21
- df = pd.DataFrame([self._response_to_json()])
22
- return df