Skip to content

Commit 4d72da4

Browse files
authored
feat(billing): implement v2alpha1 (#96)
1 parent 90097ce commit 4d72da4

File tree

10 files changed

+1042
-0
lines changed

10 files changed

+1042
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was automatically generated. DO NOT EDIT.
2+
# If you have any remark or suggestion do not hesitate to open an issue.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file was automatically generated. DO NOT EDIT.
2+
# If you have any remark or suggestion do not hesitate to open an issue.
3+
from .types import DownloadInvoiceRequestFileType
4+
from .types import InvoiceType
5+
from .types import ListInvoicesRequestOrderBy
6+
from .types import GetConsumptionResponse
7+
from .types import GetConsumptionResponseConsumption
8+
from .types import Invoice
9+
from .types import ListInvoicesResponse
10+
from .api import BillingV2Alpha1API
11+
12+
__all__ = [
13+
"DownloadInvoiceRequestFileType",
14+
"InvoiceType",
15+
"ListInvoicesRequestOrderBy",
16+
"GetConsumptionResponse",
17+
"GetConsumptionResponseConsumption",
18+
"Invoice",
19+
"ListInvoicesResponse",
20+
"BillingV2Alpha1API",
21+
]
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# This file was automatically generated. DO NOT EDIT.
2+
# If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
from datetime import datetime
5+
from typing import List, Optional
6+
7+
from scaleway_core.api import API
8+
from scaleway_core.bridge import (
9+
ScwFile,
10+
unmarshal_ScwFile,
11+
)
12+
from scaleway_core.utils import (
13+
fetch_all_pages_async,
14+
validate_path_param,
15+
)
16+
from .types import (
17+
DownloadInvoiceRequestFileType,
18+
InvoiceType,
19+
ListInvoicesRequestOrderBy,
20+
GetConsumptionResponse,
21+
Invoice,
22+
ListInvoicesResponse,
23+
)
24+
from .marshalling import (
25+
unmarshal_GetConsumptionResponse,
26+
unmarshal_ListInvoicesResponse,
27+
)
28+
29+
30+
class BillingV2Alpha1API(API):
31+
"""
32+
Billing API.
33+
34+
This API allows you to query your consumption.
35+
Billing API.
36+
"""
37+
38+
async def get_consumption(
39+
self,
40+
*,
41+
organization_id: Optional[str] = None,
42+
) -> GetConsumptionResponse:
43+
"""
44+
45+
Usage:
46+
::
47+
48+
result = await api.get_consumption()
49+
"""
50+
51+
res = self._request(
52+
"GET",
53+
f"/billing/v2alpha1/consumption",
54+
params={
55+
"organization_id": organization_id
56+
or self.client.default_organization_id,
57+
},
58+
)
59+
60+
self._throw_on_error(res)
61+
return unmarshal_GetConsumptionResponse(res.json())
62+
63+
async def list_invoices(
64+
self,
65+
*,
66+
organization_id: Optional[str] = None,
67+
started_after: Optional[datetime] = None,
68+
started_before: Optional[datetime] = None,
69+
invoice_type: InvoiceType = InvoiceType.UNKNOWN_TYPE,
70+
page: Optional[int] = None,
71+
page_size: Optional[int] = None,
72+
order_by: ListInvoicesRequestOrderBy = ListInvoicesRequestOrderBy.INVOICE_NUMBER_DESC,
73+
) -> ListInvoicesResponse:
74+
"""
75+
76+
Usage:
77+
::
78+
79+
result = await api.list_invoices()
80+
"""
81+
82+
res = self._request(
83+
"GET",
84+
f"/billing/v2alpha1/invoices",
85+
params={
86+
"invoice_type": invoice_type,
87+
"order_by": order_by,
88+
"organization_id": organization_id
89+
or self.client.default_organization_id,
90+
"page": page,
91+
"page_size": page_size or self.client.default_page_size,
92+
"started_after": started_after,
93+
"started_before": started_before,
94+
},
95+
)
96+
97+
self._throw_on_error(res)
98+
return unmarshal_ListInvoicesResponse(res.json())
99+
100+
async def list_invoices_all(
101+
self,
102+
*,
103+
organization_id: Optional[str] = None,
104+
started_after: Optional[datetime] = None,
105+
started_before: Optional[datetime] = None,
106+
invoice_type: Optional[InvoiceType] = None,
107+
page: Optional[int] = None,
108+
page_size: Optional[int] = None,
109+
order_by: Optional[ListInvoicesRequestOrderBy] = None,
110+
) -> List[Invoice]:
111+
"""
112+
:return: :class:`List[ListInvoicesResponse] <List[ListInvoicesResponse]>`
113+
114+
Usage:
115+
::
116+
117+
result = await api.list_invoices_all()
118+
"""
119+
120+
return await fetch_all_pages_async(
121+
type=ListInvoicesResponse,
122+
key="invoices",
123+
fetcher=self.list_invoices,
124+
args={
125+
"organization_id": organization_id,
126+
"started_after": started_after,
127+
"started_before": started_before,
128+
"invoice_type": invoice_type,
129+
"page": page,
130+
"page_size": page_size,
131+
"order_by": order_by,
132+
},
133+
)
134+
135+
async def download_invoice(
136+
self,
137+
*,
138+
invoice_id: str,
139+
file_type: DownloadInvoiceRequestFileType,
140+
) -> Optional[ScwFile]:
141+
"""
142+
143+
Usage:
144+
::
145+
146+
result = await api.download_invoice(
147+
invoice_id="example",
148+
file_type=pdf,
149+
)
150+
"""
151+
152+
param_invoice_id = validate_path_param("invoice_id", invoice_id)
153+
154+
res = self._request(
155+
"GET",
156+
f"/billing/v2alpha1/invoices/{param_invoice_id}/download",
157+
params={
158+
"file_type": file_type,
159+
},
160+
)
161+
162+
self._throw_on_error(res)
163+
json = res.json()
164+
return unmarshal_ScwFile(json) if json is not None else None
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# This file was automatically generated. DO NOT EDIT.
2+
# If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
from typing import Any, Dict
5+
6+
from scaleway_core.bridge import (
7+
unmarshal_Money,
8+
)
9+
from dateutil import parser
10+
from .types import (
11+
GetConsumptionResponse,
12+
GetConsumptionResponseConsumption,
13+
Invoice,
14+
ListInvoicesResponse,
15+
)
16+
17+
18+
def unmarshal_GetConsumptionResponseConsumption(
19+
data: Any,
20+
) -> GetConsumptionResponseConsumption:
21+
if type(data) is not dict:
22+
raise TypeError(
23+
f"Unmarshalling the type 'GetConsumptionResponseConsumption' failed as data isn't a dictionary."
24+
)
25+
26+
args: Dict[str, Any] = {}
27+
28+
field = data.get("category")
29+
args["category"] = field
30+
31+
field = data.get("description")
32+
args["description"] = field
33+
34+
field = data.get("operation_path")
35+
args["operation_path"] = field
36+
37+
field = data.get("project_id")
38+
args["project_id"] = field
39+
40+
field = data.get("value")
41+
args["value"] = unmarshal_Money(field) if field is not None else None
42+
43+
return GetConsumptionResponseConsumption(**args)
44+
45+
46+
def unmarshal_Invoice(data: Any) -> Invoice:
47+
if type(data) is not dict:
48+
raise TypeError(
49+
f"Unmarshalling the type 'Invoice' failed as data isn't a dictionary."
50+
)
51+
52+
args: Dict[str, Any] = {}
53+
54+
field = data.get("due_date")
55+
args["due_date"] = parser.isoparse(field) if type(field) is str else field
56+
57+
field = data.get("id")
58+
args["id"] = field
59+
60+
field = data.get("invoice_type")
61+
args["invoice_type"] = field
62+
63+
field = data.get("issued_date")
64+
args["issued_date"] = parser.isoparse(field) if type(field) is str else field
65+
66+
field = data.get("number")
67+
args["number"] = field
68+
69+
field = data.get("start_date")
70+
args["start_date"] = parser.isoparse(field) if type(field) is str else field
71+
72+
field = data.get("total_taxed")
73+
args["total_taxed"] = unmarshal_Money(field) if field is not None else None
74+
75+
field = data.get("total_untaxed")
76+
args["total_untaxed"] = unmarshal_Money(field) if field is not None else None
77+
78+
return Invoice(**args)
79+
80+
81+
def unmarshal_GetConsumptionResponse(data: Any) -> GetConsumptionResponse:
82+
if type(data) is not dict:
83+
raise TypeError(
84+
f"Unmarshalling the type 'GetConsumptionResponse' failed as data isn't a dictionary."
85+
)
86+
87+
args: Dict[str, Any] = {}
88+
89+
field = data.get("consumptions")
90+
args["consumptions"] = [
91+
unmarshal_GetConsumptionResponseConsumption(v) for v in data["consumptions"]
92+
]
93+
94+
field = data.get("updated_at")
95+
args["updated_at"] = parser.isoparse(field) if type(field) is str else field
96+
97+
return GetConsumptionResponse(**args)
98+
99+
100+
def unmarshal_ListInvoicesResponse(data: Any) -> ListInvoicesResponse:
101+
if type(data) is not dict:
102+
raise TypeError(
103+
f"Unmarshalling the type 'ListInvoicesResponse' failed as data isn't a dictionary."
104+
)
105+
106+
args: Dict[str, Any] = {}
107+
108+
field = data.get("invoices")
109+
args["invoices"] = [unmarshal_Invoice(v) for v in data["invoices"]]
110+
111+
field = data.get("total_count")
112+
args["total_count"] = field
113+
114+
return ListInvoicesResponse(**args)

0 commit comments

Comments
 (0)