csharp.WebRequestPathBuilder.mustache Maven / Gradle / Ivy
{{>partial_header}}
using System;
using System.Collections.Generic;
namespace {{packageName}}.Client
{
///
/// A URI builder
///
class WebRequestPathBuilder
{
private string _baseUrl;
private string _path;
private string _query = "?";
public WebRequestPathBuilder(string baseUrl, string path)
{
_baseUrl = baseUrl;
_path = path;
}
public void AddPathParameters(Dictionary parameters)
{
foreach (var parameter in parameters)
{
_path = _path.Replace("{" + parameter.Key + "}", Uri.EscapeDataString(parameter.Value));
}
}
public void AddQueryParameters(Multimap parameters)
{
foreach (var parameter in parameters)
{
foreach (var value in parameter.Value)
{
_query = _query + parameter.Key + "=" + Uri.EscapeDataString(value) + "&";
}
}
}
public string GetFullUri()
{
return _baseUrl + _path + _query.Substring(0, _query.Length - 1);
}
}
}