Skip to content

Commit

Permalink
Add youtube webhook api
Browse files Browse the repository at this point in the history
- Add a new webhook route to receive youtube event notifications
- Add a new integration called YoutubeClient to handle youtube API methods
  • Loading branch information
rukasudev committed Aug 20, 2024
1 parent 86f4124 commit 5424651
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/integrations/youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import time


class YoutubeClient:
def __init__(self, bot):
from app import DiscordBot
self.bot: DiscordBot = bot
self.token = None
self.token_expiration_time = None
self.webhook_url = f"{self.bot.config.WEBHOOK_URL}/youtube"

def check_auth_token(func):
def wrapper(self, *args, **kwargs):
current_time = time.time()
if not self.token_expiration_time or current_time >= self.token_expiration_time:
self.authenticate()
return func(self, *args, **kwargs)

return wrapper

def authenticate(self):
pass

def get_channel_by_username(self, username: str) -> dict:
pass

@check_auth_token
def subscribe_to_new_video_event(self, user_id: str) -> None:
pass

@check_auth_token
def unsubscribe_from_new_video_event(self, subscription_id: str) -> None:
pass

@check_auth_token
def get_subscriptions(self) -> dict:
pass

@check_auth_token
def get_subscription_by_user_id(self, user_id: str) -> dict:
pass
19 changes: 19 additions & 0 deletions app/webhooks/youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import request

from app import logger
from app.constants import LogTypes as logconstants
from app.webhooks import webhooks


@webhooks.route('/youtube', methods=['GET', 'POST'])
def twitch_webhook():
# from app import bot

challenge = request.args.get('hub.challenge')

if (challenge):
return challenge

logger.info(f'Received Youtube webhook: {request.data}', log_type=logconstants.COMMAND_INFO_TYPE)

return 'Processed', 204

0 comments on commit 5424651

Please sign in to comment.