Ejemplo n.º 1
0
        /// <summary>
        ///     Creates new notification to be sent by OneSignal system.
        /// </summary>
        /// <param name="options"> Options used for notification create operation. </param>
        /// <returns></returns>
        public async Task <NotificationCreateResult> CreateAsync(NotificationCreateOptions options)
        {
            var restRequest = new RestRequest("notifications", Method.POST);

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

            restRequest.RequestFormat  = DataFormat.Json;
            restRequest.JsonSerializer = new NewtonsoftJsonSerializer();
            restRequest.AddBody(options);

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

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

            return(restResponse.Data);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        ///     Creates new notification to be sent by OneSignal system.
        /// </summary>
        /// <param name="options"> Options used for notification create operation. </param>
        /// <returns></returns>
        public async Task <NotificationCreateResult> CreateAsync(NotificationCreateOptions options)
        {
            var result =
                await ApiUri.AppendPathSegment("notifications")
                .WithHeader("Authorization", $"Basic {ApiKey}")
                .PostJsonAsync(options)
                .ReceiveJson <NotificationCreateResult>()
                .ConfigureAwait(true);

            return(result);
        }