public async Task <TestCallResult> GetTestCallScoreAsync(Guid participantId)
        {
            var requestUri = $"{_kinlySelfTestScoreEndpointUrl}/{participantId}";

            var request = new HttpRequestMessage
            {
                RequestUri = new Uri(requestUri),
                Method     = HttpMethod.Get
            };

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
                                                                          _customJwtTokenProvider.GenerateSelfTestApiToken(participantId.ToString(), 2));

            var responseMessage = await _httpClient.SendAsync(request);

            if (responseMessage.StatusCode == HttpStatusCode.NotFound)
            {
                throw new NotFoundException($"Could not find Self Test for ParticipantId: {participantId}");
            }

            responseMessage.EnsureSuccessStatusCode();

            var content = await responseMessage.Content.ReadAsStringAsync();

            var testCall = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <KinlyVideoTestCall>(content);

            return(new TestCallResult(testCall.Passed, testCall.Score));
        }
Ejemplo n.º 2
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var participantId = request.Properties.ContainsKey(ParticipantIdName)
                ? request.Properties[ParticipantIdName]
                : throw new Exception($"Could not find the field {ParticipantIdName} in the request properties dictionary");

            var token = _tokenProvider.GenerateSelfTestApiToken(participantId.ToString(), 2);

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

            return(base.SendAsync(request, cancellationToken));
        }