Skip to content

Commit fbbf03b

Browse files
feat: Class Methods Define + write tests
1 parent 32e55de commit fbbf03b

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

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 src.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.url)
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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import pytest
2-
from src.api_to_dataframe import run
2+
import src.api_to_dataframe as apitodf
33

4-
def test_main():
5-
assert True
4+
5+
def test_constructor_without_param():
6+
with pytest.raises(ValueError):
7+
new_client = apitodf.ClientBuilder(endpoint="")
8+
9+
10+
@pytest.fixture()
11+
def test_constructor_with_param():
12+
expected_result = "param1"
13+
new_client = apitodf.ClientBuilder(endpoint=expected_result)
14+
assert new_client.endpoint == expected_result
15+
return new_client
16+
17+
18+
def test_response_to_json_with_valid_endpoint(test_constructor_with_param):
19+
pass

0 commit comments

Comments
 (0)