Skip to content

Commit ef44ed0

Browse files
committed
feat: support priority
1 parent 9c84bb0 commit ef44ed0

File tree

8 files changed

+110
-25
lines changed

8 files changed

+110
-25
lines changed

poetry.lock

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

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[tool.poetry]
22
name = "znotify"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
description = "sdk for notify"
55
authors = ["Zxilly <[email protected]>"]
6-
license = "GPL-3.0"
6+
license = "Apache-2.0"
77
readme = "README.md"
88
repository = "https://github.com/ZNotify/py-sdk"
99
classifiers = [
@@ -23,6 +23,9 @@ requests = "^2.27.1"
2323
[tool.poetry.urls]
2424
"Bug Tracker" = "https://github.com/ZNotify/py-sdk/issues"
2525

26+
[tool.poetry.group.dev.dependencies]
27+
poethepoet = "^0.16.5"
28+
2629
[build-system]
2730
requires = ["poetry-core>=1.0.0"]
2831
build-backend = "poetry.core.masonry.api"

tests/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import unittest
2+
import warnings
3+
24
from znotify import Client
35

46

@@ -53,3 +55,4 @@ def test_client_send_3(self):
5355

5456
if __name__ == "__main__":
5557
unittest.main()
58+

tests/test_send.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
23
from znotify.send import send
34

45

znotify/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .client import *
22
from .send import *
3+
4+
from .version import __title__, __description__, __url__, __version__, __author__, __license__

znotify/client.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
import requests
2-
from requests.exceptions import ConnectionError
32

4-
from znotify.static import ENDPOINT
3+
from znotify.static import ENDPOINT, Priority
4+
from znotify.version import __version__
55

66

77
class Client:
8-
def __init__(self, user_id, endpoint):
8+
def __init__(self, user_id: str, endpoint: str):
99
self.endpoint = endpoint if endpoint else ENDPOINT
1010
self.user_id = user_id
11+
self.session = requests.Session()
12+
self.session.headers.update({
13+
"User-Agent": f"znotify-py-sdk/{__version__}",
14+
})
1115

1216
@staticmethod
13-
def create(user_id, endpoint=None):
17+
def create(user_id: str, endpoint: str = None) -> "Client":
1418
client = Client(user_id, endpoint)
1519
client.check()
1620
return client
1721

1822
def check(self):
19-
resp = requests.get(f"{self.endpoint}/check", params={"user_id": self.user_id})
23+
resp = self.session.get(f"{self.endpoint}/check", params={"user_id": self.user_id})
2024
if not resp.json()["body"]:
2125
raise Exception("User ID not valid")
2226

23-
def send(self, content, title=None, long=None):
27+
def send(self, content: str, title: str = None, long: str = None, priority: Priority = None):
2428
if content is None or content == "":
2529
raise Exception("Content is required")
2630

2731
if title is None:
2832
title = "Notification"
2933
if long is None:
3034
long = ""
35+
if priority is None:
36+
priority = Priority.NORMAL
3137

3238
data = {
3339
"title": title,
3440
"content": content,
35-
"long": long
41+
"long": long,
42+
"priority": priority.value,
3643
}
37-
try:
38-
resp = requests.post(f"{self.endpoint}/{self.user_id}/send", data=data)
39-
except ConnectionError as e:
40-
raise Exception("Connection error") from e
44+
45+
resp = self.session.post(f"{self.endpoint}/{self.user_id}/send", data=data)
4146
return resp.json()["body"]

znotify/static.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import sys
2+
from enum import Enum
23

34
ENDPOINT = "https://push.learningman.top" if 'unittest' not in sys.modules else "http://localhost:14444"
5+
6+
7+
class Priority(Enum):
8+
HIGH = "high"
9+
NORMAL = "normal"
10+
LOW = "low"

znotify/version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__title__ = "znotify"
2+
__description__ = "Python SDK for ZNotify."
3+
__url__ = "https://github.com/ZNotify/py-sdk"
4+
__version__ = "0.3.0"
5+
__author__ = "Zxilly"
6+
__license__ = "Apache-2.0"

0 commit comments

Comments
 (0)