Private
Public Access
1
0

adding webhook processing for strava - does not do anything useful yet

This commit is contained in:
Sander Roosendaal
2020-07-12 10:45:40 +02:00
parent 5e023a0e07
commit c4c1a02794
3 changed files with 35 additions and 0 deletions

View File

@@ -43,6 +43,8 @@ except ImportError:
from rowers.imports import *
webhookverification = "kudos_to_rowing"
headers = {'Accept': 'application/json',
'Api-Key': STRAVA_CLIENT_ID,
'Content-Type': 'application/json',
@@ -97,6 +99,25 @@ def rower_strava_token_refresh(user):
def make_authorization_url(request):
return imports_make_authorization_url(oauth_data)
def strava_establish_push():
url = "https://www.strava.com/api/v3/push_subscriptions"
post_data = {
'client_id': STRAVA_CLIENT_ID,
'client_secret': STRAVA_CLIENT_SECRET,
'callback_url': 'http://localhost:8000/rowers/strava/webhooks/',
'verify_token': webhookverification,
}
headers = {'user-agent': 'sanderroosendaal',
'Accept': 'application/json',
'Content-Type': oauth_data['content_type']}
response = requests.post(url,data=post_data)
print(response.json())
return response.status_code
def set_strava_athlete_id(user):
r = Rower.objects.get(user=user)
if (r.stravatoken == '') or (r.stravatoken is None):

View File

@@ -417,6 +417,7 @@ urlpatterns = [
re_path(r'^workout/(?P<pk>\b[0-9A-Fa-f]+\b)/delete/$',login_required(
views.WorkoutDelete.as_view()),
name='workout_delete'),
re_path(r'^strava/webhooks/',views.strava_webhook_view,name='strava_webhook_view'),
re_path(r'^garmin/summaries/',views.garmin_summaries_view,name='garmin_summaries_view'),
re_path(r'^garmin/files/',views.garmin_newfiles_ping,name='garmin_newfiles_ping'),
re_path(r'^garmin/activities/',views.garmin_details_view,name='garmin_details_view'),

View File

@@ -1008,6 +1008,19 @@ def workout_stravaimport_view(request,message="",userid=0):
return HttpResponse(res)
# for Strava webhook request validation
def strava_webhook_view(request):
if request.method == 'GET':
challenge = request.GET.get('hub.challenge')
verificationtoken = request.GET.get('hub.verify_token')
if verificationtoken != stravastuff.webhookverification:
return HttpResponse(status=403)
data = {"hub.challenge":challenge}
return JSONResponse(data)
# POST - does nothing so far
return HttpResponse(status=200)
# For push notifications from Garmin
@csrf_exempt
def garmin_summaries_view(request):