This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jssuzanne/endpoint_exports
Endpoint exports
- Loading branch information
Showing
6 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ parts/ | |
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
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
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
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,48 @@ | ||
from functools import partial | ||
from datetime import datetime | ||
from io import BytesIO | ||
|
||
from . import Base | ||
from ..entities import Export, ExportType, ExportFormat | ||
from ..paginated_results import PaginatedResults | ||
|
||
|
||
class Exports(Base): | ||
EXPORTS_PATH = "/v1/data-exports" | ||
|
||
def create(self, export_type: ExportType, payout_id: str = None, | ||
start: datetime = None, end: datetime = None): | ||
""" Create a new export""" | ||
data = {"type": export_type.value} | ||
if payout_id: | ||
data['payout'] = payout_id | ||
|
||
if start: | ||
data['start'] = int(start.timestamp()) | ||
|
||
if end: | ||
data['end'] = int(end.timestamp()) | ||
|
||
response = self.request(self.EXPORTS_PATH).set_body(data).post() | ||
return Export(response.json) | ||
|
||
def get_file(self, export_id: str, export_format: ExportFormat = None): | ||
request = self.request(f"{self.EXPORTS_PATH}/{export_id}") | ||
if export_format: | ||
request.set_query_params({"format": export_format.value}) | ||
|
||
response = request.get() | ||
return BytesIO(response.resp.content) | ||
|
||
def fetch_all(self, limit: int = 5, **filters): | ||
args = {"limit": limit, **filters} | ||
response = self.request(self.EXPORTS_PATH).set_query_params(args).get() | ||
next_page = partial(self.fetch_all, limit=limit, **filters) | ||
return PaginatedResults(response.json, Export, next_page) | ||
|
||
def fetch(self, export_id: str = None, limit: int = 5, **filters): | ||
if export_id is None: | ||
return self.fetch_all(limit=limit, **filters) | ||
else: | ||
response = self.request(f"{self.EXPORTS_PATH}/{export_id}").get() | ||
return Export(response.json) |
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
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 @@ | ||
from enum import Enum | ||
|
||
from . import Base | ||
|
||
|
||
class ExportType(Enum): | ||
PAYMENTS = "payments" | ||
ACCOUNTING = "accounting" | ||
ACCOUNTING_FOR_PAYOUT = "accounting_for_payout" | ||
|
||
|
||
class ExportFormat(Enum): | ||
CSV = "csv" | ||
PDF = "pdf" | ||
XLSX = "xlsx" | ||
|
||
|
||
class Export(Base): | ||
pass |