private async Task <TopicManagementResponse> SendInstanceIdRequest(
            IReadOnlyList <string> registrationTokens, string topic, string path)
        {
            this.ValidateRegistrationTokenList(registrationTokens);

            string url  = $"{IidHost}/{path}";
            var    body = new InstanceIdServiceRequest
            {
                Topic = this.GetPrefixedTopic(topic),
                RegistrationTokens = registrationTokens,
            };

            var request = new HttpRequestMessage()
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(url),
                Content    = NewtonsoftJsonSerializer.Instance.CreateJsonHttpContent(body),
            };

            request.Headers.Add("access_token_auth", "true");

            var response = await this.httpClient
                           .SendAndDeserializeAsync <InstanceIdServiceResponse>(request)
                           .ConfigureAwait(false);

            return(new TopicManagementResponse(response.Result));
        }
Beispiel #2
0
        private async Task <TopicManagementResponse> SendInstanceIdRequest(string topic, List <string> registrationTokens, string path)
        {
            this.ValidateRegistrationTokenList(registrationTokens);

            string url  = $"{IidHost}/{path}";
            var    body = new InstanceIdServiceRequest
            {
                Topic = this.GetPrefixedTopic(topic),
                RegistrationTokens = registrationTokens,
            };

            var request = new HttpRequestMessage()
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(url),
                Content    = NewtonsoftJsonSerializer.Instance.CreateJsonHttpContent(body),
            };

            request.Headers.Add("access_token_auth", "true");

            try
            {
                var response = await this.httpClient.SendAsync(request, default(CancellationToken)).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                this.errorHandler.ThrowIfError(response, json);
                var instanceIdServiceResponse = JsonConvert.DeserializeObject <InstanceIdServiceResponse>(json);
                return(new TopicManagementResponse(instanceIdServiceResponse));
            }
            catch (HttpRequestException e)
            {
                throw this.CreateExceptionFromResponse(e);
            }
            catch (IOException)
            {
                throw new FirebaseMessagingException(ErrorCode.Internal, "Error while calling IID backend service");
            }
        }