Skip to content

Commit 8c2614e

Browse files
committed
begin real 0.1.0
1 parent f4b6b10 commit 8c2614e

File tree

5 files changed

+191
-39
lines changed

5 files changed

+191
-39
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.vscode/
2+
__ignore__/
23
*.pyc
34
__pycache__/
45
/dist/
56
/*.egg-info/
7+
.mypy_cache/
68
setup.py

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ 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 ID. \
9-
[ ] - 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+
[ ] - Ability to pass in a sync or async session / parameter so it is flexible.
10+
11+
[ ] - 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. \
13+
14+
### Dependencies
15+
16+
`aiohttp` - required
17+
`requests` - optional

mystbin/__init__.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,6 @@
2121
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222
DEALINGS IN THE SOFTWARE.
2323
"""
24-
import re
2524

26-
import aiohttp
27-
28-
BASE = "https://mystb.in/api/pastes"
29-
# Let's set aiohttp timeout for this
30-
TIMEOUT = aiohttp.ClientTimeout(total=15.0)
31-
32-
# grab the paste id: https://regex101.com/r/qkluDh/1
33-
MB_URL_RE = re.compile(r"(?:http[s]?://mystb\.in/)?([a-zA-Z]+)(?:.*)")
34-
35-
async def post(content: str, *, session: aiohttp.ClientSession = None, suffix: str = None) -> str:
36-
""" Post `content` to MystB.in with optional suffix text. """
37-
suffix = f".{suffix}" if suffix else ""
38-
multi_part = aiohttp.MultipartWriter()
39-
paste_content = multi_part.append(content)
40-
paste_content.set_content_disposition("form-data", name="data")
41-
paste_content = multi_part.append_json({"meta": [{"index": 0, "syntax": suffix}]})
42-
paste_content.set_content_disposition("form-data", name="meta")
43-
session = session or aiohttp.ClientSession(raise_for_status=True)
44-
async with session.post(BASE, data=multi_part, timeout=TIMEOUT) as mb_res:
45-
url = await mb_res.json()
46-
short_id = url['pastes'][0]['id']
47-
return f"https://mystb.in/{short_id}{suffix}"
48-
49-
async def get(paste: str, *, session: aiohttp.ClientSession = None) -> dict:
50-
try:
51-
paste_id = MB_URL_RE.match(paste)[1]
52-
except IndexError:
53-
return "This is not a valid Mystb.in paste ID or URL."
54-
session = session or aiohttp.ClientSession(raise_for_status=True)
55-
async with session.get(f"{BASE}/{paste_id}", timeout=TIMEOUT) as mb_res:
56-
data_json = await mb_res.json()
57-
return data_json
25+
from .client import MystClient
26+
from .errors import *

poetry.lock

Lines changed: 169 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mystbin.py"
3-
version = "0.0.1"
3+
version = "0.1.0"
44
description = "A small simple wrapper around the mystb.in API."
55
authors = ["AbstractUmbra <Umbra@AbstractUmbra.xyz>"]
66
license = "MIT"
@@ -24,10 +24,16 @@ packages = [
2424
[tool.poetry.dependencies]
2525
python = "^3.6"
2626
aiohttp = "^3.6.2"
27+
requests = {version = "^2.24.0", optional = true}
2728

2829
[tool.poetry.dev-dependencies]
2930
setuptools = "^50.3.0"
3031
wheel = "^0.35.1"
32+
autopep8 = "^1.5.4"
33+
mypy = "^0.782"
34+
35+
[tool.poetry.extras]
36+
requests = ["requests"]
3137

3238
[build-system]
3339
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)