Skip to content

Commit c9498ec

Browse files
authored
Merge pull request #1 from kilobyteno/feature/publish-event
2 parents 35ca662 + 18f21b9 commit c9498ec

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

.env

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TEST_TITLE=sample_title
2+
TEST_API_TOKEN=token
3+
TEST_CHANNEL_ID=uuid
4+
TEST_DESCRIPTION=this is an event
5+
6+
ENV=staging.

oppe/config.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
from dotenv import load_dotenv
4+
5+
6+
class Config:
7+
"""
8+
Configuration class for Oppe app settings
9+
10+
Attributes:
11+
BASE_URL (str):
12+
The base URL for the Oppe app
13+
EVENT_URL (str):
14+
The URL for accessing Oppe app events
15+
"""
16+
# Reading the env variables
17+
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
18+
if os.path.exists(dotenv_path):
19+
load_dotenv(dotenv_path)
20+
21+
BASE_URL = f"https://{os.getenv('ENV')}oppe.app"
22+
EVENT_URL = f"{BASE_URL}/api/event/"

oppe/oppe.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import requests
2+
from oppe.config import Config
3+
import json
4+
5+
6+
class Oppe:
7+
"""
8+
Oppe class for triggering events in the Oppe app.
9+
10+
Attributes:
11+
token (str):
12+
The authentication token.
13+
project (str):
14+
The project identifier.
15+
"""
16+
def __init__(self, token, project):
17+
"""
18+
Initializes an instance of the Oppe class.
19+
20+
:param token: The authentication token.
21+
:type token: str
22+
:param project: The project identifier.
23+
:type project: str
24+
"""
25+
self.token = token
26+
self.project = project
27+
28+
def trigger_event(self, channel, title, description):
29+
"""
30+
Triggers an event in the Oppe app.
31+
32+
:param channel: The channel identifier.
33+
:type channel: str
34+
:param title: The title of the event.
35+
:type title: str
36+
:param description: The description of the event.
37+
:type description: str
38+
39+
:return: True if the event was triggered successfully, False otherwise.
40+
:rtype: bool
41+
"""
42+
data = {
43+
"channel_id": channel,
44+
"title": title,
45+
"description": description,
46+
}
47+
headers = {
48+
"Accept": "application/json",
49+
"Content-Type": "application/json",
50+
"Authorization": f"Bearer {self.token}"
51+
}
52+
response = requests.post(Config.EVENT_URL, data=json.dumps(data), headers=headers)
53+
return True
54+

requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
setuptools~=68.1.2
2+
certifi==2023.7.22
3+
pytest==7.4.1
4+
python-dotenv==1.0.0
5+
requests==2.31.0
6+
tomli==2.0.1
7+
urllib3==2.0.4

tests/test_pyoppe.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
from dotenv import load_dotenv
4+
5+
from oppe.oppe import Oppe
6+
7+
# Reading the env variables
8+
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
9+
if os.path.exists(dotenv_path):
10+
load_dotenv(dotenv_path)
11+
12+
13+
def init_oppe():
14+
return Oppe(token=os.getenv('TEST_API_TOKEN'), project=os.getenv('TEST_PROJECT'))
15+
16+
17+
def test_publish_event():
18+
oppe = init_oppe()
19+
response = oppe.trigger_event(channel=os.getenv('TEST_CHANNEL_ID'), title=os.getenv('TEST_TITLE'), description=os.getenv('TEST_DESCRIPTION'))
20+
assert response == True

0 commit comments

Comments
 (0)