-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclient.py
156 lines (123 loc) · 5.59 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from urllib.parse import urljoin
from .add_ons.clients import AddOnClient
from .billable_metrics.clients import BillableMetricClient
from .coupons.clients import AppliedCouponClient, CouponClient
from .credit_notes.clients import CreditNoteClient
from .customers.clients import CustomerClient
from .events.clients import EventClient
from .fees.clients import FeeClient
from .functools_ext import callable_cached_property
from .gross_revenues.clients import GrossRevenueClient
from .invoices.clients import InvoiceClient
from .invoiced_usages.clients import InvoicedUsageClient
from .mrrs.clients import MrrClient
from .organizations.clients import OrganizationClient
from .overdue_balances.clients import OverdueBalanceClient
from .payment_requests.clients import PaymentRequestClient
from .payments.clients import PaymentClient
from .invoice_collections.clients import InvoiceCollectionClient
from .plans.clients import PlanClient
from .subscriptions.clients import SubscriptionClient
from .taxes.clients import TaxClient
from .wallets.clients import WalletClient, WalletTransactionClient
from .webhooks.clients import WebhookClient
from .webhook_endpoints.clients import WebhookEndpointClient
try:
from typing import Final
except ImportError: # Python 3.7
from typing_extensions import Final # type: ignore
class Client:
BASE_URL: Final[str] = "https://api.getlago.com/"
BASE_INGEST_URL: Final[str] = "https://ingest.getlago.com/"
API_PATH: Final[str] = "api/v1/"
def __init__(
self, api_key: str = "", api_url: str = "", use_ingest_service: bool = False, ingest_api_url: str = ""
) -> None:
self.api_key: str = api_key
self.api_url: str = api_url
self.use_ingest_service: bool = use_ingest_service
self.ingest_api_url: str = ingest_api_url
@property
def base_api_url(self) -> str:
return urljoin(self.api_url if self.api_url else Client.BASE_URL, Client.API_PATH)
@property
def base_ingest_api_url(self) -> str:
if not self.use_ingest_service:
return self.base_api_url
if self.ingest_api_url == "":
ingest_url = Client.BASE_INGEST_URL
else:
ingest_url = self.ingest_api_url
return urljoin(ingest_url, Client.API_PATH)
@callable_cached_property
def add_ons(self) -> AddOnClient:
return AddOnClient(self.base_api_url, self.api_key)
@callable_cached_property
def billable_metrics(self) -> BillableMetricClient:
return BillableMetricClient(self.base_api_url, self.api_key)
@callable_cached_property
def coupons(self) -> CouponClient:
return CouponClient(self.base_api_url, self.api_key)
@callable_cached_property
def applied_coupons(self) -> AppliedCouponClient:
return AppliedCouponClient(self.base_api_url, self.api_key)
@callable_cached_property
def credit_notes(self) -> CreditNoteClient:
return CreditNoteClient(self.base_api_url, self.api_key)
@callable_cached_property
def customers(self) -> CustomerClient:
return CustomerClient(self.base_api_url, self.api_key)
@callable_cached_property
def events(self) -> EventClient:
return EventClient(self.base_api_url, self.api_key, self.base_ingest_api_url)
@callable_cached_property
def fees(self) -> FeeClient:
return FeeClient(self.base_api_url, self.api_key)
@callable_cached_property
def gross_revenues(self) -> GrossRevenueClient:
return GrossRevenueClient(self.base_api_url, self.api_key)
@callable_cached_property
def invoices(self) -> InvoiceClient:
return InvoiceClient(self.base_api_url, self.api_key)
@callable_cached_property
def invoiced_usages(self) -> InvoicedUsageClient:
return InvoicedUsageClient(self.base_api_url, self.api_key)
@callable_cached_property
def mrrs(self) -> MrrClient:
return MrrClient(self.base_api_url, self.api_key)
@callable_cached_property
def organizations(self) -> OrganizationClient:
return OrganizationClient(self.base_api_url, self.api_key)
@callable_cached_property
def overdue_balances(self) -> OverdueBalanceClient:
return OverdueBalanceClient(self.base_api_url, self.api_key)
@callable_cached_property
def payment_requests(self) -> PaymentRequestClient:
return PaymentRequestClient(self.base_api_url, self.api_key)
@callable_cached_property
def payments(self) -> PaymentClient:
return PaymentClient(self.base_api_url, self.api_key)
@callable_cached_property
def invoice_collections(self) -> InvoiceCollectionClient:
return InvoiceCollectionClient(self.base_api_url, self.api_key)
@callable_cached_property
def plans(self) -> PlanClient:
return PlanClient(self.base_api_url, self.api_key)
@callable_cached_property
def subscriptions(self) -> SubscriptionClient:
return SubscriptionClient(self.base_api_url, self.api_key)
@callable_cached_property
def taxes(self) -> TaxClient:
return TaxClient(self.base_api_url, self.api_key)
@callable_cached_property
def wallets(self) -> WalletClient:
return WalletClient(self.base_api_url, self.api_key)
@callable_cached_property
def wallet_transactions(self) -> WalletTransactionClient:
return WalletTransactionClient(self.base_api_url, self.api_key)
@callable_cached_property
def webhooks(self) -> WebhookClient:
return WebhookClient(self.base_api_url, self.api_key)
@callable_cached_property
def webhook_endpoints(self) -> WebhookEndpointClient:
return WebhookEndpointClient(self.base_api_url, self.api_key)