Skip to content

Commit b1ba1c0

Browse files
feat(api): manual updates
1 parent 545ed69 commit b1ba1c0

Some content is hidden

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

42 files changed

+4113
-50
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 1
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/beeper%2Fbeeper-desktop-api-8c712fe19f280b0b89ecc8a3ce61e9f6b165cee97ce33f66c66a7a5db339c755.yml
3-
openapi_spec_hash: 1ea71129cc1a1ccc3dc8a99566082311
1+
configured_endpoints: 14
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/beeper%2Fbeeper-desktop-api-9f5190d7df873112f3512b5796cd95341f0fa0d2585488d3e829be80ee6045ce.yml
3+
openapi_spec_hash: ba834200758376aaea47b2a276f64c1b
44
config_hash: f83b2b6eb86f2dd68101065998479cb2

README.md

Lines changed: 123 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ client = BeeperDesktop(
3333
access_token=os.environ.get("BEEPER_ACCESS_TOKEN"), # This is the default and can be omitted
3434
)
3535

36-
user_info = client.token.info()
37-
print(user_info.sub)
36+
page = client.chats.search(
37+
include_muted=True,
38+
limit=3,
39+
type="single",
40+
)
41+
print(page.items)
3842
```
3943

4044
While you can provide a `access_token` keyword argument,
@@ -57,8 +61,12 @@ client = AsyncBeeperDesktop(
5761

5862

5963
async def main() -> None:
60-
user_info = await client.token.info()
61-
print(user_info.sub)
64+
page = await client.chats.search(
65+
include_muted=True,
66+
limit=3,
67+
type="single",
68+
)
69+
print(page.items)
6270

6371

6472
asyncio.run(main())
@@ -90,8 +98,12 @@ async def main() -> None:
9098
access_token="My Access Token",
9199
http_client=DefaultAioHttpClient(),
92100
) as client:
93-
user_info = await client.token.info()
94-
print(user_info.sub)
101+
page = await client.chats.search(
102+
include_muted=True,
103+
limit=3,
104+
type="single",
105+
)
106+
print(page.items)
95107

96108

97109
asyncio.run(main())
@@ -106,6 +118,101 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
106118

107119
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
108120

121+
## Pagination
122+
123+
List methods in the Beeper Desktop API are paginated.
124+
125+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
126+
127+
```python
128+
from beeper_desktop_api import BeeperDesktop
129+
130+
client = BeeperDesktop()
131+
132+
all_messages = []
133+
# Automatically fetches more pages as needed.
134+
for message in client.messages.search(
135+
account_ids=["local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI"],
136+
limit=10,
137+
query="deployment",
138+
):
139+
# Do something with message here
140+
all_messages.append(message)
141+
print(all_messages)
142+
```
143+
144+
Or, asynchronously:
145+
146+
```python
147+
import asyncio
148+
from beeper_desktop_api import AsyncBeeperDesktop
149+
150+
client = AsyncBeeperDesktop()
151+
152+
153+
async def main() -> None:
154+
all_messages = []
155+
# Iterate through items across all pages, issuing requests as needed.
156+
async for message in client.messages.search(
157+
account_ids=["local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI"],
158+
limit=10,
159+
query="deployment",
160+
):
161+
all_messages.append(message)
162+
print(all_messages)
163+
164+
165+
asyncio.run(main())
166+
```
167+
168+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
169+
170+
```python
171+
first_page = await client.messages.search(
172+
account_ids=["local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI"],
173+
limit=10,
174+
query="deployment",
175+
)
176+
if first_page.has_next_page():
177+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
178+
next_page = await first_page.get_next_page()
179+
print(f"number of items we just fetched: {len(next_page.items)}")
180+
181+
# Remove `await` for non-async usage.
182+
```
183+
184+
Or just work directly with the returned data:
185+
186+
```python
187+
first_page = await client.messages.search(
188+
account_ids=["local-telegram_ba_QFrb5lrLPhO3OT5MFBeTWv0x4BI"],
189+
limit=10,
190+
query="deployment",
191+
)
192+
193+
print(f"next page cursor: {first_page.oldest_cursor}") # => "next page cursor: ..."
194+
for message in first_page.items:
195+
print(message.id)
196+
197+
# Remove `await` for non-async usage.
198+
```
199+
200+
## Nested params
201+
202+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
203+
204+
```python
205+
from beeper_desktop_api import BeeperDesktop
206+
207+
client = BeeperDesktop()
208+
209+
base_response = client.chats.reminders.create(
210+
chat_id="!NCdzlIaMjZUmvmvyHU:beeper.com",
211+
reminder={"remind_at_ms": 0},
212+
)
213+
print(base_response.reminder)
214+
```
215+
109216
## Handling errors
110217

111218
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `beeper_desktop_api.APIConnectionError` is raised.
@@ -122,7 +229,10 @@ from beeper_desktop_api import BeeperDesktop
122229
client = BeeperDesktop()
123230

124231
try:
125-
client.token.info()
232+
client.messages.send(
233+
chat_id="1229391",
234+
text="Hello! Just checking in on the project status.",
235+
)
126236
except beeper_desktop_api.APIConnectionError as e:
127237
print("The server could not be reached")
128238
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -165,7 +275,7 @@ client = BeeperDesktop(
165275
)
166276

167277
# Or, configure per-request:
168-
client.with_options(max_retries=5).token.info()
278+
client.with_options(max_retries=5).accounts.list()
169279
```
170280

171281
### Timeouts
@@ -188,7 +298,7 @@ client = BeeperDesktop(
188298
)
189299

190300
# Override per-request:
191-
client.with_options(timeout=5.0).token.info()
301+
client.with_options(timeout=5.0).accounts.list()
192302
```
193303

194304
On timeout, an `APITimeoutError` is thrown.
@@ -229,11 +339,11 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
229339
from beeper_desktop_api import BeeperDesktop
230340

231341
client = BeeperDesktop()
232-
response = client.token.with_raw_response.info()
342+
response = client.accounts.with_raw_response.list()
233343
print(response.headers.get('X-My-Header'))
234344

235-
token = response.parse() # get the object that `token.info()` would have returned
236-
print(token.sub)
345+
account = response.parse() # get the object that `accounts.list()` would have returned
346+
print(account)
237347
```
238348

239349
These methods return an [`APIResponse`](https://github.com/beeper/desktop-api-python/tree/main/src/beeper_desktop_api/_response.py) object.
@@ -247,7 +357,7 @@ The above interface eagerly reads the full response body when you make the reque
247357
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
248358

249359
```python
250-
with client.token.with_streaming_response.info() as response:
360+
with client.accounts.with_streaming_response.list() as response:
251361
print(response.headers.get("X-My-Header"))
252362

253363
for line in response.iter_lines():

api.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,79 @@
44
from beeper_desktop_api.types import Attachment, BaseResponse, Error, Message, Reaction, User
55
```
66

7+
# BeeperDesktop
8+
9+
Types:
10+
11+
```python
12+
from beeper_desktop_api.types import DownloadAssetResponse, OpenResponse, SearchResponse
13+
```
14+
15+
Methods:
16+
17+
- <code title="post /v1/app/download-asset">client.<a href="./src/beeper_desktop_api/_client.py">download_asset</a>(\*\*<a href="src/beeper_desktop_api/types/client_download_asset_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/download_asset_response.py">DownloadAssetResponse</a></code>
18+
- <code title="post /v1/app/open">client.<a href="./src/beeper_desktop_api/_client.py">open</a>(\*\*<a href="src/beeper_desktop_api/types/client_open_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/open_response.py">OpenResponse</a></code>
19+
- <code title="get /v1/search">client.<a href="./src/beeper_desktop_api/_client.py">search</a>(\*\*<a href="src/beeper_desktop_api/types/client_search_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/search_response.py">SearchResponse</a></code>
20+
721
# Accounts
822

923
Types:
1024

1125
```python
12-
from beeper_desktop_api.types import Account
26+
from beeper_desktop_api.types import Account, AccountListResponse
1327
```
1428

29+
Methods:
30+
31+
- <code title="get /v1/accounts">client.accounts.<a href="./src/beeper_desktop_api/resources/accounts.py">list</a>() -> <a href="./src/beeper_desktop_api/types/account_list_response.py">AccountListResponse</a></code>
32+
33+
# Contacts
34+
35+
Types:
36+
37+
```python
38+
from beeper_desktop_api.types import ContactSearchResponse
39+
```
40+
41+
Methods:
42+
43+
- <code title="get /v1/contacts/search">client.contacts.<a href="./src/beeper_desktop_api/resources/contacts.py">search</a>(\*\*<a href="src/beeper_desktop_api/types/contact_search_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/contact_search_response.py">ContactSearchResponse</a></code>
44+
1545
# Chats
1646

1747
Types:
1848

1949
```python
20-
from beeper_desktop_api.types import Chat
50+
from beeper_desktop_api.types import Chat, ChatCreateResponse
51+
```
52+
53+
Methods:
54+
55+
- <code title="post /v1/chats">client.chats.<a href="./src/beeper_desktop_api/resources/chats/chats.py">create</a>(\*\*<a href="src/beeper_desktop_api/types/chat_create_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/chat_create_response.py">ChatCreateResponse</a></code>
56+
- <code title="get /v1/chats/{chatID}">client.chats.<a href="./src/beeper_desktop_api/resources/chats/chats.py">retrieve</a>(chat_id, \*\*<a href="src/beeper_desktop_api/types/chat_retrieve_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/chat.py">Chat</a></code>
57+
- <code title="post /v1/chats/{chatID}/archive">client.chats.<a href="./src/beeper_desktop_api/resources/chats/chats.py">archive</a>(chat_id, \*\*<a href="src/beeper_desktop_api/types/chat_archive_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/shared/base_response.py">BaseResponse</a></code>
58+
- <code title="get /v1/chats/search">client.chats.<a href="./src/beeper_desktop_api/resources/chats/chats.py">search</a>(\*\*<a href="src/beeper_desktop_api/types/chat_search_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/chat.py">SyncCursor[Chat]</a></code>
59+
60+
## Reminders
61+
62+
Methods:
63+
64+
- <code title="post /v1/chats/{chatID}/reminders">client.chats.reminders.<a href="./src/beeper_desktop_api/resources/chats/reminders.py">create</a>(chat_id, \*\*<a href="src/beeper_desktop_api/types/chats/reminder_create_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/shared/base_response.py">BaseResponse</a></code>
65+
- <code title="delete /v1/chats/{chatID}/reminders">client.chats.reminders.<a href="./src/beeper_desktop_api/resources/chats/reminders.py">delete</a>(chat_id) -> <a href="./src/beeper_desktop_api/types/shared/base_response.py">BaseResponse</a></code>
66+
67+
# Messages
68+
69+
Types:
70+
71+
```python
72+
from beeper_desktop_api.types import MessageSendResponse
2173
```
2274

75+
Methods:
76+
77+
- <code title="get /v1/messages/search">client.messages.<a href="./src/beeper_desktop_api/resources/messages.py">search</a>(\*\*<a href="src/beeper_desktop_api/types/message_search_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/shared/message.py">SyncCursor[Message]</a></code>
78+
- <code title="post /v1/messages">client.messages.<a href="./src/beeper_desktop_api/resources/messages.py">send</a>(\*\*<a href="src/beeper_desktop_api/types/message_send_params.py">params</a>) -> <a href="./src/beeper_desktop_api/types/message_send_response.py">MessageSendResponse</a></code>
79+
2380
# Token
2481

2582
Types:

0 commit comments

Comments
 (0)