notifox 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
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.
Potentially problematic release.
This version of notifox might be problematic. Click here for more details.
- notifox/__init__.py +3 -3
- notifox/client.py +21 -20
- notifox/exceptions.py +2 -2
- {notifox-0.1.0.dist-info → notifox-0.1.1.dist-info}/METADATA +9 -5
- notifox-0.1.1.dist-info/RECORD +8 -0
- notifox-0.1.0.dist-info/RECORD +0 -8
- {notifox-0.1.0.dist-info → notifox-0.1.1.dist-info}/WHEEL +0 -0
- {notifox-0.1.0.dist-info → notifox-0.1.1.dist-info}/licenses/LICENSE +0 -0
- {notifox-0.1.0.dist-info → notifox-0.1.1.dist-info}/top_level.txt +0 -0
notifox/__init__.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from .client import NotifoxClient
|
|
2
2
|
from .exceptions import (
|
|
3
|
-
NotifoxError,
|
|
4
3
|
NotifoxAPIError,
|
|
5
4
|
NotifoxAuthenticationError,
|
|
5
|
+
NotifoxConnectionError,
|
|
6
|
+
NotifoxError,
|
|
6
7
|
NotifoxRateLimitError,
|
|
7
|
-
NotifoxConnectionError
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
@@ -15,4 +15,4 @@ __all__ = [
|
|
|
15
15
|
"NotifoxRateLimitError",
|
|
16
16
|
"NotifoxConnectionError",
|
|
17
17
|
]
|
|
18
|
-
__version__ = "0.1.
|
|
18
|
+
__version__ = "0.1.1"
|
notifox/client.py
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
# notifox/client.py
|
|
2
2
|
import os
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
4
5
|
import requests
|
|
5
6
|
from requests.adapters import HTTPAdapter
|
|
6
7
|
from urllib3.util.retry import Retry
|
|
7
8
|
|
|
8
9
|
from .exceptions import (
|
|
9
|
-
NotifoxError,
|
|
10
10
|
NotifoxAPIError,
|
|
11
11
|
NotifoxAuthenticationError,
|
|
12
|
+
NotifoxConnectionError,
|
|
13
|
+
NotifoxError,
|
|
12
14
|
NotifoxRateLimitError,
|
|
13
|
-
NotifoxConnectionError
|
|
14
15
|
)
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class NotifoxClient:
|
|
18
19
|
"""
|
|
19
20
|
Python SDK for Notifox alerting API.
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
Examples:
|
|
22
23
|
client = NotifoxClient(api_key="your_api_key")
|
|
23
24
|
client.send_alert(audience="user1", alert="Server down!")
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
client = NotifoxClient() # Reads from NOTIFOX_API_KEY env var
|
|
26
27
|
"""
|
|
27
28
|
|
|
@@ -34,7 +35,7 @@ class NotifoxClient:
|
|
|
34
35
|
):
|
|
35
36
|
"""
|
|
36
37
|
Initialize the Notifox client.
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
Args:
|
|
39
40
|
api_key: Your Notifox API key. If not provided, will attempt to read from
|
|
40
41
|
the NOTIFOX_API_KEY environment variable.
|
|
@@ -48,10 +49,10 @@ class NotifoxClient:
|
|
|
48
49
|
"API key is required. Provide it as an argument or set the "
|
|
49
50
|
"NOTIFOX_API_KEY environment variable."
|
|
50
51
|
)
|
|
51
|
-
|
|
52
|
+
|
|
52
53
|
self.base_url = base_url.rstrip("/")
|
|
53
54
|
self.timeout = timeout
|
|
54
|
-
|
|
55
|
+
|
|
55
56
|
# Create a session with retry logic
|
|
56
57
|
self.session = requests.Session()
|
|
57
58
|
retry_strategy = Retry(
|
|
@@ -65,13 +66,13 @@ class NotifoxClient:
|
|
|
65
66
|
def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
|
|
66
67
|
"""
|
|
67
68
|
Handle API response and raise appropriate exceptions for errors.
|
|
68
|
-
|
|
69
|
+
|
|
69
70
|
Args:
|
|
70
71
|
response: The HTTP response from the API
|
|
71
|
-
|
|
72
|
+
|
|
72
73
|
Returns:
|
|
73
74
|
The JSON response data
|
|
74
|
-
|
|
75
|
+
|
|
75
76
|
Raises:
|
|
76
77
|
NotifoxAuthenticationError: For 401 or 403 status codes
|
|
77
78
|
NotifoxRateLimitError: For 429 status code
|
|
@@ -83,21 +84,21 @@ class NotifoxClient:
|
|
|
83
84
|
status_code=response.status_code,
|
|
84
85
|
response_text=response.text
|
|
85
86
|
)
|
|
86
|
-
|
|
87
|
+
|
|
87
88
|
if response.status_code == 429:
|
|
88
89
|
raise NotifoxRateLimitError(
|
|
89
90
|
"Rate limit exceeded. Please try again later.",
|
|
90
91
|
status_code=response.status_code,
|
|
91
92
|
response_text=response.text
|
|
92
93
|
)
|
|
93
|
-
|
|
94
|
+
|
|
94
95
|
if response.status_code >= 400:
|
|
95
96
|
raise NotifoxAPIError(
|
|
96
97
|
f"API error: {response.status_code} - {response.text}",
|
|
97
98
|
status_code=response.status_code,
|
|
98
99
|
response_text=response.text
|
|
99
100
|
)
|
|
100
|
-
|
|
101
|
+
|
|
101
102
|
return response.json()
|
|
102
103
|
|
|
103
104
|
def send_alert(
|
|
@@ -107,14 +108,14 @@ class NotifoxClient:
|
|
|
107
108
|
) -> Dict[str, Any]:
|
|
108
109
|
"""
|
|
109
110
|
Sends an alert to the specified audience.
|
|
110
|
-
|
|
111
|
+
|
|
111
112
|
Args:
|
|
112
113
|
audience: Audience identifier (e.g., mike, devops, support)
|
|
113
114
|
alert: The alert message to send
|
|
114
|
-
|
|
115
|
+
|
|
115
116
|
Returns:
|
|
116
117
|
API response as a dictionary
|
|
117
|
-
|
|
118
|
+
|
|
118
119
|
Raises:
|
|
119
120
|
NotifoxAuthenticationError: If authentication fails
|
|
120
121
|
NotifoxRateLimitError: If rate limit is exceeded
|
|
@@ -139,8 +140,8 @@ class NotifoxClient:
|
|
|
139
140
|
except requests.exceptions.Timeout:
|
|
140
141
|
raise NotifoxConnectionError(
|
|
141
142
|
f"Request timed out after {self.timeout} seconds"
|
|
142
|
-
)
|
|
143
|
+
) from None
|
|
143
144
|
except requests.exceptions.ConnectionError as e:
|
|
144
|
-
raise NotifoxConnectionError(f"Connection error: {str(e)}")
|
|
145
|
+
raise NotifoxConnectionError(f"Connection error: {str(e)}") from e
|
|
145
146
|
except requests.exceptions.RequestException as e:
|
|
146
|
-
raise NotifoxError(f"Request failed: {str(e)}")
|
|
147
|
+
raise NotifoxError(f"Request failed: {str(e)}") from e
|
notifox/exceptions.py
CHANGED
|
@@ -6,7 +6,7 @@ class NotifoxError(Exception):
|
|
|
6
6
|
|
|
7
7
|
class NotifoxAPIError(NotifoxError):
|
|
8
8
|
"""Raised when the API returns an error response."""
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
def __init__(self, message: str, status_code: int, response_text: str = ""):
|
|
11
11
|
self.status_code = status_code
|
|
12
12
|
self.response_text = response_text
|
|
@@ -25,4 +25,4 @@ class NotifoxRateLimitError(NotifoxAPIError):
|
|
|
25
25
|
|
|
26
26
|
class NotifoxConnectionError(NotifoxError):
|
|
27
27
|
"""Raised when there's a connection error to the API."""
|
|
28
|
-
pass
|
|
28
|
+
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: notifox
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Official Python SDK for Notifox alerting API
|
|
5
5
|
Author: Mathis Van Eetvelde
|
|
6
6
|
License: MIT
|
|
@@ -66,14 +66,18 @@ from notifox import (
|
|
|
66
66
|
NotifoxConnectionError
|
|
67
67
|
)
|
|
68
68
|
|
|
69
|
+
client = NotifoxClient(api_key="your_api_key")
|
|
70
|
+
|
|
69
71
|
try:
|
|
70
|
-
client.send_alert(audience=
|
|
72
|
+
client.send_alert(audience="admin", alert="System is running low on memory")
|
|
71
73
|
except NotifoxAuthenticationError:
|
|
72
|
-
|
|
74
|
+
print("Authentication failed. Check your API key.")
|
|
73
75
|
except NotifoxRateLimitError:
|
|
74
|
-
|
|
76
|
+
print("Rate limit exceeded. Please wait before sending more alerts.")
|
|
75
77
|
except NotifoxAPIError as e:
|
|
76
|
-
print(f"{e.status_code}: {e.response_text}")
|
|
78
|
+
print(f"API error ({e.status_code}): {e.response_text}")
|
|
79
|
+
except NotifoxConnectionError as e:
|
|
80
|
+
print(f"Connection failed: {e}")
|
|
77
81
|
```
|
|
78
82
|
|
|
79
83
|
Available exceptions:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
notifox/__init__.py,sha256=dvO0GnAfHz9qqs53aecJf-saVHet2XAotFVFPiWCbkY,382
|
|
2
|
+
notifox/client.py,sha256=NVZMjWhj3ut_Eom_bzUE0RBxnEve4Il0P_EtjruOszQ,4784
|
|
3
|
+
notifox/exceptions.py,sha256=lHDVJrOo5Y-xa0_KyLI2pwPW3yJAlEUpWKDdlpqlnLM,752
|
|
4
|
+
notifox-0.1.1.dist-info/licenses/LICENSE,sha256=eZtQec-wzyeDB7eeTSsosa9_a6RR0ebVBPPxn7xSakQ,1094
|
|
5
|
+
notifox-0.1.1.dist-info/METADATA,sha256=LNvHwHBL6eNM8dMtmVdU8ewwJkxWH8q1Eun1aI-5Jgc,2080
|
|
6
|
+
notifox-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
notifox-0.1.1.dist-info/top_level.txt,sha256=VvmvnNCybE97RLvBOCrYNYCKGdhhVkPBVdYW_kM_spc,8
|
|
8
|
+
notifox-0.1.1.dist-info/RECORD,,
|
notifox-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
notifox/__init__.py,sha256=JTWJrlY-jCkYf6PSUMAF1Eng8blox8yX_xeYqxgJlJo,380
|
|
2
|
-
notifox/client.py,sha256=mwNYavJqPs__UNxWRZwVy6mRXF_tlCT-PUOTWjIlZ3A,4881
|
|
3
|
-
notifox/exceptions.py,sha256=Mbks4ACBd8tt2XEDgiFofsWXpY9xaqzw43H3ZLgyJXk,755
|
|
4
|
-
notifox-0.1.0.dist-info/licenses/LICENSE,sha256=eZtQec-wzyeDB7eeTSsosa9_a6RR0ebVBPPxn7xSakQ,1094
|
|
5
|
-
notifox-0.1.0.dist-info/METADATA,sha256=muT8mutjJijvkCHHcdJmoEphP7y3Vk2FduxNPIRDZRs,1811
|
|
6
|
-
notifox-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
notifox-0.1.0.dist-info/top_level.txt,sha256=VvmvnNCybE97RLvBOCrYNYCKGdhhVkPBVdYW_kM_spc,8
|
|
8
|
-
notifox-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|