Пример #1
0
        /// <summary>
        ///     Cancel a notification scheduled by the OneSignal system
        /// </summary>
        /// <param name="options"> Options used for notification cancel operation. </param>
        /// <returns></returns>
        public async Task <NotificationCancelResult> CancelAsync(NotificationCancelOptions options)
        {
            var result =
                await ApiUri.AppendPathSegment($"notifications/{options.Id}?app_id={options.AppId}")
                .WithHeader("Authorization", $"Basic {ApiKey}")
                .DeleteAsync()
                .ReceiveJson <NotificationCancelResult>()
                .ConfigureAwait(true);

            return(result);
        }
Пример #2
0
        /// <summary>
        ///     Cancel a notification scheduled by the OneSignal system
        /// </summary>
        /// <param name="options"> Options used for notification cancel operation. </param>
        /// <returns></returns>
        public async Task <NotificationCancelResult> CancelAsync(NotificationCancelOptions options)
        {
            var restRequest = new RestRequest("notifications/" + options.Id, Method.DELETE);

            restRequest.AddHeader("Authorization", string.Format("Basic {0}", ApiKey));

            restRequest.AddParameter("app_id", options.AppId);

            restRequest.RequestFormat = DataFormat.Json;

            var restResponse = await RestClient.ExecuteAsync <NotificationCancelResult>(restRequest).ConfigureAwait(true);

            if (restResponse.ErrorException != null)
            {
                throw restResponse.ErrorException;
            }
            if (restResponse.StatusCode != HttpStatusCode.OK && restResponse.Content != null)
            {
                throw new Exception(restResponse.Content);
            }

            return(restResponse.Data);
        }