mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-07-27 03:36:52 +00:00
Added AppendPath method
This commit is contained in:
parent
8b619e82f2
commit
9ebe5de825
@ -124,5 +124,18 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
// assert
|
// assert
|
||||||
Assert.IsTrue(result == "http://test.api/1/path/test");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
|
|
||||||
|
|
||||||
// assert
|
// 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.RateLimiters.Count == 1);
|
||||||
Assert.IsTrue(client.ClientOptions.RateLimitingBehaviour == RateLimitingBehaviour.Fail);
|
Assert.IsTrue(client.ClientOptions.RateLimitingBehaviour == RateLimitingBehaviour.Fail);
|
||||||
Assert.IsTrue(client.ClientOptions.RequestTimeout == TimeSpan.FromMinutes(1));
|
Assert.IsTrue(client.ClientOptions.RequestTimeout == TimeSpan.FromMinutes(1));
|
||||||
|
@ -25,7 +25,7 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
|
|
||||||
|
|
||||||
//assert
|
//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);
|
Assert.IsTrue(client.ClientOptions.ReconnectInterval.TotalSeconds == 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +352,23 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
return message.ToString();
|
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('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +78,6 @@ namespace CryptoExchange.Net.Objects
|
|||||||
if (value == null)
|
if (value == null)
|
||||||
return;
|
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;
|
_baseAddress = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user