Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
General SDK updates (#116)
Browse files Browse the repository at this point in the history
- Added `CreateAsync(...)` in `MessagesServiceClient` and mark `SendAsync(...)` as obsolete.
- Replace `Message.Provider` with `Message.Error`.
  • Loading branch information
mburumaxwell authored Aug 29, 2022
1 parent 03eb94a commit 4972f5d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 45 deletions.
13 changes: 5 additions & 8 deletions src/FaluSdk/FaluClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ public class FaluClientOptions

internal static JsonSerializerOptions GetSerializerOptions()
{
if (serializerOptions is null)
serializerOptions ??= new(JsonSerializerDefaults.Web)
{
serializerOptions = new(JsonSerializerDefaults.Web)
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
};
}
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
};

return serializerOptions;
}
Expand Down
10 changes: 5 additions & 5 deletions src/FaluSdk/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public class Message : MessagePatchModel, IHasId, IHasCreated, IHasUpdated, IHas
/// </summary>
public int Segements { get; set; }

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

/// <summary>
/// Schedule information for the message.
/// </summary>
Expand All @@ -70,6 +65,11 @@ public class Message : MessagePatchModel, IHasId, IHasCreated, IHasUpdated, IHas
/// </summary>
public DateTimeOffset? Sent { get; set; }

/// <summary>
/// If present, this property tells you the error encountered when processing the message.
/// </summary>
public MessageError? Error { get; set; }

/// <summary>
/// Time at which the message was delivered.
/// This is dependent on the underlying provider.
Expand Down
16 changes: 16 additions & 0 deletions src/FaluSdk/Messages/MessageError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Falu.Messages;

///
public class MessageError
{
/// <summary>
/// A short machine-readable string giving the reason for message failure.
/// </summary>
public string? Code { get; set; }

/// <summary>
/// A human-readable message that explains the reason for message failure.
/// These message can be shown to your user.
/// </summary>
public string? Message { get; set; }
}
20 changes: 0 additions & 20 deletions src/FaluSdk/Messages/MessageProvider.cs

This file was deleted.

22 changes: 18 additions & 4 deletions src/FaluSdk/Messages/MessagesServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Falu.Messages;
public class MessagesServiceClient : BaseServiceClient<Message>,
ISupportsListing<Message, MessagesListOptions>,
ISupportsRetrieving<Message>,
//ISupportsCreation<Message, MessageCreateRequest>,
ISupportsUpdating<Message, MessagePatchModel>,
ISupportsCanceling<Message>,
ISupportsRedaction<Message>
Expand Down Expand Up @@ -49,21 +50,34 @@ public virtual Task<ResourceResponse<Message>> GetAsync(string id,
return GetResourceAsync(id, options, cancellationToken);
}

/// <summary>Send a message.</summary>
/// <summary>Create a message.</summary>
/// <param name="message"></param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<ResourceResponse<MessageCreateResponse>> SendAsync(MessageCreateRequest message,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
public virtual Task<ResourceResponse<MessageCreateResponse>> CreateAsync(MessageCreateRequest message,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
if (message is null) throw new ArgumentNullException(nameof(message));
message.Template?.Model?.GetType().EnsureAllowedForMessageTemplateModel();

return CreateResourceAsync<MessageCreateResponse>(message, options, cancellationToken);
}

/// <summary>Send a message.</summary>
/// <param name="message"></param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("Use 'CreateAsync(...)' instead.")]
public virtual Task<ResourceResponse<MessageCreateResponse>> SendAsync(MessageCreateRequest message,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
return CreateAsync(message, options, cancellationToken);
}

/// <summary>Update a message.</summary>
/// <param name="id">Unique identifier for the message.</param>
/// <param name="patch"></param>
Expand Down
12 changes: 6 additions & 6 deletions src/FaluSdk/Webhooks/EventTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
public static class EventTypes
{
#region Evaluation
#region Evaluations

/// <summary>
/// Occurs whenever an evaluation is created.
Expand Down Expand Up @@ -42,7 +42,7 @@ public static class EventTypes

#endregion

#region IdentityVerifications
#region Identity Verifications

/// <summary>
/// Occurs whenever an identity verification is created.
Expand Down Expand Up @@ -135,7 +135,7 @@ public static class EventTypes

#endregion

#region MessageTemplates
#region Message Templates

/// <summary>
/// Occurs whenever a message template is created.
Expand Down Expand Up @@ -182,7 +182,7 @@ public static class EventTypes

#endregion

#region PaymentAuthorizations
#region Payment Authorizations

/// <summary>
/// Occurs whenever a payment authorization is requested.
Expand All @@ -201,7 +201,7 @@ public static class EventTypes

#endregion

#region PaymentRefunds
#region Payment Refunds

/// <summary>
/// Occurs whenever a payment refund is created.
Expand Down Expand Up @@ -249,7 +249,7 @@ public static class EventTypes

#endregion

#region TransferReversals
#region Transfer Reversals

/// <summary>
/// Occurs whenever a transfer reversal is created.
Expand Down
4 changes: 2 additions & 2 deletions tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ await TestAsync(handler, async (client) =>

[Theory]
[MemberData(nameof(RequestOptionsData))]
public async Task SendAsync_Works(RequestOptions options)
public async Task CreateAsync_Works(RequestOptions options)
{
var handler = CreateAsync_Handler(options);

Expand All @@ -103,7 +103,7 @@ await TestAsync(handler, async (client) =>
To = new[] { Data!.To!, },
Body = Data!.Body
};
var response = await client.Messages.SendAsync(model, options);
var response = await client.Messages.CreateAsync(model, options);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Resource);
Expand Down

0 comments on commit 4972f5d

Please sign in to comment.