Skip to content
Open
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
22 changes: 21 additions & 1 deletion EasyPost.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading;
Expand All @@ -7,8 +8,8 @@
using EasyPost.Exceptions.API;
using EasyPost.Tests._Utilities;
using EasyPost.Tests._Utilities.Attributes;
using Newtonsoft.Json.Linq;
using Xunit;
using CustomAssertions = EasyPost.Tests._Utilities.Assertions.Assert;

namespace EasyPost.Tests
{
Expand Down Expand Up @@ -301,5 +302,24 @@ public async Task TestCancellationToken()
// this will not record a cassette because the request should be cancelled before it is sent
await Assert.ThrowsAsync<TimeoutError>(async () => await Client.Address.Create(new Parameters.Address.Create(), token));
}

[Fact]
[Testing.Function]
public async Task TestClientMakeApiCall()
{
UseVCR("make_api_call");

Dictionary<string, object> parameters = new()
{
{ "page_size", 1 },
};

Dictionary<string, object> response = await Client.MakeApiCallAsync(Http.Method.Get, "/addresses", parameters);

JArray addresses = response["addresses"] as JArray;
Assert.Single(addresses);
JObject firstAddress = addresses[0] as JObject;
Assert.Equal("Address", firstAddress["object"].ToString());
}
}
}
48 changes: 48 additions & 0 deletions EasyPost.Tests/cassettes/net/client/make_api_call.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions EasyPost/_base/EasyPostClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ public async Task<bool> RequestAsync(Method method, string endpoint, ApiVersion
return errorRaised;
}

/// <summary>
/// Make an API call to the EasyPost API.
/// This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
/// are not yet supported by the client library's services. When possible, the service for your use case
/// should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
/// </summary>
/// <param name="method">HTTP <see cref="Method"/> to use for the request.</param>
/// <param name="endpoint">EasyPost API endpoint to use for the request.</param>
/// <param name="parameters">Parameters to use for the request.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/> to use for the HTTP request.</param>
/// <returns>A <see cref="Dictionary{TKey, TValue}"/> representing the response data.</returns>
public async Task<Dictionary<string, object>> MakeApiCallAsync(Method method, string endpoint, Dictionary<string, object> parameters, CancellationToken cancellationToken = default)
{
return await RequestAsync<Dictionary<string, object>>(method, endpoint, ApiVersion.Current, cancellationToken, parameters);
}

/// <summary>
/// Compare this <see cref="EasyPostClient"/> to another object for equality.
/// </summary>
Expand Down
Loading