Skip to content

Commit 80a8228

Browse files
🌿 Fern Regeneration -- Client constructor accepts access_token (#9)
* SDK regeneration * update README --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: dsinghvi <[email protected]>
1 parent a6e072d commit 80a8228

File tree

4 files changed

+28
-50
lines changed

4 files changed

+28
-50
lines changed

README.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ Simply import `Webflow` and start making calls to our API.
2828
from webflow.client import Webflow
2929

3030
client = Webflow(
31-
client_id="YOUR_CLIENT_ID",
32-
client_secret="YOUR_CLIENT_SECRET",
33-
code="YOUR_AUTHORIZATION_CODE"
31+
access_token="YOUR_ACCESS_TOKEN"
3432
)
3533
site = client.sites.get("site-id")
3634
```
@@ -43,9 +41,7 @@ calls to our API.
4341
from webflow.client import AsyncWebflow
4442

4543
client = AsyncWebflow(
46-
client_id="YOUR_CLIENT_ID",
47-
client_secret="YOUR_CLIENT_SECRET",
48-
code="YOUR_AUTHORIZATION_CODE"
44+
access_token="YOUR_ACCESS_TOKEN"
4945
)
5046

5147
async def main() -> None:
@@ -70,32 +66,18 @@ from webflow.oauth import authorize_url
7066
from webflow import OauthScope
7167

7268
url = authorize_url(
73-
client_id="[CLIENT ID]",
69+
client_id="YOUR_CLIENT_ID",
7470
scope=OauthScope.USERS_READ, # or [OauthScope.USERS_READ, OauthScope.USERS_WRITE]
7571
state="1234567890", # optional
7672
redirect_uri="https://my.server.com/oauth/callback", # optional
77-
);
73+
)
7874

7975
print(url)
8076
```
8177

82-
### Step 2: Instantiate the client
83-
Pass in your `client_id`, `client_secret`, `authorization_code` when instantiating
84-
the client. Our SDK handles generating an access token and passing that to every endpoint.
85-
86-
```python
87-
from webflow.client import Webflow
88-
89-
client = Webflow(
90-
client_id="YOUR_CLIENT_ID",
91-
client_secret="YOUR_CLIENT_SECRET",
92-
code="YOUR_AUTHORIZATION_CODE",
93-
redirect_uri="https://my.server.com/oauth/callback", # optional
94-
)
95-
```
96-
97-
If you want to generate an access token yourself, simply import the
98-
`get_access_token` function.
78+
### Step 2: Retrieve your acccess token
79+
Use the `get_access_token` function and pass in your `client_id`,
80+
`client_secret`, and `authorization_code`.
9981

10082
```python
10183
from webflow.oauth import get_access_token
@@ -107,6 +89,17 @@ access_token = get_access_token(
10789
)
10890
```
10991

92+
### Step 3: Instantiate the client
93+
Instantiate the client using your access_token.
94+
95+
```python
96+
from webflow.client import Webflow
97+
98+
client = Webflow(
99+
access_token=access_token
100+
)
101+
```
102+
110103
## Webflow Module
111104
All of the models are nested within the Webflow module. Let Intellisense
112105
guide you!

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "webflow"
3-
version = "0.1.0b1"
3+
version = "0.1.0b2"
44
description = ""
55
readme = "README.md"
66
authors = []

src/webflow/client.py

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

77
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
88
from .environment import WebflowEnvironment
9-
from .oauth import get_access_token
109
from .resources.access_groups.client import AccessGroupsClient, AsyncAccessGroupsClient
1110
from .resources.assets.client import AssetsClient, AsyncAssetsClient
1211
from .resources.collections.client import AsyncCollectionsClient, CollectionsClient
@@ -27,22 +26,15 @@ class Webflow:
2726
def __init__(
2827
self,
2928
*,
30-
client_id: str,
31-
client_secret: str,
32-
code: str,
33-
redirect_uri: typing.Optional[str] = None,
29+
base_url: typing.Optional[str] = None,
3430
environment: WebflowEnvironment = WebflowEnvironment.DEFAULT,
31+
access_token: typing.Union[str, typing.Callable[[], str]],
3532
timeout: typing.Optional[float] = 60,
3633
httpx_client: typing.Optional[httpx.Client] = None
3734
):
38-
self._token = get_access_token(
39-
client_id=client_id,
40-
client_secret=client_secret,
41-
code=code,
42-
redirect_uri=redirect_uri)
4335
self._client_wrapper = SyncClientWrapper(
44-
base_url=_get_base_url(base_url=None, environment=environment),
45-
access_token=self._token,
36+
base_url=_get_base_url(base_url=base_url, environment=environment),
37+
access_token=access_token,
4638
httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
4739
)
4840
self.token = TokenClient(client_wrapper=self._client_wrapper)
@@ -65,22 +57,15 @@ class AsyncWebflow:
6557
def __init__(
6658
self,
6759
*,
68-
client_id: str,
69-
client_secret: str,
70-
code: str,
71-
redirect_uri: typing.Optional[str] = None,
60+
base_url: typing.Optional[str] = None,
7261
environment: WebflowEnvironment = WebflowEnvironment.DEFAULT,
62+
access_token: typing.Union[str, typing.Callable[[], str]],
7363
timeout: typing.Optional[float] = 60,
7464
httpx_client: typing.Optional[httpx.AsyncClient] = None
7565
):
76-
self._token = get_access_token(
77-
client_id=client_id,
78-
client_secret=client_secret,
79-
code=code,
80-
redirect_uri=redirect_uri)
8166
self._client_wrapper = AsyncClientWrapper(
82-
base_url=_get_base_url(base_url=None, environment=environment),
83-
access_token=self._token,
67+
base_url=_get_base_url(base_url=base_url, environment=environment),
68+
access_token=access_token,
8469
httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
8570
)
8671
self.token = AsyncTokenClient(client_wrapper=self._client_wrapper)

src/webflow/core/client_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_headers(self) -> typing.Dict[str, str]:
1414
headers: typing.Dict[str, str] = {
1515
"X-Fern-Language": "Python",
1616
"X-Fern-SDK-Name": "webflow",
17-
"X-Fern-SDK-Version": "0.1.0b1",
17+
"X-Fern-SDK-Version": "0.1.0b2",
1818
}
1919
headers["Authorization"] = f"Bearer {self._get_access_token()}"
2020
return headers

0 commit comments

Comments
 (0)