1- from django .db .models import Count , Exists , OuterRef , Sum
2- from django .utils import timezone
1+ from django .db .models import Sum
2+ from django .http import JsonResponse
33from django .utils .decorators import method_decorator
44from django .views .decorators .cache import cache_page
55from drf_spectacular .utils import (
66 OpenApiExample ,
7- OpenApiParameter ,
87 OpenApiResponse ,
98 extend_schema ,
109)
10+ from django .conf import settings
11+ from asgiref .sync import async_to_sync
1112from rest_framework import serializers
1213from rest_framework .request import Request
1314from rest_framework .response import Response
1415from rest_framework .views import APIView
15-
16+ from reclaim_python_sdk import ReclaimProofRequest
1617from accounts .models import Account
1718from donations .models import Donation
1819from pots .models import PotPayout
@@ -25,6 +26,8 @@ class StatsResponseSerializer(serializers.Serializer):
2526 total_donors_count = serializers .IntegerField ()
2627 total_recipients_count = serializers .IntegerField ()
2728
29+ class ReclaimProofRequestConfigSerializer (serializers .Serializer ):
30+ reclaimProofRequestConfig = serializers .CharField ()
2831
2932class StatsAPI (APIView ):
3033 def dispatch (self , request , * args , ** kwargs ):
@@ -87,3 +90,45 @@ def get(self, request: Request, *args, **kwargs):
8790 "total_recipients_count" : total_recipients_count ,
8891 }
8992 )
93+
94+
95+ class ReclaimProofRequestView (APIView ):
96+
97+ @extend_schema (
98+ responses = {
99+ 200 : OpenApiResponse (
100+ response = ReclaimProofRequestConfigSerializer ,
101+ description = "Returns Reclaim proof request configuration" ,
102+ examples = [
103+ OpenApiExample (
104+ "example-1" ,
105+ summary = "Simple example" ,
106+ description = "Example response for Reclaim proof request config" ,
107+ value = {
108+ "reclaimProofRequestConfig" : "{}"
109+ },
110+ response_only = True ,
111+ ),
112+ ],
113+ ),
114+ 500 : OpenApiResponse (description = "Internal server error" ),
115+ }
116+ )
117+ def post (self , request : Request , * args , ** kwargs ):
118+ APP_ID = settings .RECLAIM_APP_ID
119+ APP_SECRET = settings .RECLAIM_APP_SECRET
120+ PROVIDER_ID = settings .RECLAIM_TWITTER_PROVIDER_ID
121+
122+ platform = request .query_params .get ("platform" )
123+ handle = request .query_params .get ("handle" )
124+
125+ try :
126+ reclaim_proof_func = async_to_sync (ReclaimProofRequest .init )
127+ reclaim_proof_request = reclaim_proof_func (APP_ID , APP_SECRET , PROVIDER_ID , {"context" : {"handle" : handle }})
128+ # reclaim_proof_request.set_app_callback_url("https://your-backend.com/receive-proofs")
129+ reclaim_proof_request_config = reclaim_proof_request .to_json_string ()
130+
131+ return JsonResponse ({"reclaimProofRequestConfig" : reclaim_proof_request_config })
132+ except Exception as error :
133+ print (f"Error generating request config: { error } " )
134+ return JsonResponse ({"error" : "Failed to generate request config" }, status = 500 )
0 commit comments