Skip to content

Commit

Permalink
🌿 Fern Regeneration -- Client constructor accepts access_token (#9)
Browse files Browse the repository at this point in the history
* SDK regeneration

* update README

---------

Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: dsinghvi <[email protected]>
  • Loading branch information
fern-api[bot] and dsinghvi authored Dec 30, 2023
1 parent a6e072d commit 80a8228
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
43 changes: 18 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ Simply import `Webflow` and start making calls to our API.
from webflow.client import Webflow

client = Webflow(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
code="YOUR_AUTHORIZATION_CODE"
access_token="YOUR_ACCESS_TOKEN"
)
site = client.sites.get("site-id")
```
Expand All @@ -43,9 +41,7 @@ calls to our API.
from webflow.client import AsyncWebflow

client = AsyncWebflow(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
code="YOUR_AUTHORIZATION_CODE"
access_token="YOUR_ACCESS_TOKEN"
)

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

url = authorize_url(
client_id="[CLIENT ID]",
client_id="YOUR_CLIENT_ID",
scope=OauthScope.USERS_READ, # or [OauthScope.USERS_READ, OauthScope.USERS_WRITE]
state="1234567890", # optional
redirect_uri="https://my.server.com/oauth/callback", # optional
);
)

print(url)
```

### Step 2: Instantiate the client
Pass in your `client_id`, `client_secret`, `authorization_code` when instantiating
the client. Our SDK handles generating an access token and passing that to every endpoint.

```python
from webflow.client import Webflow

client = Webflow(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
code="YOUR_AUTHORIZATION_CODE",
redirect_uri="https://my.server.com/oauth/callback", # optional
)
```

If you want to generate an access token yourself, simply import the
`get_access_token` function.
### Step 2: Retrieve your acccess token
Use the `get_access_token` function and pass in your `client_id`,
`client_secret`, and `authorization_code`.

```python
from webflow.oauth import get_access_token
Expand All @@ -107,6 +89,17 @@ access_token = get_access_token(
)
```

### Step 3: Instantiate the client
Instantiate the client using your access_token.

```python
from webflow.client import Webflow

client = Webflow(
access_token=access_token
)
```

## Webflow Module
All of the models are nested within the Webflow module. Let Intellisense
guide you!
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "webflow"
version = "0.1.0b1"
version = "0.1.0b2"
description = ""
readme = "README.md"
authors = []
Expand Down
31 changes: 8 additions & 23 deletions src/webflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import WebflowEnvironment
from .oauth import get_access_token
from .resources.access_groups.client import AccessGroupsClient, AsyncAccessGroupsClient
from .resources.assets.client import AssetsClient, AsyncAssetsClient
from .resources.collections.client import AsyncCollectionsClient, CollectionsClient
Expand All @@ -27,22 +26,15 @@ class Webflow:
def __init__(
self,
*,
client_id: str,
client_secret: str,
code: str,
redirect_uri: typing.Optional[str] = None,
base_url: typing.Optional[str] = None,
environment: WebflowEnvironment = WebflowEnvironment.DEFAULT,
access_token: typing.Union[str, typing.Callable[[], str]],
timeout: typing.Optional[float] = 60,
httpx_client: typing.Optional[httpx.Client] = None
):
self._token = get_access_token(
client_id=client_id,
client_secret=client_secret,
code=code,
redirect_uri=redirect_uri)
self._client_wrapper = SyncClientWrapper(
base_url=_get_base_url(base_url=None, environment=environment),
access_token=self._token,
base_url=_get_base_url(base_url=base_url, environment=environment),
access_token=access_token,
httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
)
self.token = TokenClient(client_wrapper=self._client_wrapper)
Expand All @@ -65,22 +57,15 @@ class AsyncWebflow:
def __init__(
self,
*,
client_id: str,
client_secret: str,
code: str,
redirect_uri: typing.Optional[str] = None,
base_url: typing.Optional[str] = None,
environment: WebflowEnvironment = WebflowEnvironment.DEFAULT,
access_token: typing.Union[str, typing.Callable[[], str]],
timeout: typing.Optional[float] = 60,
httpx_client: typing.Optional[httpx.AsyncClient] = None
):
self._token = get_access_token(
client_id=client_id,
client_secret=client_secret,
code=code,
redirect_uri=redirect_uri)
self._client_wrapper = AsyncClientWrapper(
base_url=_get_base_url(base_url=None, environment=environment),
access_token=self._token,
base_url=_get_base_url(base_url=base_url, environment=environment),
access_token=access_token,
httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
)
self.token = AsyncTokenClient(client_wrapper=self._client_wrapper)
Expand Down
2 changes: 1 addition & 1 deletion src/webflow/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "webflow",
"X-Fern-SDK-Version": "0.1.0b1",
"X-Fern-SDK-Version": "0.1.0b2",
}
headers["Authorization"] = f"Bearer {self._get_access_token()}"
return headers
Expand Down

0 comments on commit 80a8228

Please sign in to comment.