Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Feb 19, 2023
1 parent 8e957e7 commit b2decf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/alertify/webhook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from .client import Client
14 changes: 7 additions & 7 deletions src/alertify/webhook/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,39 @@


class Client():
"""Client Class"""
"""Webhook Client Class"""

def __init__(self):
self._logging = logging.getLogger(__name__)

def post(self, url, api_key, payload={}):

headers = {
'Authorization': f'Bearer {api_key}',
'X-API-KEY': api_key,
}

try:
response = requests.post(url, json=payload, headers=headers)
except Exception as e:
raise ApiError("Failed to call webhook: {}".format(str(e)))

if response.status_code // 100 == 2:
if response.status_code // 100 != 2:
raise ApiError("Webhook respond with error status code {}".format(response.status_code))

return True
return response.content.decode("utf-8")

def put(self, url, api_key, payload={}):

headers = {
'Authorization': f'Bearer {api_key}',
'X-API-KEY': api_key,
}

try:
response = requests.put(url, json=payload, headers=headers)
except Exception as e:
raise ApiError("Failed to call webhook: {}".format(str(e)))

if response.status_code // 100 == 2:
if response.status_code // 100 != 2:
raise ApiError("Webhook respond with error status code {}".format(response.status_code))

return True
return response.content.decode("utf-8")

0 comments on commit b2decf1

Please sign in to comment.