/// <summary>
        /// Creates new notification to be sent by OneSignal system.
        /// </summary>
        /// <param name="options">Options used for notification create operation.</param>
        /// <returns></returns>
        public NotificationCreateResult Create(NotificationCreateOptions options)
        {
            RestRequest restRequest = new RestRequest("notifications", Method.POST);

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

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

            IRestResponse <NotificationCreateResult> restResponse = base.RestClient.Execute <NotificationCreateResult>(restRequest);

            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);
        }
Пример #2
0
        // Otra forma de hacerlo con el SDK
        public ActionResult Index_SDK()
        {
            var client = new OneSignalClient("Y2Y1MDFlZTktNjk3My00NTAxLWE3OTctYTAyN2ExNDQ1OTE0");

            var options = new OneSignal.CSharp.SDK.Resources.Notifications.NotificationCreateOptions()
            {
                AppId            = Guid.Parse("444ebbf4-2456-48b8-9b03-95bd9df4bb0d"),
                IncludedSegments = new List <string> {
                    "All"
                }
            };

            options.Contents.Add(LanguageCodes.Spanish, "Juan Perez aplicó a tu oferta");

            NotificationCreateResult ret = client.Notifications.Create(options);

            return(View());
        }