python-ntfy 0.2.4__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-ntfy
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: An ntfy library aiming for feature completeness
5
5
  Home-page: https://github.com/MatthewCane/python-ntfy
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-ntfy"
3
- version = "0.2.4"
3
+ version = "0.2.5"
4
4
  description = "An ntfy library aiming for feature completeness"
5
5
  authors = ["Matthew Cane <matthew.cane0@gmail.com>"]
6
6
  readme = "README.md"
@@ -1,17 +1,22 @@
1
1
  import os
2
- from types import MethodType
3
- from ._send_functions import (
4
- send,
5
- send_file,
6
- MessagePriority,
7
- ViewAction,
8
- BroadcastAction,
9
- HttpAction,
10
- )
11
- from ._get_functions import get_cached_messages
12
2
 
13
3
 
14
4
  class NtfyClient:
5
+ # The functions need to be imported here to:
6
+ # 1. Keep the functions in a separate file
7
+ # 2. Keep the docstrings working in the IDE
8
+ # 3. Allow the functions to be called with self
9
+ # MyPy does not like this, but it works
10
+ from ._send_functions import ( # type: ignore
11
+ send,
12
+ send_file,
13
+ MessagePriority,
14
+ ViewAction,
15
+ BroadcastAction,
16
+ HttpAction,
17
+ )
18
+ from ._get_functions import get_cached_messages # type: ignore
19
+
15
20
  def __init__(
16
21
  self,
17
22
  topic: str,
@@ -22,16 +27,6 @@ class NtfyClient:
22
27
  :param server: The server to connect to. Must include the protocol (http/https)
23
28
  :return None:
24
29
  """
25
- # Bind the imported functions to the class
26
- self.send = MethodType(send, self)
27
- self.send_file = MethodType(send_file, self)
28
- self.MessagePriority = MethodType(MessagePriority, self)
29
- self.get_cached_messages = MethodType(get_cached_messages, self)
30
-
31
- # These are Enums that don't need to be bound
32
- self.ViewAction = ViewAction
33
- self.BroadcastAction = BroadcastAction
34
- self.HttpAction = HttpAction
35
30
 
36
31
  self._server = os.environ.get("NTFY_SERVER") or server
37
32
  self._topic = topic
@@ -57,7 +57,7 @@ class BroadcastAction(Action):
57
57
  self,
58
58
  label: str,
59
59
  intent: str = "io.heckel.ntfy.USER_ACTION",
60
- extras: Optional[dict] = None,
60
+ extras: Optional[dict[str, str]] = None,
61
61
  clear: bool = False,
62
62
  ):
63
63
  self.action = ActionType.BROADCAST
@@ -71,14 +71,18 @@ class BroadcastAction(Action):
71
71
  "label": self.label,
72
72
  "extras": self.extras,
73
73
  "clear": self.clear,
74
+ "intent": self.intent,
74
75
  }
75
76
 
76
77
  def to_header(self) -> str:
77
- extras = ""
78
- if self.extras is not None:
79
- for key, value in self.extras.items():
80
- extras += f"{key}={value},"
81
- return f"action={self.action.value}, label={self.label}, url={self.url}, clear={self.clear}"
78
+ if self.extras:
79
+ extras_str = ", ".join([f"extras.{k}={v}" for k, v in self.extras.items()])
80
+ return (
81
+ f"action={self.action.value}, label={self.label}, url={self.url}, clear={self.clear}, intent={self.intent}"
82
+ + extras_str
83
+ if self.extras
84
+ else ""
85
+ )
82
86
 
83
87
 
84
88
  class HttpAction(Action):
@@ -153,7 +157,7 @@ def send(
153
157
  "Title": title,
154
158
  "Priority": priority.value,
155
159
  "Tags": ",".join(tags),
156
- "Markdown": "true" if format_as_markdown else "false",
160
+ "Markdown": str(format_as_markdown).lower(),
157
161
  }
158
162
  if len(actions) > 0:
159
163
  headers["Actions"] = " ; ".join([action.to_header() for action in actions])
File without changes
File without changes