Skip to content

Commit 32ea717

Browse files
committed
v0.2.2 - fix missing timeout and README
1 parent 28212ea commit 32ea717

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ A small simple wrapper around the [Mystb.in](https://mystb.in/) API.
44

55
### Features
66

7-
[x] - `POST`ing to the API, which will return the provided url. \
8-
[x] - `GET`ting from the API, provided you know the URL or paste ID. \
9-
[x] - Ability to pass in a sync or async session / parameter so it is flexible.
10-
11-
[x] - Write a real underlying Client for this, it will be required for... \
12-
[ ] - Authorization. Awaiting the API making this public as it is still WIP. \
7+
- [x] - `POST`ing to the API, which will return the provided url.
8+
- [x] - `GET`ting from the API, provided you know the URL or paste ID.
9+
- [x] - Ability to pass in a sync or async session / parameter so it is flexible.
10+
- [x] - Write a real underlying Client for this, it will be required for...
11+
- [ ] - ... Authorization. Awaiting the API making this public as it is still WIP.
1312

1413
### Installation
1514
This project will be on [PyPI](https://pypi.org/project/mystbin.py/) as a stable release, you can always find that there.
@@ -35,8 +34,19 @@ import mystbin
3534

3635
mystbin_client = mystbin.MystbinClient() ## api_key kwarg for authentication also
3736

38-
await mystbin_client.post("Hello from Mystb.in!", suffix="python")
37+
paste = await mystbin_client.post("Hello from Mystb.in!", syntax="python")
38+
str(paste)
39+
>>> 'https://mystb.in/<your generated ID>.python'
40+
41+
paste.url
3942
>>> 'https://mystb.in/<your generated ID>.python'
43+
44+
get_paste = await mystbin_client.get("https://mystb.in/<your generated ID>")
45+
str(paste)
46+
>>> "Hello from Mystb.in!"
47+
48+
paste.created_at
49+
>>> datetime.datetime(2020, 10, 6, 10, 53, 57, 556741)
4050
```
4151

4252
```py
@@ -47,7 +57,7 @@ import requests
4757
sync_session = requests.Session()
4858
mystbin_client = mystbin.MystbinClient(session=sync_session) ## optional api_key kwarg also
4959

50-
mystbin_client.post("Hello from sync Mystb.in!", suffix="text")
60+
mystbin_client.post("Hello from sync Mystb.in!", syntax="text")
5161
>>> 'https://mystb.in/<your generated ID>.text'
5262
```
5363

mystbin/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def _generate_sync_session(self, session: requests.Session) -> requests.Session:
7373
async def _generate_async_session(self, session: Optional[aiohttp.ClientSession] = None) -> aiohttp.ClientSession:
7474
""" We will update (or create) a :class:`aiohttp.ClientSession` instance with the auth we require. """
7575
if not session:
76-
session = aiohttp.ClientSession(raise_for_status=False,
77-
timeout=aiohttp.ClientTimeout(CLIENT_TIMEOUT))
76+
session = aiohttp.ClientSession(raise_for_status=False)
7877
if self.api_key:
7978
session._default_headers.update(
8079
{"Authorization": self.api_key})
80+
session._timeout = aiohttp.ClientTimeout(CLIENT_TIMEOUT)
8181
return session
8282

8383
def post(self, content: str, syntax: str = None) -> Union[Paste, Awaitable]:
@@ -100,7 +100,7 @@ def _perform_sync_post(self, content: str, syntax: str = None) -> Paste:
100100
""" Sync post request. """
101101
payload = {'meta': [{'index': 0, 'syntax': syntax}]}
102102
response: requests.Response = self.session.post(API_BASE_URL, files={
103-
'data': content, 'meta': (None, json.dumps(payload), 'application/json')})
103+
'data': content, 'meta': (None, json.dumps(payload), 'application/json')}, timeout=CLIENT_TIMEOUT)
104104
if response.status_code not in [200, 201]:
105105
raise APIError(response.status_code, response.text)
106106

@@ -163,4 +163,4 @@ async def _perform_async_get(self, paste_id: str, syntax: str = None) -> PasteDa
163163
async def close(self):
164164
""" Async only - close the session. """
165165
if self.session and isinstance(self.session, aiohttp.ClientSession):
166-
await self.session.close()
166+
await self.session.close()

0 commit comments

Comments
 (0)