Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>0.17.0</Version>
<Version>0.18.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/Resend/IResend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ public interface IResend
/// <returns>Response.</returns>
Task<ResendResponse> BroadcastCancelAsync( Guid broadcastId, CancellationToken cancellationToken = default );

/// <summary>
/// Duplicates a broadcast.
/// </summary>
/// <param name="broadcastId">Broadcast identifier.</param>
/// <param name="cancellationToken">Cancelation token.</param>
/// <returns>Identifier of newly created duplicate.</returns>
/// <see href="https://resend.com/docs/api-reference/broadcasts/duplicate-broadcast"/>
Task<ResendResponse<Guid>> BroadcastDuplicateAsync( Guid broadcastId, CancellationToken cancellationToken = default );
Comment thread
gabrielmfern marked this conversation as resolved.

/// <summary>
/// Lists all broadcasts.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Resend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The `ResendClient` supports the following objects (and methods):
* Receiving (List, Retrieve, Attachment List, Attachment Retrieve)
* Domain (List, Add, Retrieve, Update, Verify, Delete)
* API key (List, Create, Delete)
* Broadcast (List, Add, Retrieve, Update, Send, Schedule, Delete)
* Broadcast (List, Add, Retrieve, Update, Send, Schedule, Duplicate, Delete)
* Audience (List, Add, Retrieve, Delete)
* Contact (List, Add, Retrieve, Update, Delete)
* Segment (List, Create, Retrieve, Update, Delete)
Expand Down
10 changes: 10 additions & 0 deletions src/Resend/ResendClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ private static string ToUtcQueryValue( DateTime value )
}


/// <inheritdoc/>
public Task<ResendResponse<Guid>> BroadcastDuplicateAsync( Guid broadcastId, CancellationToken cancellationToken = default )
{
var path = $"/broadcasts/{broadcastId}/duplicate";
var req = new HttpRequestMessage( HttpMethod.Post, path );

return Execute<ObjectId, Guid>( req, ( x ) => x.Id, cancellationToken );
}


/// <inheritdoc/>
public Task<ResendResponse<List<Broadcast>>> BroadcastListAsync( CancellationToken cancellationToken = default )
{
Expand Down
15 changes: 15 additions & 0 deletions tests/Resend.Tests/ResendClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,21 @@ public async Task BroadcastCancel()
}


/// <summary/>
[Fact]
public async Task BroadcastDuplicate()
{
var broadcastId = Guid.NewGuid();

var resp = await _resend.BroadcastDuplicateAsync( broadcastId );

Assert.NotNull( resp );
Assert.True( resp.Success );
Assert.NotEqual( Guid.Empty, resp.Content );
Assert.NotEqual( broadcastId, resp.Content );
}


/// <summary/>
[Fact]
public async Task BroadcastList()
Expand Down
15 changes: 15 additions & 0 deletions tools/Resend.ApiServer/Controllers/BroadcastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public ActionResult BroadcastCancel( [FromRoute] Guid broadcastId )
}


/// <summary />
[HttpPost]
[Route( "broadcasts/{broadcastId}/duplicate" )]
public ObjectId BroadcastDuplicate( [FromRoute] Guid broadcastId )
{
_logger.LogDebug( "BroadcastDuplicate" );

return new ObjectId()
{
Object = "broadcast",
Id = Guid.NewGuid(),
};
}


/// <summary>
/// The fake server has no persisted state, so the well-known empty id doubles as the
/// "broadcast not found" fixture for tests, mirroring <see cref="EmailController.EmailShare"/>.
Expand Down
34 changes: 34 additions & 0 deletions tools/Resend.Cli/Broadcast/BroadcastDuplicateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using McMaster.Extensions.CommandLineUtils;
using System.ComponentModel.DataAnnotations;

namespace Resend.Cli.Broadcast;

/// <summary />
[Command( "duplicate", Description = "Duplicate a broadcast" )]
public class BroadcastDuplicateCommand
{
private readonly IResend _resend;


/// <summary />
[Argument( 0, Description = "Broadcast identifier" )]
[Required]
public Guid? BroadcastId { get; set; }


/// <summary />
public BroadcastDuplicateCommand( IResend resend )
{
_resend = resend;
}


/// <summary />
public async Task<int> OnExecuteAsync()
{
var res = await _resend.BroadcastDuplicateAsync( this.BroadcastId!.Value );
Console.WriteLine( res.Content );

return 0;
}
}
1 change: 1 addition & 0 deletions tools/Resend.Cli/BroadcastCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Resend.Cli;
[Subcommand( typeof( Broadcast.BroadcastCancelCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastClickedLinksCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastDeleteCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastDuplicateCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastListCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastListRecipientsCommand ) )]
[Subcommand( typeof( Broadcast.BroadcastRetrieveCommand ))]
Expand Down
Loading