Skip to content

Commit 5bdc670

Browse files
Add version support in the URL
1 parent 0d9f230 commit 5bdc670

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CSharpHTTPClient/Client.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ public Client(string host, Dictionary<string,string> requestHeaders = null, stri
5252

5353
private string BuildUrl(string query_params = null)
5454
{
55-
string endpoint = _host + "/" + _version + _urlPath;
55+
string endpoint = null;
56+
if( _version != null)
57+
{
58+
endpoint = _host + "/" + _version + _urlPath;
59+
}
60+
else
61+
{
62+
endpoint = _host + _urlPath;
63+
}
5664

5765
if (query_params != null)
5866
{
@@ -85,6 +93,11 @@ private Client BuildClient(string name = null)
8593
return new Client(_host, _requestHeaders, _version, endpoint);
8694
}
8795

96+
private void AddVersion(string version)
97+
{
98+
_version = version;
99+
}
100+
88101
// Magic method to handle special cases
89102
public Client _(string magic)
90103
{
@@ -101,6 +114,13 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
101114
// Catch final method call
102115
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
103116
{
117+
if (binder.Name == "version")
118+
{
119+
AddVersion(args[0].ToString());
120+
result = BuildClient();
121+
return true;
122+
}
123+
104124
var paramDict = new Dictionary<string, object>();
105125
string query_params = null;
106126
string request_body = null;

Example/Example.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void Main(string[] args)
2222
string query_params = @"{
2323
'limit': 100
2424
}";
25-
dynamic response = client.api_keys.get(query_params: query_params);
25+
dynamic response = client.version("v3").api_keys.get(query_params: query_params);
2626
Console.WriteLine(response.StatusCode);
2727
Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result);
2828
Console.WriteLine(response.ResponseHeaders.ToString());

0 commit comments

Comments
 (0)