/// <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.AddJsonBody(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); }
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.ErrorException != null) { throw restResponse.ErrorException; } return(restResponse.Data); }