|
5 | 5 | import httpx |
6 | 6 |
|
7 | 7 | from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 | +from .environment import FlagrightEnvironment |
8 | 9 | from .resources.business_user_events.client import AsyncBusinessUserEventsClient, BusinessUserEventsClient |
9 | 10 | from .resources.business_users.client import AsyncBusinessUsersClient, BusinessUsersClient |
10 | 11 | from .resources.consumer_user_events.client import AsyncConsumerUserEventsClient, ConsumerUserEventsClient |
|
14 | 15 |
|
15 | 16 |
|
16 | 17 | class Flagright: |
17 | | - def __init__(self, *, environment: str, api_key: str, timeout: typing.Optional[float] = 60): |
18 | | - self._environment = environment |
19 | | - self._client_wrapper = SyncClientWrapper(api_key=api_key, httpx_client=httpx.Client(timeout=timeout)) |
20 | | - self.transactions = TransactionsClient(environment=environment, client_wrapper=self._client_wrapper) |
21 | | - self.transaction_events = TransactionEventsClient(environment=environment, client_wrapper=self._client_wrapper) |
22 | | - self.consumer_users = ConsumerUsersClient(environment=environment, client_wrapper=self._client_wrapper) |
23 | | - self.business_users = BusinessUsersClient(environment=environment, client_wrapper=self._client_wrapper) |
24 | | - self.consumer_user_events = ConsumerUserEventsClient( |
25 | | - environment=environment, client_wrapper=self._client_wrapper |
26 | | - ) |
27 | | - self.business_user_events = BusinessUserEventsClient( |
28 | | - environment=environment, client_wrapper=self._client_wrapper |
| 18 | + def __init__( |
| 19 | + self, |
| 20 | + *, |
| 21 | + base_url: typing.Optional[str] = None, |
| 22 | + environment: FlagrightEnvironment = FlagrightEnvironment.DEFAULT, |
| 23 | + api_key: str, |
| 24 | + timeout: typing.Optional[float] = 60 |
| 25 | + ): |
| 26 | + self._client_wrapper = SyncClientWrapper( |
| 27 | + base_url=_get_base_url(base_url=base_url, environment=environment), |
| 28 | + api_key=api_key, |
| 29 | + httpx_client=httpx.Client(timeout=timeout), |
29 | 30 | ) |
| 31 | + self.transactions = TransactionsClient(client_wrapper=self._client_wrapper) |
| 32 | + self.transaction_events = TransactionEventsClient(client_wrapper=self._client_wrapper) |
| 33 | + self.consumer_users = ConsumerUsersClient(client_wrapper=self._client_wrapper) |
| 34 | + self.business_users = BusinessUsersClient(client_wrapper=self._client_wrapper) |
| 35 | + self.consumer_user_events = ConsumerUserEventsClient(client_wrapper=self._client_wrapper) |
| 36 | + self.business_user_events = BusinessUserEventsClient(client_wrapper=self._client_wrapper) |
30 | 37 |
|
31 | 38 |
|
32 | 39 | class AsyncFlagright: |
33 | | - def __init__(self, *, environment: str, api_key: str, timeout: typing.Optional[float] = 60): |
34 | | - self._environment = environment |
35 | | - self._client_wrapper = AsyncClientWrapper(api_key=api_key, httpx_client=httpx.AsyncClient(timeout=timeout)) |
36 | | - self.transactions = AsyncTransactionsClient(environment=environment, client_wrapper=self._client_wrapper) |
37 | | - self.transaction_events = AsyncTransactionEventsClient( |
38 | | - environment=environment, client_wrapper=self._client_wrapper |
39 | | - ) |
40 | | - self.consumer_users = AsyncConsumerUsersClient(environment=environment, client_wrapper=self._client_wrapper) |
41 | | - self.business_users = AsyncBusinessUsersClient(environment=environment, client_wrapper=self._client_wrapper) |
42 | | - self.consumer_user_events = AsyncConsumerUserEventsClient( |
43 | | - environment=environment, client_wrapper=self._client_wrapper |
44 | | - ) |
45 | | - self.business_user_events = AsyncBusinessUserEventsClient( |
46 | | - environment=environment, client_wrapper=self._client_wrapper |
| 40 | + def __init__( |
| 41 | + self, |
| 42 | + *, |
| 43 | + base_url: typing.Optional[str] = None, |
| 44 | + environment: FlagrightEnvironment = FlagrightEnvironment.DEFAULT, |
| 45 | + api_key: str, |
| 46 | + timeout: typing.Optional[float] = 60 |
| 47 | + ): |
| 48 | + self._client_wrapper = AsyncClientWrapper( |
| 49 | + base_url=_get_base_url(base_url=base_url, environment=environment), |
| 50 | + api_key=api_key, |
| 51 | + httpx_client=httpx.AsyncClient(timeout=timeout), |
47 | 52 | ) |
| 53 | + self.transactions = AsyncTransactionsClient(client_wrapper=self._client_wrapper) |
| 54 | + self.transaction_events = AsyncTransactionEventsClient(client_wrapper=self._client_wrapper) |
| 55 | + self.consumer_users = AsyncConsumerUsersClient(client_wrapper=self._client_wrapper) |
| 56 | + self.business_users = AsyncBusinessUsersClient(client_wrapper=self._client_wrapper) |
| 57 | + self.consumer_user_events = AsyncConsumerUserEventsClient(client_wrapper=self._client_wrapper) |
| 58 | + self.business_user_events = AsyncBusinessUserEventsClient(client_wrapper=self._client_wrapper) |
| 59 | + |
| 60 | + |
| 61 | +def _get_base_url(*, base_url: typing.Optional[str] = None, environment: FlagrightEnvironment) -> str: |
| 62 | + if base_url is not None: |
| 63 | + return base_url |
| 64 | + elif environment is not None: |
| 65 | + return environment.value |
| 66 | + else: |
| 67 | + raise Exception("Please pass in either base_url or environment to construct the client") |
0 commit comments