Skip to content

Commit 0477161

Browse files
authored
feat(billing): discount application scope endpoint (#344)
1 parent 1f991bb commit 0477161

File tree

8 files changed

+722
-0
lines changed

8 files changed

+722
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
3+
from .types import DiscountDiscountMode
4+
from .types import DiscountFilterType
35
from .types import DownloadInvoiceRequestFileType
46
from .types import InvoiceType
7+
from .types import ListDiscountsRequestOrderBy
58
from .types import ListInvoicesRequestOrderBy
9+
from .types import Discount
10+
from .types import DiscountCoupon
11+
from .types import DiscountFilter
612
from .types import GetConsumptionResponse
713
from .types import GetConsumptionResponseConsumption
814
from .types import Invoice
15+
from .types import ListDiscountsResponse
916
from .types import ListInvoicesResponse
1017
from .api import BillingV2Alpha1API
1118

1219
__all__ = [
20+
"DiscountDiscountMode",
21+
"DiscountFilterType",
1322
"DownloadInvoiceRequestFileType",
1423
"InvoiceType",
24+
"ListDiscountsRequestOrderBy",
1525
"ListInvoicesRequestOrderBy",
26+
"Discount",
27+
"DiscountCoupon",
28+
"DiscountFilter",
1629
"GetConsumptionResponse",
1730
"GetConsumptionResponseConsumption",
1831
"Invoice",
32+
"ListDiscountsResponse",
1933
"ListInvoicesResponse",
2034
"BillingV2Alpha1API",
2135
]

scaleway-async/scaleway_async/billing/v2alpha1/api.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
from .types import (
1717
DownloadInvoiceRequestFileType,
1818
InvoiceType,
19+
ListDiscountsRequestOrderBy,
1920
ListInvoicesRequestOrderBy,
21+
Discount,
2022
GetConsumptionResponse,
2123
Invoice,
24+
ListDiscountsResponse,
2225
ListInvoicesResponse,
2326
)
2427
from .marshalling import (
2528
unmarshal_GetConsumptionResponse,
29+
unmarshal_ListDiscountsResponse,
2630
unmarshal_ListInvoicesResponse,
2731
)
2832

@@ -191,3 +195,76 @@ async def download_invoice(
191195
self._throw_on_error(res)
192196
json = res.json()
193197
return unmarshal_ScwFile(json) if json is not None else None
198+
199+
async def list_discounts(
200+
self,
201+
*,
202+
order_by: ListDiscountsRequestOrderBy = ListDiscountsRequestOrderBy.CREATION_DATE_DESC,
203+
page: Optional[int] = None,
204+
page_size: Optional[int] = None,
205+
organization_id: Optional[str] = None,
206+
) -> ListDiscountsResponse:
207+
"""
208+
List all user's discounts.
209+
List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.
210+
:param order_by: Order discounts in the response by their description.
211+
:param page: Positive integer to choose the page to return.
212+
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
213+
:param organization_id: ID of the organization.
214+
:return: :class:`ListDiscountsResponse <ListDiscountsResponse>`
215+
216+
Usage:
217+
::
218+
219+
result = await api.list_discounts()
220+
"""
221+
222+
res = self._request(
223+
"GET",
224+
f"/billing/v2alpha1/discounts",
225+
params={
226+
"order_by": order_by,
227+
"organization_id": organization_id
228+
or self.client.default_organization_id,
229+
"page": page,
230+
"page_size": page_size or self.client.default_page_size,
231+
},
232+
)
233+
234+
self._throw_on_error(res)
235+
return unmarshal_ListDiscountsResponse(res.json())
236+
237+
async def list_discounts_all(
238+
self,
239+
*,
240+
order_by: Optional[ListDiscountsRequestOrderBy] = None,
241+
page: Optional[int] = None,
242+
page_size: Optional[int] = None,
243+
organization_id: Optional[str] = None,
244+
) -> List[Discount]:
245+
"""
246+
List all user's discounts.
247+
List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.
248+
:param order_by: Order discounts in the response by their description.
249+
:param page: Positive integer to choose the page to return.
250+
:param page_size: Positive integer lower or equal to 100 to select the number of items to return.
251+
:param organization_id: ID of the organization.
252+
:return: :class:`List[ListDiscountsResponse] <List[ListDiscountsResponse]>`
253+
254+
Usage:
255+
::
256+
257+
result = await api.list_discounts_all()
258+
"""
259+
260+
return await fetch_all_pages_async(
261+
type=ListDiscountsResponse,
262+
key="discounts",
263+
fetcher=self.list_discounts,
264+
args={
265+
"order_by": order_by,
266+
"page": page,
267+
"page_size": page_size,
268+
"organization_id": organization_id,
269+
},
270+
)

scaleway-async/scaleway_async/billing/v2alpha1/marshalling.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,97 @@
88
)
99
from dateutil import parser
1010
from .types import (
11+
Discount,
12+
DiscountCoupon,
13+
DiscountFilter,
1114
GetConsumptionResponse,
1215
GetConsumptionResponseConsumption,
1316
Invoice,
17+
ListDiscountsResponse,
1418
ListInvoicesResponse,
1519
)
1620

1721

22+
def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon:
23+
if type(data) is not dict:
24+
raise TypeError(
25+
f"Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary."
26+
)
27+
28+
args: Dict[str, Any] = {}
29+
30+
field = data.get("description", None)
31+
args["description"] = field
32+
33+
return DiscountCoupon(**args)
34+
35+
36+
def unmarshal_DiscountFilter(data: Any) -> DiscountFilter:
37+
if type(data) is not dict:
38+
raise TypeError(
39+
f"Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary."
40+
)
41+
42+
args: Dict[str, Any] = {}
43+
44+
field = data.get("type", None)
45+
args["type_"] = field
46+
47+
field = data.get("value", None)
48+
args["value"] = field
49+
50+
return DiscountFilter(**args)
51+
52+
53+
def unmarshal_Discount(data: Any) -> Discount:
54+
if type(data) is not dict:
55+
raise TypeError(
56+
f"Unmarshalling the type 'Discount' failed as data isn't a dictionary."
57+
)
58+
59+
args: Dict[str, Any] = {}
60+
61+
field = data.get("coupon", None)
62+
args["coupon"] = unmarshal_DiscountCoupon(field) if field is not None else None
63+
64+
field = data.get("creation_date", None)
65+
args["creation_date"] = parser.isoparse(field) if type(field) is str else field
66+
67+
field = data.get("description", None)
68+
args["description"] = field
69+
70+
field = data.get("filters", None)
71+
args["filters"] = (
72+
[unmarshal_DiscountFilter(v) for v in field] if field is not None else None
73+
)
74+
75+
field = data.get("id", None)
76+
args["id"] = field
77+
78+
field = data.get("mode", None)
79+
args["mode"] = field
80+
81+
field = data.get("organization_id", None)
82+
args["organization_id"] = field
83+
84+
field = data.get("start_date", None)
85+
args["start_date"] = parser.isoparse(field) if type(field) is str else field
86+
87+
field = data.get("stop_date", None)
88+
args["stop_date"] = parser.isoparse(field) if type(field) is str else field
89+
90+
field = data.get("value", None)
91+
args["value"] = field
92+
93+
field = data.get("value_remaining", None)
94+
args["value_remaining"] = field
95+
96+
field = data.get("value_used", None)
97+
args["value_used"] = field
98+
99+
return Discount(**args)
100+
101+
18102
def unmarshal_GetConsumptionResponseConsumption(
19103
data: Any,
20104
) -> GetConsumptionResponseConsumption:
@@ -99,6 +183,25 @@ def unmarshal_GetConsumptionResponse(data: Any) -> GetConsumptionResponse:
99183
return GetConsumptionResponse(**args)
100184

101185

186+
def unmarshal_ListDiscountsResponse(data: Any) -> ListDiscountsResponse:
187+
if type(data) is not dict:
188+
raise TypeError(
189+
f"Unmarshalling the type 'ListDiscountsResponse' failed as data isn't a dictionary."
190+
)
191+
192+
args: Dict[str, Any] = {}
193+
194+
field = data.get("discounts", None)
195+
args["discounts"] = (
196+
[unmarshal_Discount(v) for v in field] if field is not None else None
197+
)
198+
199+
field = data.get("total_count", None)
200+
args["total_count"] = field
201+
202+
return ListDiscountsResponse(**args)
203+
204+
102205
def unmarshal_ListInvoicesResponse(data: Any) -> ListInvoicesResponse:
103206
if type(data) is not dict:
104207
raise TypeError(

0 commit comments

Comments
 (0)