Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .idea/api-to-dataframe.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "api-to-dataframe"
version = "0.0.11"
version = "0.1.0"
description = "A package to convert API responses to pandas dataframe"
authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
readme = "README.md"
license = "MIT"
packages = [{ include = "api_to_dataframe", from = "src" }]
classifiers=[
"Development Status :: 1 - Planning",
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
Expand Down
2 changes: 1 addition & 1 deletion src/api_to_dataframe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import run as ApiToDataframe
from api_to_dataframe.main import ClientBuilder
22 changes: 22 additions & 0 deletions src/api_to_dataframe/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
import pandas as pd


class ClientBuilder:
def __init__(self, endpoint: str):
if endpoint == "":
raise ValueError("::: endpoint param is mandatory :::")
else:
self.endpoint = endpoint

def _response_to_json(self):
response = requests.get(self.endpoint)

if response.ok:
return response.json()
else:
raise ConnectionError(response.status_code)

def to_dataframe(self):
df = pd.DataFrame([self._response_to_json()])
return df
6 changes: 0 additions & 6 deletions src/api_to_dataframe/run.py

This file was deleted.

33 changes: 30 additions & 3 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import pytest
from src.api_to_dataframe import run
import pandas as pd
import api_to_dataframe as api_to_dataframe

def test_main():
assert True

@pytest.fixture()
def setup():
new_client = api_to_dataframe.ClientBuilder(endpoint="https://economia.awesomeapi.com.br/last/USD-BRL")
return new_client


def test_constructor_without_param():
with pytest.raises(ValueError):
new_client = api_to_dataframe.ClientBuilder(endpoint="")


def test_constructor_with_param(setup):
expected_result = "https://economia.awesomeapi.com.br/last/USD-BRL"
new_client = setup
assert new_client.endpoint == expected_result


def test_response_to_json(setup):
new_client = setup
response = new_client._response_to_json()
assert isinstance(response, dict)


def test_to_dataframe(setup):
new_client = setup
df = new_client.to_dataframe()
assert isinstance(df, pd.DataFrame)