Skip to content

Commit 8d5c213

Browse files
Merge pull request #28 from IvanildoBarauna/feature/entrypoint_definition
FEATURE-EntrypointDefinition
2 parents 32e55de + ff88f57 commit 8d5c213

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

.idea/api-to-dataframe.iml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[tool.poetry]
22
name = "api-to-dataframe"
3-
version = "0.0.11"
3+
version = "0.1.0"
44
description = "A package to convert API responses to pandas dataframe"
55
authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
66
readme = "README.md"
77
license = "MIT"
88
packages = [{ include = "api_to_dataframe", from = "src" }]
99
classifiers=[
10-
"Development Status :: 1 - Planning",
10+
"Development Status :: 2 - Pre-Alpha",
1111
"Intended Audience :: Developers",
1212
"License :: OSI Approved :: MIT License",
1313
"Programming Language :: Python :: 3",

src/api_to_dataframe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import run as ApiToDataframe
1+
from api_to_dataframe.main import ClientBuilder

src/api_to_dataframe/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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

src/api_to_dataframe/run.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/test_run.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
import pytest
2-
from src.api_to_dataframe import run
2+
import pandas as pd
3+
import api_to_dataframe as api_to_dataframe
34

4-
def test_main():
5-
assert True
5+
6+
@pytest.fixture()
7+
def setup():
8+
new_client = api_to_dataframe.ClientBuilder(endpoint="https://economia.awesomeapi.com.br/last/USD-BRL")
9+
return new_client
10+
11+
12+
def test_constructor_without_param():
13+
with pytest.raises(ValueError):
14+
new_client = api_to_dataframe.ClientBuilder(endpoint="")
15+
16+
17+
def test_constructor_with_param(setup):
18+
expected_result = "https://economia.awesomeapi.com.br/last/USD-BRL"
19+
new_client = setup
20+
assert new_client.endpoint == expected_result
21+
22+
23+
def test_response_to_json(setup):
24+
new_client = setup
25+
response = new_client._response_to_json()
26+
assert isinstance(response, dict)
27+
28+
29+
def test_to_dataframe(setup):
30+
new_client = setup
31+
df = new_client.to_dataframe()
32+
assert isinstance(df, pd.DataFrame)

0 commit comments

Comments
 (0)