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

Commit

Permalink
Merge pull request #376 from QuantozTechnology/support-serveruri-paths
Browse files Browse the repository at this point in the history
Support ServerUri with a path included
  • Loading branch information
elucidsoft authored Oct 31, 2022
2 parents fb6fc02 + 259bfaf commit 373b68f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 15 additions & 0 deletions stellar-dotnet-sdk-test/requests/AccountsRequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ public void TestAccountsBuildUri()
}
}

[TestMethod]
public void TestAccountsBuildUriPathPrefix()
{
using (var server = new Server("https://nodeapi.com/xlm/authkey/"))
{
var uri = server.Accounts
.Cursor("13537736921089")
.Limit(200)
.Order(OrderDirection.ASC)
.BuildUri();

Assert.AreEqual("https://nodeapi.com/xlm/authkey/accounts?cursor=13537736921089&limit=200&order=asc", uri.ToString());
}
}

[TestMethod]
public async Task TestAccountsAccount()
{
Expand Down
9 changes: 6 additions & 3 deletions stellar-dotnet-sdk/requests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using stellar_dotnet_sdk.responses.operations;

namespace stellar_dotnet_sdk.requests
{
Expand All @@ -20,6 +19,7 @@ public class RequestBuilder<T> where T : class
private readonly List<string> _segments;
private bool _segmentsAdded;
protected UriBuilder UriBuilder;
private readonly string _serverPathPrefix;

public static HttpClient HttpClient { get; set; }

Expand All @@ -41,6 +41,9 @@ public RequestBuilder(Uri serverUri, string defaultSegment, HttpClient httpClien
UriBuilder = new UriBuilder(serverUri);
_segments = new List<string>();

// Store the required path part of the serverUri
_serverPathPrefix = UriBuilder.Path;

if (!string.IsNullOrEmpty(defaultSegment))
SetSegments(defaultSegment);

Expand Down Expand Up @@ -120,10 +123,10 @@ public Uri BuildUri()
{
if (_segments.Count > 0)
{
var path = "";
var path = _serverPathPrefix;

foreach (var segment in _segments)
path += "/" + segment;
path += (path.EndsWith("/") ? string.Empty : "/") + segment;

UriBuilder.Path = path;

Expand Down

0 comments on commit 373b68f

Please sign in to comment.