1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 08:56:13 +00:00

Added AppendPath method

This commit is contained in:
Jan Korf 2021-11-24 19:32:37 +01:00
parent 8b619e82f2
commit 9ebe5de825
5 changed files with 32 additions and 10 deletions

View File

@ -124,5 +124,18 @@ namespace CryptoExchange.Net.UnitTests
// assert
Assert.IsTrue(result == "http://test.api/1/path/test");
}
[TestCase("https://api.test.com/api", new[] { "path1", "path2" }, "https://api.test.com/api/path1/path2")]
[TestCase("https://api.test.com/api", new[] { "path1", "/path2" }, "https://api.test.com/api/path1/path2")]
[TestCase("https://api.test.com/api", new[] { "path1/", "path2" }, "https://api.test.com/api/path1/path2")]
[TestCase("https://api.test.com/api", new[] { "path1/", "/path2" }, "https://api.test.com/api/path1/path2")]
[TestCase("https://api.test.com/api/", new[] { "path1", "path2" }, "https://api.test.com/api/path1/path2")]
[TestCase("https://api.test.com", new[] { "test-path/test-path" }, "https://api.test.com/test-path/test-path")]
[TestCase("https://api.test.com/", new[] { "test-path/test-path" }, "https://api.test.com/test-path/test-path")]
public void AppendPathTests(string baseUrl, string[] path, string expected)
{
var result = baseUrl.AppendPath(path);
Assert.AreEqual(expected, result);
}
}
}

View File

@ -116,7 +116,7 @@ namespace CryptoExchange.Net.UnitTests
// assert
Assert.IsTrue(client.ClientOptions.BaseAddress == "http://test.address.com/");
Assert.IsTrue(client.ClientOptions.BaseAddress == "http://test.address.com");
Assert.IsTrue(client.ClientOptions.RateLimiters.Count == 1);
Assert.IsTrue(client.ClientOptions.RateLimitingBehaviour == RateLimitingBehaviour.Fail);
Assert.IsTrue(client.ClientOptions.RequestTimeout == TimeSpan.FromMinutes(1));

View File

@ -25,7 +25,7 @@ namespace CryptoExchange.Net.UnitTests
//assert
Assert.IsTrue(client.ClientOptions.BaseAddress == "http://test.address.com/");
Assert.IsTrue(client.ClientOptions.BaseAddress == "http://test.address.com");
Assert.IsTrue(client.ClientOptions.ReconnectInterval.TotalSeconds == 6);
}

View File

@ -352,6 +352,23 @@ namespace CryptoExchange.Net
return message.ToString();
}
/// <summary>
/// Append a base url with provided path
/// </summary>
/// <param name="url"></param>
/// <param name="path"></param>
/// <returns></returns>
public static string AppendPath(this string url, params string[] path)
{
if (!url.EndsWith("/"))
url += "/";
foreach (var item in path)
url += item.Trim('/') + "/";
return url.TrimEnd('/');
}
}
}

View File

@ -78,14 +78,6 @@ namespace CryptoExchange.Net.Objects
if (value == null)
return;
// TODO addresses can't always be forced to end with '/', bybit websocket doesn't work with it.
// Should be fixed in the GetUrl methods?
//var newValue = value;
//if (!newValue.EndsWith("/"))
// newValue += "/";
//_baseAddress = newValue;
_baseAddress = value;
}
}