Skip to content

Commit

Permalink
API updates (#115)
Browse files Browse the repository at this point in the history
- Added support for message batches API hence mark `SendBatchAsync(...)` as obsolete in its favour.
- Added endpoints/methods for cancel and redact on identity verifications, evaluations and messages.
- Added `Batch`, `Segements`, `Sent` properties to `Message`.
- Added filters by `sent`, `batch`, and `stream ` when listing messages
  • Loading branch information
mburumaxwell authored Aug 26, 2022
1 parent b7115c9 commit 03eb94a
Show file tree
Hide file tree
Showing 20 changed files with 685 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/FaluSdk/Core/BaseServiceClientOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ protected virtual Task<ResourceResponse<TResource>> UpdateResourceAsync(string i
}


///
protected virtual Task<ResourceResponse<TResource>> CancelResourceAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
var uri = $"{MakeResourcePath(id)}/cancel";
return RequestAsync<TResource>(uri, HttpMethod.Post, null, options, cancellationToken);
}

///
protected virtual Task<ResourceResponse<TResource>> RedactResourceAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
var uri = $"{MakeResourcePath(id)}/redact";
return RequestAsync<TResource>(uri, HttpMethod.Post, null, options, cancellationToken);
}

///
protected virtual Task<ResourceResponse<object>> DeleteResourceAsync(string id,
RequestOptions? options = null,
Expand Down
16 changes: 16 additions & 0 deletions src/FaluSdk/Core/ISupportsCanceling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Falu.Core;

///
public interface ISupportsCanceling<TResource> where TResource : IHasId, IHasRedaction
{
/// <summary>
///
/// </summary>
/// <param name="id">Unique identifier for the object.</param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<ResourceResponse<TResource>> CancelAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default);
}
16 changes: 14 additions & 2 deletions src/FaluSdk/Evaluations/EvaluationsServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class EvaluationsServiceClient : BaseServiceClient<Evaluation>,
ISupportsRetrieving<Evaluation>,
ISupportsCreation<Evaluation, EvaluationCreateRequest>,
ISupportsUpdating<Evaluation, EvaluationPatchModel>,
ISupportsCanceling<Evaluation>,
ISupportsRedaction<Evaluation>
{
///
Expand Down Expand Up @@ -79,6 +80,18 @@ public virtual Task<ResourceResponse<Evaluation>> CreateAsync(EvaluationCreateRe
return CreateResourceAsync(request, options, cancellationToken);
}

/// <summary>Cancel an evaluation preventing further updates.</summary>
/// <param name="id">Unique identifier for the evaluation.</param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<ResourceResponse<Evaluation>> CancelAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
return CancelResourceAsync(id, options, cancellationToken);
}

/// <summary>Redact an evaluation to remove all collected information from Falu.</summary>
/// <param name="id">Unique identifier for the evaluation.</param>
/// <param name="options">Options to use for the request.</param>
Expand All @@ -88,7 +101,6 @@ public Task<ResourceResponse<Evaluation>> RedactAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
var uri = $"{MakeResourcePath(id)}/redact";
return RequestAsync<Evaluation>(uri, HttpMethod.Post, new { }, options, cancellationToken);
return RedactResourceAsync(id, options, cancellationToken);
}
}
5 changes: 5 additions & 0 deletions src/FaluSdk/FaluClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Falu.Identity;
using Falu.IdentityVerificationReports;
using Falu.IdentityVerifications;
using Falu.MessageBatches;
using Falu.Messages;
using Falu.MessageStreams;
using Falu.MessageTemplates;
Expand Down Expand Up @@ -53,6 +54,7 @@ public FaluClient(HttpClient backChannel, IOptionsSnapshot<TOptions> optionsAcce
IdentityVerifications = new IdentityVerificationsServiceClient(BackChannel, Options);
IdentityVerificationReports = new IdentityVerificationReportsServiceClient(BackChannel, Options);
Messages = new MessagesServiceClient(BackChannel, Options);
MessageBatches = new MessageBatchesServiceClient(BackChannel, Options);
MessageStreams = new MessageStreamsServiceClient(BackChannel, Options);
MessageTemplates = new MessageTemplatesServiceClient(BackChannel, Options);
MoneyBalances = new MoneyBalancesServiceClient(BackChannel, Options);
Expand Down Expand Up @@ -100,6 +102,9 @@ public FaluClient(HttpClient backChannel, IOptionsSnapshot<TOptions> optionsAcce
///
public virtual MessagesServiceClient Messages { get; protected set; }

///
public virtual MessageBatchesServiceClient MessageBatches { get; protected set; }

///
public virtual MessageStreamsServiceClient MessageStreams { get; protected set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ namespace Falu.IdentityVerifications;

///
public class IdentityVerificationsServiceClient : BaseServiceClient<IdentityVerification>,
ISupportsListing<IdentityVerification, IdentityVerificationsListOptions>,
ISupportsRetrieving<IdentityVerification>,
ISupportsCreation<IdentityVerification, IdentityVerificationCreateRequest>,
ISupportsUpdating<IdentityVerification, IdentityVerificationPatchModel>,
ISupportsRedaction<IdentityVerification>
ISupportsListing<IdentityVerification, IdentityVerificationsListOptions>,
ISupportsRetrieving<IdentityVerification>,
ISupportsCreation<IdentityVerification, IdentityVerificationCreateRequest>,
ISupportsUpdating<IdentityVerification, IdentityVerificationPatchModel>,
ISupportsCanceling<IdentityVerification>,
ISupportsRedaction<IdentityVerification>
{
///
public IdentityVerificationsServiceClient(HttpClient backChannel, FaluClientOptions options) : base(backChannel, options) { }
Expand Down Expand Up @@ -79,6 +80,18 @@ public virtual Task<ResourceResponse<IdentityVerification>> CreateAsync(Identity
return CreateResourceAsync(request, options, cancellationToken);
}

/// <summary>Cancel an identity verification preventing further updates.</summary>
/// <param name="id">Unique identifier for the identity verification.</param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<ResourceResponse<IdentityVerification>> CancelAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
return CancelResourceAsync(id, options, cancellationToken);
}

/// <summary>Redact an identity verification to remove all collected information from Falu.</summary>
/// <param name="id">Unique identifier for the identity verification.</param>
/// <param name="options">Options to use for the request.</param>
Expand All @@ -88,7 +101,6 @@ public Task<ResourceResponse<IdentityVerification>> RedactAsync(string id,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
var uri = $"{MakeResourcePath(id)}/redact";
return RequestAsync<IdentityVerification>(uri, HttpMethod.Post, new { }, options, cancellationToken);
return RedactResourceAsync(id, options, cancellationToken);
}
}
50 changes: 50 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Falu.Core;

namespace Falu.MessageBatches;

/// <summary>
/// Represents a batch of messages
/// </summary>
public class MessageBatch : MessageBatchPatchModel, IHasId, IHasCreated, IHasUpdated, IHasRedaction, IHasWorkspace, IHasLive, IHasEtag
{
/// <inheritdoc/>
public string? Id { get; set; }

/// <inheritdoc/>
public DateTimeOffset Created { get; set; }

/// <inheritdoc/>
public DateTimeOffset Updated { get; set; }

/// <summary>
/// Stream used for the message.
/// </summary>
public string? Stream { get; set; }

/// <summary>
/// Schedule information for the message batch.
/// </summary>
public MessageBatchSchedule? Schedule { get; set; }

/// <summary>
/// Unique identifiers of the messages tracked in this batch.
/// </summary>
public List<string>? Messages { get; set; }

/// <summary>
/// Total number of segments from each message.
/// </summary>
public int Segements { get; set; }

/// <inheritdoc/>
public DataRedaction? Redaction { get; set; }

/// <inheritdoc/>
public string? Workspace { get; set; }

/// <inheritdoc/>
public bool Live { get; set; }

/// <inheritdoc/>
public string? Etag { get; set; }
}
28 changes: 28 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatchCreateRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Falu.Messages;

namespace Falu.MessageBatches;

/// <summary>
/// Information for creating a message batch.
/// </summary>
public class MessageBatchCreateRequest
{
/// <summary>
/// The messages.
/// </summary>
public List<MessageBatchCreateRequestMessage>? Messages { get; set; }

/// <summary>
/// The stream to use.
/// It can either be the name or unique identifier of the stream.
/// If not provided, message will default to the "transactional" stream.
/// </summary>
public string Stream { get; set; } = "transactional";

/// <summary>
/// Schedule for sending the message batch.
/// When <see langword="null"/>, the message batch
/// is enqueued for immediate sending.
/// </summary>
public MessageCreateRequestSchedule? Schedule { get; set; }
}
27 changes: 27 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatchCreateRequestMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Falu.Messages;

namespace Falu.MessageBatches;

/// <summary>
/// Information about one or more messages to be created in a batch
/// </summary>
public class MessageBatchCreateRequestMessage
{
/// <summary>
/// Destination phone numbers in <see href="https://en.wikipedia.org/wiki/E.164">E.164 format</see>.
/// You can provide up to 500 numbers in one request.
/// </summary>
public IList<string>? To { get; set; }

/// <summary>
/// Actual message content to be sent.
/// Required if <see cref="Template"/> is not specified.
/// </summary>
public string? Body { get; set; }

/// <summary>
/// The template to use.
/// Required if <see cref="Body"/> is not specified.
/// </summary>
public MessageSourceTemplate? Template { get; set; }
}
12 changes: 12 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatchPatchModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Falu.Core;

namespace Falu.MessageBatches;

/// <summary>
/// A model representing details that can be changed about a message batch.
/// </summary>
public class MessageBatchPatchModel : IHasMetadata
{
/// <inheritdoc/>
public Dictionary<string, string>? Metadata { get; set; }
}
17 changes: 17 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatchSchedule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Falu.MessageBatches;

/// <summary>
/// Information about scheduling for a message batch.
/// </summary>
public class MessageBatchSchedule
{
/// <summary>
/// Time at which the message batch is/was scheduled scheduled to be sent.
/// </summary>
public DateTimeOffset Time { get; set; }

/// <summary>
/// Duration for which the message batch is/was to be delayed before sending.
/// </summary>
public TimeSpan? Delay { get; set; }
}
19 changes: 19 additions & 0 deletions src/FaluSdk/MessageBatches/MessageBatchesListOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Falu.Core;

namespace Falu.MessageBatches;

/// <summary>Options for filtering and pagination of message batches.</summary>
public record MessageBatchesListOptions : BasicListOptions
{
/// <summary>
/// Unique identifier of the message stream to filter for.
/// </summary>
public string? Stream { get; set; }

/// <inheritdoc/>
internal override void Populate(QueryValues values)
{
base.Populate(values);
values.Add("stream", Stream);
}
}
Loading

0 comments on commit 03eb94a

Please sign in to comment.