Skip to content

Commit 81893ed

Browse files
committed
Release 1.0.3
1 parent c3e99fb commit 81893ed

File tree

92 files changed

+198
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+198
-105
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ci
33
on: [push]
44
jobs:
55
compile:
6-
runs-on: ubuntu-latest
6+
runs-on: ubuntu-20.04
77
steps:
88
- name: Checkout repo
99
uses: actions/checkout@v3
@@ -13,13 +13,13 @@ jobs:
1313
python-version: 3.7
1414
- name: Bootstrap poetry
1515
run: |
16-
curl -sSL https://install.python-poetry.org | python - -y
16+
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
1717
- name: Install dependencies
1818
run: poetry install
1919
- name: Compile
2020
run: poetry run mypy .
2121
test:
22-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-20.04
2323
steps:
2424
- name: Checkout repo
2525
uses: actions/checkout@v3
@@ -29,7 +29,7 @@ jobs:
2929
python-version: 3.7
3030
- name: Bootstrap poetry
3131
run: |
32-
curl -sSL https://install.python-poetry.org | python - -y
32+
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
3333
- name: Install dependencies
3434
run: poetry install
3535
- name: Test
@@ -38,7 +38,7 @@ jobs:
3838
publish:
3939
needs: [compile, test]
4040
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
41-
runs-on: ubuntu-latest
41+
runs-on: ubuntu-20.04
4242
steps:
4343
- name: Checkout repo
4444
uses: actions/checkout@v3
@@ -48,7 +48,7 @@ jobs:
4848
python-version: 3.7
4949
- name: Bootstrap poetry
5050
run: |
51-
curl -sSL https://install.python-poetry.org | python - -y
51+
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
5252
- name: Install dependencies
5353
run: poetry install
5454
- name: Publish to pypi

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "flagright"
3-
version = "1.0.0"
3+
version = "1.0.3"
44
description = ""
55
readme = "README.md"
66
authors = []
@@ -10,7 +10,7 @@ packages = [
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.7"
13-
httpx = "0.23.3"
13+
httpx = ">=0.21.2"
1414
pydantic = "^1.9.2"
1515

1616
[tool.poetry.dev-dependencies]

src/flagright/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
BusinessOptional,
1515
BusinessOptionalSavedPaymentDetailsItem,
1616
BusinessResponse,
17+
BusinessUserSegment,
1718
BusinessUsersCreateResponse,
1819
BusinessUsersResponse,
1920
BusinessWithRulesResult,
@@ -33,7 +34,6 @@
3334
CheckPaymentMethod,
3435
CompanyFinancialDetails,
3536
CompanyGeneralDetails,
36-
CompanyGeneralDetailsUserSegment,
3737
CompanyRegistrationDetails,
3838
ConsumerName,
3939
ConsumerUserSegment,
@@ -132,6 +132,7 @@
132132
transaction_events,
133133
transactions,
134134
)
135+
from .environment import FlagrightEnvironment
135136

136137
__all__ = [
137138
"AchDetails",
@@ -148,6 +149,7 @@
148149
"BusinessOptional",
149150
"BusinessOptionalSavedPaymentDetailsItem",
150151
"BusinessResponse",
152+
"BusinessUserSegment",
151153
"BusinessUsersCreateResponse",
152154
"BusinessUsersResponse",
153155
"BusinessWithRulesResult",
@@ -167,7 +169,6 @@
167169
"CheckPaymentMethod",
168170
"CompanyFinancialDetails",
169171
"CompanyGeneralDetails",
170-
"CompanyGeneralDetailsUserSegment",
171172
"CompanyRegistrationDetails",
172173
"ConsumerName",
173174
"ConsumerUserSegment",
@@ -181,6 +182,7 @@
181182
"ExecutedRulesResult",
182183
"FailedRulesResult",
183184
"FalsePositiveDetails",
185+
"FlagrightEnvironment",
184186
"GeneralBankAccountPaymentMethod",
185187
"GenericBankAccountDetails",
186188
"HitRulesDetails",

src/flagright/client.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import httpx
66

77
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8+
from .environment import FlagrightEnvironment
89
from .resources.business_user_events.client import AsyncBusinessUserEventsClient, BusinessUserEventsClient
910
from .resources.business_users.client import AsyncBusinessUsersClient, BusinessUsersClient
1011
from .resources.consumer_user_events.client import AsyncConsumerUserEventsClient, ConsumerUserEventsClient
@@ -14,34 +15,53 @@
1415

1516

1617
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),
2930
)
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)
3037

3138

3239
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),
4752
)
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")

src/flagright/core/client_wrapper.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,30 @@
66

77

88
class BaseClientWrapper:
9-
def __init__(self, *, api_key: str):
9+
def __init__(self, *, api_key: str, base_url: str):
1010
self.api_key = api_key
11+
self._base_url = base_url
1112

1213
def get_headers(self) -> typing.Dict[str, str]:
1314
headers: typing.Dict[str, str] = {
1415
"X-Fern-Language": "Python",
1516
"X-Fern-SDK-Name": "flagright",
16-
"X-Fern-SDK-Version": "1.0.0",
17+
"X-Fern-SDK-Version": "1.0.3",
1718
}
1819
headers["x-api-key"] = self.api_key
1920
return headers
2021

22+
def get_base_url(self) -> str:
23+
return self._base_url
24+
2125

2226
class SyncClientWrapper(BaseClientWrapper):
23-
def __init__(self, *, api_key: str, httpx_client: httpx.Client):
24-
super().__init__(api_key=api_key)
27+
def __init__(self, *, api_key: str, base_url: str, httpx_client: httpx.Client):
28+
super().__init__(api_key=api_key, base_url=base_url)
2529
self.httpx_client = httpx_client
2630

2731

2832
class AsyncClientWrapper(BaseClientWrapper):
29-
def __init__(self, *, api_key: str, httpx_client: httpx.AsyncClient):
30-
super().__init__(api_key=api_key)
33+
def __init__(self, *, api_key: str, base_url: str, httpx_client: httpx.AsyncClient):
34+
super().__init__(api_key=api_key, base_url=base_url)
3135
self.httpx_client = httpx_client

src/flagright/environment.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import enum
4+
5+
6+
class FlagrightEnvironment(enum.Enum):
7+
DEFAULT = "https://sandbox.api.flagright.com"

src/flagright/resources/business_user_events/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323

2424
class BusinessUserEventsClient:
25-
def __init__(self, *, environment: str, client_wrapper: SyncClientWrapper):
26-
self._environment = environment
25+
def __init__(self, *, client_wrapper: SyncClientWrapper):
2726
self._client_wrapper = client_wrapper
2827

2928
def create(
@@ -84,7 +83,7 @@ def create(
8483
_request["updatedBusinessUserAttributes"] = updated_business_user_attributes
8584
_response = self._client_wrapper.httpx_client.request(
8685
"POST",
87-
urllib.parse.urljoin(f"{self._environment}/", "events/business/user"),
86+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "events/business/user"),
8887
params=remove_none_from_dict({"allowUserTypeConversion": allow_user_type_conversion}),
8988
json=jsonable_encoder(_request),
9089
headers=self._client_wrapper.get_headers(),
@@ -106,8 +105,7 @@ def create(
106105

107106

108107
class AsyncBusinessUserEventsClient:
109-
def __init__(self, *, environment: str, client_wrapper: AsyncClientWrapper):
110-
self._environment = environment
108+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
111109
self._client_wrapper = client_wrapper
112110

113111
async def create(
@@ -168,7 +166,7 @@ async def create(
168166
_request["updatedBusinessUserAttributes"] = updated_business_user_attributes
169167
_response = await self._client_wrapper.httpx_client.request(
170168
"POST",
171-
urllib.parse.urljoin(f"{self._environment}/", "events/business/user"),
169+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "events/business/user"),
172170
params=remove_none_from_dict({"allowUserTypeConversion": allow_user_type_conversion}),
173171
json=jsonable_encoder(_request),
174172
headers=self._client_wrapper.get_headers(),

src/flagright/resources/business_users/client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222

2323
class BusinessUsersClient:
24-
def __init__(self, *, environment: str, client_wrapper: SyncClientWrapper):
25-
self._environment = environment
24+
def __init__(self, *, client_wrapper: SyncClientWrapper):
2625
self._client_wrapper = client_wrapper
2726

2827
def create(self, *, request: Business) -> BusinessUsersCreateResponse:
@@ -47,7 +46,7 @@ def create(self, *, request: Business) -> BusinessUsersCreateResponse:
4746
"""
4847
_response = self._client_wrapper.httpx_client.request(
4948
"POST",
50-
urllib.parse.urljoin(f"{self._environment}/", "business/users"),
49+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "business/users"),
5150
json=jsonable_encoder(request),
5251
headers=self._client_wrapper.get_headers(),
5352
timeout=60,
@@ -79,7 +78,7 @@ def get(self, user_id: str) -> BusinessResponse:
7978
"""
8079
_response = self._client_wrapper.httpx_client.request(
8180
"GET",
82-
urllib.parse.urljoin(f"{self._environment}/", f"business/users/{user_id}"),
81+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"business/users/{user_id}"),
8382
headers=self._client_wrapper.get_headers(),
8483
timeout=60,
8584
)
@@ -97,8 +96,7 @@ def get(self, user_id: str) -> BusinessResponse:
9796

9897

9998
class AsyncBusinessUsersClient:
100-
def __init__(self, *, environment: str, client_wrapper: AsyncClientWrapper):
101-
self._environment = environment
99+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
102100
self._client_wrapper = client_wrapper
103101

104102
async def create(self, *, request: Business) -> BusinessUsersCreateResponse:
@@ -123,7 +121,7 @@ async def create(self, *, request: Business) -> BusinessUsersCreateResponse:
123121
"""
124122
_response = await self._client_wrapper.httpx_client.request(
125123
"POST",
126-
urllib.parse.urljoin(f"{self._environment}/", "business/users"),
124+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "business/users"),
127125
json=jsonable_encoder(request),
128126
headers=self._client_wrapper.get_headers(),
129127
timeout=60,
@@ -155,7 +153,7 @@ async def get(self, user_id: str) -> BusinessResponse:
155153
"""
156154
_response = await self._client_wrapper.httpx_client.request(
157155
"GET",
158-
urllib.parse.urljoin(f"{self._environment}/", f"business/users/{user_id}"),
156+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"business/users/{user_id}"),
159157
headers=self._client_wrapper.get_headers(),
160158
timeout=60,
161159
)

src/flagright/resources/consumer_user_events/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323

2424
class ConsumerUserEventsClient:
25-
def __init__(self, *, environment: str, client_wrapper: SyncClientWrapper):
26-
self._environment = environment
25+
def __init__(self, *, client_wrapper: SyncClientWrapper):
2726
self._client_wrapper = client_wrapper
2827

2928
def create(
@@ -84,7 +83,7 @@ def create(
8483
_request["updatedConsumerUserAttributes"] = updated_consumer_user_attributes
8584
_response = self._client_wrapper.httpx_client.request(
8685
"POST",
87-
urllib.parse.urljoin(f"{self._environment}/", "events/consumer/user"),
86+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "events/consumer/user"),
8887
params=remove_none_from_dict({"allowUserTypeConversion": allow_user_type_conversion}),
8988
json=jsonable_encoder(_request),
9089
headers=self._client_wrapper.get_headers(),
@@ -106,8 +105,7 @@ def create(
106105

107106

108107
class AsyncConsumerUserEventsClient:
109-
def __init__(self, *, environment: str, client_wrapper: AsyncClientWrapper):
110-
self._environment = environment
108+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
111109
self._client_wrapper = client_wrapper
112110

113111
async def create(
@@ -168,7 +166,7 @@ async def create(
168166
_request["updatedConsumerUserAttributes"] = updated_consumer_user_attributes
169167
_response = await self._client_wrapper.httpx_client.request(
170168
"POST",
171-
urllib.parse.urljoin(f"{self._environment}/", "events/consumer/user"),
169+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "events/consumer/user"),
172170
params=remove_none_from_dict({"allowUserTypeConversion": allow_user_type_conversion}),
173171
json=jsonable_encoder(_request),
174172
headers=self._client_wrapper.get_headers(),

0 commit comments

Comments
 (0)