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

SDK Updates #120

Merged
merged 2 commits into from
Sep 1, 2022
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
40 changes: 0 additions & 40 deletions src/FaluSdk/Messages/MessagesServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ public virtual Task<ResourceResponse<MessageCreateResponse>> CreateAsync(Message
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 All @@ -92,33 +79,6 @@ public virtual Task<ResourceResponse<Message>> UpdateAsync(string id,
return UpdateResourceAsync(id, patch, options, cancellationToken);
}

/// <summary>Send a batch of messages.</summary>
/// <param name="messages"></param>
/// <param name="options">Options to use for the request.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("Migrate to using MessageBatch API resource.")]
public virtual Task<ResourceResponse<MessageCreateResponse>> SendBatchAsync(IList<MessageCreateRequest> messages,
RequestOptions? options = null,
CancellationToken cancellationToken = default)
{
if (messages is null) throw new ArgumentNullException(nameof(messages));

if (messages.Count > 1_000)
{
throw new ArgumentOutOfRangeException(paramName: nameof(messages),
message: "The service does not support more than 1,000 (1k) messages");
}

foreach (var m in messages)
{
m.Template?.Model?.GetType().EnsureAllowedForMessageTemplateModel();
}

var uri = MakePath("/batch");
return RequestAsync<MessageCreateResponse>(uri, HttpMethod.Post, messages, options, cancellationToken);
}

/// <summary>Cancel a message preventing further updates.</summary>
/// <param name="id">Unique identifier for the message.</param>
/// <param name="options">Options to use for the request.</param>
Expand Down
44 changes: 0 additions & 44 deletions tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,50 +110,6 @@ await TestAsync(handler, async (client) =>
});
}

[Theory]
[MemberData(nameof(RequestOptionsData))]
public async Task SendBatchAsync_Works(RequestOptions options)
{
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal($"{BasePath}/batch", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, options);

var content = new MessageCreateResponse
{
Created = Data.Created,
Ids = new[] { Data.Id!, },
Live = Data.Live,
Workspace = Data.Workspace,
};
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonSerializer.Serialize(content), Encoding.UTF8, MediaTypeNames.Application.Json)
};

return response;
});

await TestAsync(handler, async (client) =>
{
var model = new MessageCreateRequest
{
To = new[] { Data!.To!, },
Body = Data!.Body
};

#pragma warning disable CS0618 // Type or member is obsolete
var response = await client.Messages.SendBatchAsync(new[] { model }, options);
#pragma warning restore CS0618 // Type or member is obsolete

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Resource?.Ids);
Assert.Single(response.Resource.Ids);
});
}

[Theory]
[MemberData(nameof(RequestOptionsData))]
public async Task UpdateAsync_Works(RequestOptions options)
Expand Down