Skip to content

Commit 62906c2

Browse files
BitlyAPI 1.0.1
1 parent d014b8f commit 62906c2

File tree

6 files changed

+118
-131
lines changed

6 files changed

+118
-131
lines changed

.gitignore

Lines changed: 0 additions & 129 deletions
This file was deleted.

BitlyAPI/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import requests
2+
from .exceptions import BitlyApiNotWorking, BitlyException
3+
4+
__version__ = "1.0.1"
5+
bitli_api = "https://api.ksprojects.me/bitly?url={}"
6+
7+
8+
def shorten_url(url: str) -> str:
9+
try:
10+
response = requests.get(bitli_api.format(url)).json()
11+
except Exception:
12+
raise BitlyApiNotWorking
13+
if response['success'] is True:
14+
return response.get('link')
15+
if response.get('message'):
16+
raise BitlyException(response['message'])
17+
raise BitlyApiNotWorking

BitlyAPI/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class BitlyApiNotWorking(Exception):
2+
pass
3+
4+
5+
class BitlyException(Exception):
6+
pass

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
1-
# bitly-api-python
2-
A Python wrapper for the bit.ly API
1+
# <b>BitlyAPI</b>
2+
3+
- [<b>Installation</b>](#installation)
4+
- [<b>Documentation</b>](#documentation)
5+
- [<b>Examples</b>](#examples)
6+
- [<b>Short Url</b>](#short-url)
7+
- [<b>Version</b>](#version)
8+
- [<b>Copyright</b>](#copyright)
9+
10+
<br>
11+
12+
# <b>Installation</b>
13+
14+
```shell
15+
pip install bitly-api-python
16+
```
17+
18+
<br>
19+
20+
# <b>Documentation</b>
21+
22+
You can read our Documention on https://api.ksprojects.me/docs
23+
24+
<br>
25+
26+
# <b>Examples</b>
27+
28+
## <b>Short Url</b>
29+
30+
```python
31+
from BitlyAPI import shorten_url
32+
33+
url = "https://github.com/Krishna-Singhal"
34+
35+
shortened_url = shorten_url(url)
36+
print(shortened_url)
37+
```
38+
39+
#### <b>Parameters</b>
40+
41+
Parameter | description
42+
--------- | -----------
43+
`url` | Long url
44+
45+
<br>
46+
47+
## <b>Version</b>
48+
49+
```python
50+
from BitlyAPI import __version__
51+
52+
print(__version__)
53+
```
54+
55+
# <b>Copyright</b>
56+
57+
Copyright (C) 2022 by Krishna-Singhal, < https://github.com/Krishna-Singhal >.
58+
59+
All rights reserved.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
import setuptools
3+
4+
with open("BitlyAPI/__init__.py", encoding="utf-8") as f:
5+
version = re.findall(r"__version__ = \"(.+)\"", f.read())[0]
6+
7+
with open("README.md", "r") as fh:
8+
long_description = fh.read()
9+
10+
setuptools.setup(
11+
name="bitly-api-python",
12+
version=version,
13+
author="Krishna-Singhal",
14+
author_email="[email protected]",
15+
description="Wrapper for [Bitly API](https://api.ksprojects.me/bitly)",
16+
long_description=long_description,
17+
long_description_content_type="text/markdown",
18+
url="https://github.com/Krishna-Singhal/bitly-api-python",
19+
project_urls={
20+
"Bug Tracker": "https://github.com/Krishna-Singhal/bitly-api-python/issues",
21+
},
22+
classifiers=[
23+
"Programming Language :: Python :: 3",
24+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
25+
"Operating System :: OS Independent",
26+
],
27+
install_requires=["requests"],
28+
packages=['BitlyAPI'],
29+
python_requires=">=3.6",
30+
)

0 commit comments

Comments
 (0)