Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ably request method param #1260

Merged
merged 7 commits into from
Oct 13, 2023
Merged
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,20 @@ DateTimeOffset time = await client.TimeAsync();
- It automatically adds necessary auth headers based on the initial auth config and supports pagination.
- The following is an example of using the batch publish API based on the [Ably batch publish rest endpoint documentation](https://ably.com/docs/api/rest-api#batch-publish).
```csharp
var jsonPayload =
@"{
""channels"" : [ ""channel1"", ""channel2"" ],
""messages"" : [
var objectPayload = new
{
channels = new[] { "channel1", "channel2", "channel3", "channel4" },
messages = new[]
{
new
{
""name"": ""eventName"",
""data"" : ""message"",
name = "eventName",
data = "foo",
}
]
}";
var paginatedResponse = await ablyRest.Request(HttpMethod.Post, "/messages", null, JObject.Parse(jsonPayload), null);
}
};
var jsonPayload = JsonConvert.SerializeObject(objectPayload);
var paginatedResponse = await ablyRest.Request(HttpMethod.Post, "/messages", null, jsonPayload, null);
```
- Follow official [ably rest endpoint doc](https://ably.com/docs/api/rest-api) for more information on other endpoints.

Expand Down
12 changes: 9 additions & 3 deletions src/IO.Ably.Shared/AblyRest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,19 @@ internal async Task<HttpPaginatedResponse> HttpPaginatedRequestInternal(Paginate
/// <param name="method">http method.</param>
/// <param name="path">the path component of the resource URI.</param>
/// <param name="requestParams">(optional; may be null): any parameters to send with the request; see API-specific documentation.</param>
/// <param name="body">(optional; may be null): an instance of RequestBody. It will be sent as a json object.</param>
/// <param name="body">(optional; may be null): a json string RequestBody. It will be sent as a json object.</param>
/// <param name="headers">(optional; may be null): any additional headers to send; see API-specific documentation.</param>
/// <returns>a page of results.</returns>
public async Task<HttpPaginatedResponse> Request(string method, string path, Dictionary<string, string> requestParams = null, JToken body = null, Dictionary<string, string> headers = null)
public async Task<HttpPaginatedResponse> Request(string method, string path, Dictionary<string, string> requestParams = null, string body = null, Dictionary<string, string> headers = null)
{
var httpMethod = new HttpMethod(method);
return await Request(httpMethod, path, requestParams, body, headers);
JToken requestBody = null;
if (body != null)
{
requestBody = JToken.Parse(body);
}

return await Request(httpMethod, path, requestParams, requestBody, headers);
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/IO.Ably.Tests.Shared/Rest/RequestSandBoxSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RichardSzalay.MockHttp;
using Xunit;
Expand Down Expand Up @@ -162,7 +163,7 @@ async Task ValidateMessages(string channelName, Action<Message, int> validate)
data = "foo",
}
};
var paginatedResponse = await client.Request(HttpMethod.Post, "/messages", null, JObject.FromObject(objectPayload), null);
var paginatedResponse = await client.Request(HttpMethod.Post, "/messages", null, JToken.FromObject(objectPayload), null);

ValidateResponse(paginatedResponse);

Expand All @@ -189,7 +190,7 @@ await ValidateMessages(channel, (message, messageIndex) =>
}
]
}";
paginatedResponse = await client.Request(HttpMethod.Post, "/messages", null, JObject.Parse(jsonPayload), null);
paginatedResponse = await client.Request(HttpMethod.Post.Method, "/messages", null, jsonPayload, null);

ValidateResponse(paginatedResponse, 5);

Expand Down
Loading