/// <summary> /// Adds new device into OneSignal App. /// </summary> /// <param name="options"> Here you can specify options used to add new device. </param> /// <returns> Result of device add operation. </returns> public async Task <DeviceAddResult> AddAsync(DeviceAddOptions options) { var result = await ApiUri.AppendPathSegment("players") .WithHeader("Authorization", $"Basic {ApiKey}") .PostJsonAsync(options) .ReceiveJson <DeviceAddResult>() .ConfigureAwait(true); return(result); }
/// <summary> /// Adds new device into OneSignal App. /// </summary> /// <param name="options"> Here you can specify options used to add new device. </param> /// <returns> Result of device add operation. </returns> public async Task <DeviceAddResult> AddAsync(DeviceAddOptions options) { var restRequest = new RestRequest("players", 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 <DeviceAddResult>(restRequest).ConfigureAwait(true); if (restResponse.ErrorException != null) { throw restResponse.ErrorException; } return(restResponse.Data); }