/// <summary>
        /// Delete segments (not user devices) - Requires OneSignal Plan
        /// </summary>
        /// <param name="segmentId">Id of the segment you want to delete</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>Status of the delete segment call</returns>
        public async Task <GenericResponse> DeleteSegmentAsync(string segmentId, string appId = null)
        {
            var response = await DeleteAsync <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/segments/{segmentId}");

            response.Id = segmentId;
            return(response);
        }
        /// <summary>
        /// Delete segments (not user devices) - Requires OneSignal Plan
        /// </summary>
        /// <param name="segmentId">Id of the segment you want to delete</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>Status of the delete segment call</returns>
        public GenericResponse DeleteSegment(string segmentId, string appId = null)
        {
            var response = Delete <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/segments/{segmentId}");

            response.Id = segmentId;
            return(response);
        }
        /// <summary>
        /// View the details of a single notification and outcomes associated with it
        /// </summary>
        /// <param name="notificationId">The id of the notification</param>
        /// <param name="outcomeNames">List of names and the value (sum/count) for the returned outcome data. For out-of-the-box OneSignal outcomes such as click and session duration, please use the “os” prefix with two underscores. For other outcomes, please use the name specified by the user.</param>
        /// <param name="outcomeTimeRange">Time range for the returned data. The values can be 1h (for the last 1 hour data), 1d (for the last 1 day data), or 1mo (for the last 1 month data).</param>
        /// <param name="outcomePlatforms">Default is data from all platforms if the parameter is omitted.</param>
        /// <param name="outcomeAttribution">Attribution type for the outcomes. The values can be direct or influenced.</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>Notification details</returns>
        public NotificationResponse ViewNotification(string notificationId, List <string> outcomeNames = null, OutcomeTimeRange outcomeTimeRange = OutcomeTimeRange.OneHour, List <DeviceType> outcomePlatforms = null, OutcomeAttribution outcomeAttribution = OutcomeAttribution.Total, string appId = null)
        {
            var url = $"notifications/{notificationId}?app_id={appId ?? OneSignalConfiguration.GetAppId()}";

            if (outcomeNames != null && outcomeNames.Any())
            {
                url += BuildOutcomes(false, outcomeNames, outcomeTimeRange, outcomePlatforms, outcomeAttribution);
            }

            return(Get <NotificationResponse>(url));
        }
Exemple #4
0
        private static HttpClient SetupClient()
        {
            var client = new HttpClient()
            {
                BaseAddress = new Uri(OneSignalConfiguration.GetBasePath())
            };

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", OneSignalConfiguration.GetApiKey());

            return(client);
        }
 /// <summary>
 /// View the details of a single OneSignal app
 /// </summary>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Detail of the current app</returns>
 public async Task <AppResponse> ViewAppAsync(string appId = null)
 {
     return(await GetAsync <AppResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}"));
 }
 /// <summary>
 /// View the details of a single OneSignal app
 /// </summary>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Detail of the current app</returns>
 public AppResponse ViewApp(string appId = null)
 {
     return(Get <AppResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}"));
 }
 /// <summary>
 /// Updates the name or configuration settings of an existing OneSignal app
 /// </summary>
 /// <param name="options">Parameters for updating the current app</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Details of the updated app</returns>
 public async Task <AppResponse> UpdateAppAsync(CreateUpdateAppOptions options, string appId = null)
 {
     return(await PutAsync <AppResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}", options));
 }
 /// <summary>
 /// Updates the name or configuration settings of an existing OneSignal app
 /// </summary>
 /// <param name="options">Parameters for updating the current app</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Details of the updated app</returns>
 public AppResponse UpdateApp(CreateUpdateAppOptions options, string appId = null)
 {
     return(Put <AppResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}", options));
 }
 /// <summary>
 /// Update an existing device's tags in one of your OneSignal apps using the External User ID.
 /// </summary>
 /// <param name="externalUserId">Required: The OneSignal App ID the user record is found under.</param>
 /// <param name="options">Tags to update with</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Status of update</returns>
 public GenericResponse EditTagsWithExternalUserId(string externalUserId, EditTagsOptions options, string appId = null)
 {
     return(Put <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/users/{externalUserId}", options));
 }
 /// <summary>
 /// Update an existing device's tags in one of your OneSignal apps using the External User ID.
 /// </summary>
 /// <param name="externalUserId">Required: The OneSignal App ID the user record is found under.</param>
 /// <param name="options">Tags to update with</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Status of update</returns>
 public async Task <GenericResponse> EditTagsWithExternalUserIdAsync(string externalUserId, EditTagsOptions options, string appId = null)
 {
     return(await PutAsync <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/users/{externalUserId}", options));
 }
        /// <summary>
        /// Stop a scheduled or currently outgoing notification
        /// </summary>
        /// <param name="notificationId">The Id of the notification you would like to cancel</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>If the cancel was successful or not.</returns>
        public GenericResponse Cancel(string notificationId, string appId = null)
        {
            var response = Delete <GenericResponse>($"notifications/{notificationId}?app_id={appId ?? OneSignalConfiguration.GetAppId()}");

            response.Id = notificationId;
            return(response);
        }
 /// <summary>
 /// <para>Generate a compressed CSV export of all of your current user data</para>
 /// <para>This method can be used to generate a compressed CSV export of all of your current user data. It is a much faster alternative than retrieving this data using the /players API endpoint.</para>
 /// <para>The file will be compressed using GZip.</para>
 /// <para>The file may take several minutes to generate depending on the number of users in your app.</para>
 /// <para>The URL generated will be available for 3 days and includes random v4 uuid as part of the resource name to be unguessable.</para>
 /// </summary>
 /// <param name="options">Parameters for CSV export</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>URL to download CSV export file</returns>
 public CsvExportResponse CsvExport(CsvExportOptions options, string appId = null)
 {
     return(Post <CsvExportResponse>($"players/csv_export?app_id={appId ?? OneSignalConfiguration.GetAppId()}", options));
 }
 /// <summary>
 /// View the details of an existing device in one of your OneSignal apps
 /// </summary>
 /// <param name="playerId">The id of the device you want to view</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Device details</returns>
 public DeviceResponse ViewDevice(string playerId, string appId = null)
 {
     return(Get <DeviceResponse>($"players/{playerId}?app_id={appId ?? OneSignalConfiguration.GetAppId()}"));
 }
        /// <summary>
        /// View the details of all the outcomes associated with your app
        /// </summary>
        /// <param name="outcomeNames">List of names and the value (sum/count) for the returned outcome data. For out-of-the-box OneSignal outcomes such as click and session duration, please use the “os” prefix with two underscores. For other outcomes, please use the name specified by the user.</param>
        /// <param name="outcomeTimeRange">Time range for the returned data. The values can be 1h (for the last 1 hour data), 1d (for the last 1 day data), or 1mo (for the last 1 month data).</param>
        /// <param name="outcomePlatforms">Default is data from all platforms if the parameter is omitted.</param>
        /// <param name="outcomeAttribution">Attribution type for the outcomes. The values can be direct or influenced.</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>App outcomes</returns>
        public NotificationOutcomeResponse ViewOutcomes(List <string> outcomeNames, OutcomeTimeRange outcomeTimeRange = OutcomeTimeRange.OneHour, List <DeviceType> outcomePlatforms = null, OutcomeAttribution outcomeAttribution = OutcomeAttribution.Total, string appId = null)
        {
            var url = $"apps/{appId ?? OneSignalConfiguration.GetAppId()}/outcomes{BuildOutcomes(true, outcomeNames, outcomeTimeRange, outcomePlatforms, outcomeAttribution)}";

            return(Get <NotificationOutcomeResponse>(url));
        }
 /// <summary>
 /// View the details of an existing device in one of your OneSignal apps
 /// </summary>
 /// <param name="playerId">The id of the device you want to view</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Device details</returns>
 public async Task <DeviceResponse> ViewDeviceAsync(string playerId, string appId = null)
 {
     return(await GetAsync <DeviceResponse>($"players/{playerId}?app_id={appId ?? OneSignalConfiguration.GetAppId()}"));
 }
 /// <summary>
 /// <para>View the details of multiple devices in one of your OneSignal apps</para>
 /// <para>For performance reasons, this method is not available for larger apps. Larger apps should use the CSV export API endpoint, which is much more performant.</para>
 /// </summary>
 /// <param name="limit">Number of devices per page: Default and Max are 300</param>
 /// <param name="offset">Offset for pagination</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>A list of devices</returns>
 public DeviceListResponse ViewDevices(int limit = 300, int offset = 0, string appId = null)
 {
     return(Get <DeviceListResponse>($"players?app_id={appId ?? OneSignalConfiguration.GetAppId()}&limit={limit}&offset={offset}"));
 }
 /// <summary>
 /// <para>View the details of multiple devices in one of your OneSignal apps</para>
 /// <para>For performance reasons, this method is not available for larger apps. Larger apps should use the CSV export API endpoint, which is much more performant.</para>
 /// </summary>
 /// <param name="limit">Number of devices per page: Default and Max are 300</param>
 /// <param name="offset">Offset for pagination</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>A list of devices</returns>
 public async Task <DeviceListResponse> ViewDevicesAsync(int limit = 300, int offset = 0, string appId = null)
 {
     return(await GetAsync <DeviceListResponse>($"players?app_id={appId ?? OneSignalConfiguration.GetAppId()}&limit={limit}&offset={offset}"));
 }
Exemple #18
0
 /// <summary>
 /// Create segments visible and usable in the dashboard and API - Requires OneSignal Plan
 /// </summary>
 /// <param name="options">Parameters for creating a segment</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Status of the create segment call</returns>
 public async Task <GenericResponse> CreateSegmentAsync(CreateSegmentOptions options, string appId = null)
 {
     return(await PostAsync <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/segments", options));
 }
 public GetNotificationHistoryOptions(string appId = null)
 {
     AppId = appId ?? OneSignalConfiguration.GetAppId();
 }
 public CreateNotificationOptions(string appId = null)
 {
     AppId = appId ?? OneSignalConfiguration.GetAppId();
 }
 /// <summary>
 /// <para>Generate a compressed CSV export of all of your current user data</para>
 /// <para>This method can be used to generate a compressed CSV export of all of your current user data. It is a much faster alternative than retrieving this data using the /players API endpoint.</para>
 /// <para>The file will be compressed using GZip.</para>
 /// <para>The file may take several minutes to generate depending on the number of users in your app.</para>
 /// <para>The URL generated will be available for 3 days and includes random v4 uuid as part of the resource name to be unguessable.</para>
 /// </summary>
 /// <param name="options">Parameters for CSV export</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>URL to download CSV export file</returns>
 public async Task <CsvExportResponse> CsvExportAsync(CsvExportOptions options, string appId = null)
 {
     return(await PostAsync <CsvExportResponse>($"players/csv_export?app_id={appId ?? OneSignalConfiguration.GetAppId()}", options));
 }
        /// <summary>
        /// Stop a scheduled or currently outgoing notification
        /// </summary>
        /// <param name="notificationId">The Id of the notification you would like to cancel</param>
        /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
        /// <returns>If the cancel was successful or not.</returns>
        public async Task <GenericResponse> CancelAsync(string notificationId, string appId = null)
        {
            var response = await DeleteAsync <GenericResponse>($"notifications/{notificationId}?app_id={appId ?? OneSignalConfiguration.GetAppId()}");

            response.Id = notificationId;
            return(response);
        }
Exemple #23
0
 /// <summary>
 /// Create segments visible and usable in the dashboard and API - Requires OneSignal Plan
 /// </summary>
 /// <param name="options">Parameters for creating a segment</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Status of the create segment call</returns>
 public GenericResponse CreateSegment(CreateSegmentOptions options, string appId = null)
 {
     return(Post <GenericResponse>($"apps/{appId ?? OneSignalConfiguration.GetAppId()}/segments", options));
 }
 /// <summary>
 /// View the details of multiple notifications
 /// </summary>
 /// <param name="kind">The kind of notification (Dashboard, Api, or Automated)</param>
 /// <param name="limit">The number of notifications per page</param>
 /// <param name="offset">The number of notifications to skip</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Paginated list of notifications</returns>
 public ViewNotificationsResponse ViewNotifications(NotificationKind kind, int limit = 50, int offset = 0, string appId = null)
 {
     return(Get <ViewNotificationsResponse>($"notifications?app_id={appId ?? OneSignalConfiguration.GetAppId()}&limit={limit}&offset={offset}&kind={kind}"));
 }
Exemple #25
0
 public CreateUpdateDeviceOptions(string appId = null)
 {
     AppId = appId ?? OneSignalConfiguration.GetAppId();
 }