Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

namespace PubnubApi
{
/// <summary>
/// Request object for adding channels to a channel group
/// </summary>
public class AddChannelsToChannelGroupRequest
{
/// <summary>
/// The channels to add to the channel group
/// </summary>
public string[] Channels { get; set; }

/// <summary>
/// The channel group to add channels to
/// </summary>
public string ChannelGroup { get; set; }

/// <summary>
/// Validates the request parameters
/// </summary>
internal void Validate()
{
if (Channels == null || Channels.Length == 0)
{
throw new ArgumentException("Channels cannot be null or empty");
}

if (string.IsNullOrEmpty(ChannelGroup) || ChannelGroup.Trim().Length == 0)
{
throw new ArgumentException("ChannelGroup cannot be null or empty");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;

namespace PubnubApi
{
/// <summary>
/// Response object for adding channels to a channel group
/// </summary>
public class AddChannelsToChannelGroupResponse
{
/// <summary>
/// Indicates whether the operation was successful
/// </summary>
public bool Success { get; }

/// <summary>
/// The response message
/// </summary>
public string Message { get; }

/// <summary>
/// The exception if the operation failed
/// </summary>
public Exception Exception { get; }

private AddChannelsToChannelGroupResponse(bool success, string message, Exception exception = null)
{
Success = success;
Message = message;
Exception = exception;
}

/// <summary>
/// Creates a successful response
/// </summary>
internal static AddChannelsToChannelGroupResponse CreateSuccess(PNChannelGroupsAddChannelResult result)
{
return new AddChannelsToChannelGroupResponse(true, "Channel(s) added successfully", null);
}

/// <summary>
/// Creates a failure response
/// </summary>
internal static AddChannelsToChannelGroupResponse CreateFailure(Exception exception)
{
return new AddChannelsToChannelGroupResponse(false, exception?.Message ?? "Operation failed", exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace PubnubApi
{
/// <summary>
/// Request object for deleting a channel group
/// </summary>
public class DeleteChannelGroupRequest
{
/// <summary>
/// The channel group to delete
/// </summary>
public string ChannelGroup { get; set; }

/// <summary>
/// Validates the request parameters
/// </summary>
internal void Validate()
{
if (string.IsNullOrEmpty(ChannelGroup) || ChannelGroup.Trim().Length == 0)
{
throw new ArgumentException("ChannelGroup cannot be null or empty");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;

namespace PubnubApi
{
/// <summary>
/// Response object for deleting a channel group
/// </summary>
public class DeleteChannelGroupResponse
{
/// <summary>
/// Indicates whether the operation was successful
/// </summary>
public bool Success { get; }

/// <summary>
/// The response message
/// </summary>
public string Message { get; }

/// <summary>
/// The exception if the operation failed
/// </summary>
public Exception Exception { get; }

private DeleteChannelGroupResponse(bool success, string message, Exception exception = null)
{
Success = success;
Message = message;
Exception = exception;
}

/// <summary>
/// Creates a successful response
/// </summary>
internal static DeleteChannelGroupResponse CreateSuccess(PNChannelGroupsDeleteGroupResult result)
{
return new DeleteChannelGroupResponse(true, result?.Message ?? "Channel group deleted successfully", null);
}

/// <summary>
/// Creates a failure response
/// </summary>
internal static DeleteChannelGroupResponse CreateFailure(Exception exception)
{
return new DeleteChannelGroupResponse(false, exception?.Message ?? "Operation failed", exception);
}
}
}
171 changes: 171 additions & 0 deletions src/Api/PubnubApi/Model/RequestResponse/DeleteMessageRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;

namespace PubnubApi
{
/// <summary>
/// Request model for delete message operations using the request/response API pattern.
/// This request deletes messages from a specific channel within an optional timetoken range.
/// </summary>
public class DeleteMessageRequest
{
/// <summary>
/// The channel from which to delete messages. Required field.
/// Only a single channel is supported for delete operations.
/// </summary>
public string Channel { get; set; }

/// <summary>
/// The starting timetoken for the deletion range (inclusive).
/// If not specified, deletes from the beginning of the channel history.
/// </summary>
public long? Start { get; set; }

/// <summary>
/// The ending timetoken for the deletion range (exclusive).
/// If not specified, deletes to the end of the channel history.
/// </summary>
public long? End { get; set; }

/// <summary>
/// Additional query parameters for the request.
/// Allows for future extensibility and custom parameters.
/// </summary>
public Dictionary<string, object> QueryParameters { get; set; }

/// <summary>
/// Validates the request parameters.
/// </summary>
/// <exception cref="ArgumentException">Thrown when validation fails</exception>
public void Validate()
{
// Validate required channel
if (string.IsNullOrWhiteSpace(Channel))
{
throw new ArgumentException("Channel is required for delete message operation");
}

// Validate timetoken values if provided
if (Start.HasValue && Start.Value < 0)
{
throw new ArgumentException("Start timetoken cannot be negative");
}

if (End.HasValue && End.Value < 0)
{
throw new ArgumentException("End timetoken cannot be negative");
}

// Validate logical timetoken range
if (Start.HasValue && End.HasValue && Start.Value > End.Value)
{
throw new ArgumentException("Start timetoken must be less than or equal to end timetoken");
}
}

/// <summary>
/// Creates a new DeleteMessageRequest for deleting all messages in a channel.
/// </summary>
/// <param name="channel">The channel to delete messages from</param>
/// <returns>A configured DeleteMessageRequest</returns>
public static DeleteMessageRequest ForChannel(string channel)
{
if (string.IsNullOrWhiteSpace(channel))
{
throw new ArgumentException("Channel cannot be null or empty", nameof(channel));
}

return new DeleteMessageRequest
{
Channel = channel
};
}

/// <summary>
/// Creates a new DeleteMessageRequest for deleting messages within a specific timetoken range.
/// </summary>
/// <param name="channel">The channel to delete messages from</param>
/// <param name="start">The starting timetoken (inclusive)</param>
/// <param name="end">The ending timetoken (exclusive)</param>
/// <returns>A configured DeleteMessageRequest</returns>
public static DeleteMessageRequest ForChannelWithRange(string channel, long start, long end)
{
if (string.IsNullOrWhiteSpace(channel))
{
throw new ArgumentException("Channel cannot be null or empty", nameof(channel));
}

if (start < 0)
{
throw new ArgumentException("Start timetoken cannot be negative", nameof(start));
}

if (end < 0)
{
throw new ArgumentException("End timetoken cannot be negative", nameof(end));
}

if (start > end)
{
throw new ArgumentException("Start timetoken must be less than or equal to end timetoken");
}

return new DeleteMessageRequest
{
Channel = channel,
Start = start,
End = end
};
}

/// <summary>
/// Creates a new DeleteMessageRequest for deleting messages from a specific start time.
/// </summary>
/// <param name="channel">The channel to delete messages from</param>
/// <param name="start">The starting timetoken (inclusive)</param>
/// <returns>A configured DeleteMessageRequest</returns>
public static DeleteMessageRequest ForChannelFromTime(string channel, long start)
{
if (string.IsNullOrWhiteSpace(channel))
{
throw new ArgumentException("Channel cannot be null or empty", nameof(channel));
}

if (start < 0)
{
throw new ArgumentException("Start timetoken cannot be negative", nameof(start));
}

return new DeleteMessageRequest
{
Channel = channel,
Start = start
};
}

/// <summary>
/// Creates a new DeleteMessageRequest for deleting messages up to a specific end time.
/// </summary>
/// <param name="channel">The channel to delete messages from</param>
/// <param name="end">The ending timetoken (exclusive)</param>
/// <returns>A configured DeleteMessageRequest</returns>
public static DeleteMessageRequest ForChannelUntilTime(string channel, long end)
{
if (string.IsNullOrWhiteSpace(channel))
{
throw new ArgumentException("Channel cannot be null or empty", nameof(channel));
}

if (end < 0)
{
throw new ArgumentException("End timetoken cannot be negative", nameof(end));
}

return new DeleteMessageRequest
{
Channel = channel,
End = end
};
}
}
}
Loading
Loading