-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): Add analytics resources
- Loading branch information
1 parent
ec9de82
commit 8143b81
Showing
16 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
from typing import Any, ClassVar, Type, Union | ||
|
||
from ..base_client import BaseClient | ||
from ..mixins import FindAllCommandMixin | ||
from ..models.gross_revenue import GrossRevenueResponse | ||
from ..services.request import make_headers, make_url, send_get_request | ||
from ..services.response import get_response_data, prepare_index_response, Response | ||
|
||
if sys.version_info >= (3, 9): | ||
from collections.abc import Mapping | ||
else: | ||
from typing import Mapping | ||
|
||
|
||
class GrossRevenueClient( | ||
FindAllCommandMixin[GrossRevenueResponse], | ||
BaseClient, | ||
): | ||
API_RESOURCE: ClassVar[str] = 'gross_revenues' | ||
RESPONSE_MODEL: ClassVar[Type[GrossRevenueResponse]] = GrossRevenueResponse | ||
ROOT_NAME: ClassVar[str] = 'gross_revenue' | ||
|
||
def find_all(self, options: Mapping[str, Union[int, str]] = {}) -> Mapping[str, Any]: | ||
api_response: Response = send_get_request( | ||
url=make_url( | ||
origin=self.base_url, | ||
path_parts=('analytics', 'gross_revenue'), | ||
query_pairs=options, | ||
), | ||
headers=make_headers(api_key=self.api_key), | ||
) | ||
|
||
# Process response data | ||
return prepare_index_response( | ||
api_resource=self.API_RESOURCE, | ||
response_model=self.RESPONSE_MODEL, | ||
data=get_response_data(response=api_response), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import List, Optional | ||
|
||
from ..base_model import BaseModel, BaseResponseModel | ||
|
||
|
||
class GrossRevenueResponse(BaseResponseModel): | ||
amount_cents: Optional[int] | ||
currency: Optional[str] | ||
month: str | ||
|
||
|
||
class GrossRevenuesResponse(BaseResponseModel): | ||
__root__: List[GrossRevenueResponse] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import List, Optional | ||
|
||
from ..base_model import BaseModel, BaseResponseModel | ||
|
||
|
||
class MrrResponse(BaseResponseModel): | ||
amount_cents: Optional[int] | ||
currency: Optional[str] | ||
month: str | ||
|
||
|
||
class MrrsResponse(BaseResponseModel): | ||
__root__: List[MrrResponse] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import List, Optional | ||
|
||
from ..base_model import BaseModel, BaseResponseModel | ||
|
||
|
||
class OutstandingInvoiceResponse(BaseResponseModel): | ||
amount_cents: int | ||
currency: Optional[str] | ||
month: str | ||
invoices_count: int | ||
payment_status: Optional[str] | ||
|
||
|
||
class OutstandingInvoicesResponse(BaseResponseModel): | ||
__root__: List[OutstandingInvoiceResponse] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
from typing import Any, ClassVar, Type, Union | ||
|
||
from ..base_client import BaseClient | ||
from ..mixins import FindAllCommandMixin | ||
from ..models.mrr import MrrResponse | ||
from ..services.request import make_headers, make_url, send_get_request | ||
from ..services.response import get_response_data, prepare_index_response, Response | ||
|
||
if sys.version_info >= (3, 9): | ||
from collections.abc import Mapping | ||
else: | ||
from typing import Mapping | ||
|
||
|
||
class MrrClient( | ||
FindAllCommandMixin[MrrResponse], | ||
BaseClient, | ||
): | ||
API_RESOURCE: ClassVar[str] = 'mrrs' | ||
RESPONSE_MODEL: ClassVar[Type[MrrResponse]] = MrrResponse | ||
ROOT_NAME: ClassVar[str] = 'mrr' | ||
|
||
def find_all(self, options: Mapping[str, Union[int, str]] = {}) -> Mapping[str, Any]: | ||
api_response: Response = send_get_request( | ||
url=make_url( | ||
origin=self.base_url, | ||
path_parts=('analytics', 'mrr'), | ||
query_pairs=options, | ||
), | ||
headers=make_headers(api_key=self.api_key), | ||
) | ||
|
||
# Process response data | ||
return prepare_index_response( | ||
api_resource=self.API_RESOURCE, | ||
response_model=self.RESPONSE_MODEL, | ||
data=get_response_data(response=api_response), | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
from typing import Any, ClassVar, Type, Union | ||
|
||
from ..base_client import BaseClient | ||
from ..mixins import FindAllCommandMixin | ||
from ..models.outstanding_invoice import OutstandingInvoiceResponse | ||
from ..services.request import make_headers, make_url, send_get_request | ||
from ..services.response import get_response_data, prepare_index_response, Response | ||
|
||
if sys.version_info >= (3, 9): | ||
from collections.abc import Mapping | ||
else: | ||
from typing import Mapping | ||
|
||
|
||
class OutstandingInvoiceClient( | ||
FindAllCommandMixin[OutstandingInvoiceResponse], | ||
BaseClient, | ||
): | ||
API_RESOURCE: ClassVar[str] = 'outstanding_invoices' | ||
RESPONSE_MODEL: ClassVar[Type[OutstandingInvoiceResponse]] = OutstandingInvoiceResponse | ||
ROOT_NAME: ClassVar[str] = 'outstanding_invoice' | ||
|
||
def find_all(self, options: Mapping[str, Union[int, str]] = {}) -> Mapping[str, Any]: | ||
api_response: Response = send_get_request( | ||
url=make_url( | ||
origin=self.base_url, | ||
path_parts=('analytics', self.API_RESOURCE), | ||
query_pairs=options, | ||
), | ||
headers=make_headers(api_key=self.api_key), | ||
) | ||
|
||
# Process response data | ||
return prepare_index_response( | ||
api_resource=self.API_RESOURCE, | ||
response_model=self.RESPONSE_MODEL, | ||
data=get_response_data(response=api_response), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"gross_revenues": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD" | ||
} | ||
], | ||
"meta": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"mrrs": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD" | ||
} | ||
], | ||
"meta": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"outstanding_invoices": [ | ||
{ | ||
"month": "2023-11-01T00:00:00.000Z", | ||
"amount_cents": 100, | ||
"currency": "EUR", | ||
"invoices_count": 10, | ||
"payment_status": "pending" | ||
}, | ||
{ | ||
"month": "2023-12-01T00:00:00.000Z", | ||
"amount_cents": 200, | ||
"currency": "USD", | ||
"invoices_count": 5, | ||
"payment_status": "pending" | ||
} | ||
], | ||
"meta": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
|
||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
|
||
from lago_python_client.client import Client | ||
from lago_python_client.exceptions import LagoApiError | ||
from lago_python_client.models.gross_revenue import GrossRevenueResponse | ||
|
||
|
||
def mock_collection_response(): | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(current_dir, 'fixtures/gross_revenue_index.json') | ||
|
||
with open(data_path, 'rb') as gross_revenues_response: | ||
return gross_revenues_response.read() | ||
|
||
|
||
def test_valid_find_all_gross_revenues_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') | ||
|
||
httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/gross_revenue', content=mock_collection_response()) | ||
response = client.gross_revenues.find_all() | ||
|
||
assert response['gross_revenues'][0].currency == 'EUR' | ||
assert response['gross_revenues'][0].amount_cents == 100 | ||
assert response['gross_revenues'][0].month == '2023-11-01T00:00:00.000Z' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
|
||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
|
||
from lago_python_client.client import Client | ||
from lago_python_client.exceptions import LagoApiError | ||
from lago_python_client.models.mrr import MrrResponse | ||
|
||
|
||
def mock_collection_response(): | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(current_dir, 'fixtures/mrr_index.json') | ||
|
||
with open(data_path, 'rb') as mrrs_response: | ||
return mrrs_response.read() | ||
|
||
|
||
def test_valid_find_all_mrrs_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') | ||
|
||
httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/mrr', content=mock_collection_response()) | ||
response = client.mrrs.find_all() | ||
|
||
assert response['mrrs'][0].currency == 'EUR' | ||
assert response['mrrs'][0].amount_cents == 100 | ||
assert response['mrrs'][0].month == '2023-11-01T00:00:00.000Z' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
|
||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
|
||
from lago_python_client.client import Client | ||
from lago_python_client.exceptions import LagoApiError | ||
from lago_python_client.models.outstanding_invoice import OutstandingInvoiceResponse | ||
|
||
|
||
def mock_collection_response(): | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(current_dir, 'fixtures/outstanding_invoice_index.json') | ||
|
||
with open(data_path, 'rb') as outstanding_invoices_response: | ||
return outstanding_invoices_response.read() | ||
|
||
|
||
def test_valid_find_all_outstanding_invoices_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') | ||
|
||
httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/outstanding_invoices', content=mock_collection_response()) | ||
response = client.outstanding_invoices.find_all() | ||
|
||
assert response['outstanding_invoices'][0].currency == 'EUR' | ||
assert response['outstanding_invoices'][0].amount_cents == 100 | ||
assert response['outstanding_invoices'][0].month == '2023-11-01T00:00:00.000Z' | ||
assert response['outstanding_invoices'][0].invoices_count == 10 | ||
assert response['outstanding_invoices'][0].payment_status == 'pending' |