today I coded a simple API class in C# with just a WebClient instance in each void and just simple voids to do simple things, can anyone give me any support in how I can improove it? Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace uTune.Base.Api
{
class API
{
/// <summary>
/// Runs a website script vue a url.
/// </summary>
/// <param name="url">URL to run.</param>
public void runScript(string url)
{
WebClient client = new WebClient();
client.DownloadString(url);
}
/// <summary>
/// Runs a website script with the option of multiple parameters
/// </summary>
/// <param name="url">URL to run.</param>
/// <param name="parameters">A list of parameters to include.</param>
public void runScriptWithParameters(string url, Dictionary<string, string> parameters)
{
string urlToRun = url;
bool firstParam = true;
if (parameters.Count > 0)
{
foreach (KeyValuePair<string, string> parameter in parameters)
{
if (firstParam)
{
urlToRun += "?" + parameter.Key + "=" + parameter.Value;
firstParam = false;
}
else
{
urlToRun += "&" + parameter.Key + "=" + parameter.Value;
}
}
}
runScript(urlToRun);
}
/// <summary>
/// Returns the pages content after a script has been executed.
/// </summary>
/// <param name="url">URL to get the content from.</param>
/// <returns>Webpages content.</returns>
public string getScriptReturn(string url)
{
WebClient client = new WebClient();
return client.DownloadString(url);
}
/// <summary>
/// Returns the pages conect after a script has been executed.
/// </summary>
/// <param name="url">URL to get the content form.</param>
/// <param name="parameters">Parameters included in the URL.</param>
/// <returns>Webpages content</returns>
public string getScriptReturnWithParameters(string url, Dictionary<string, string> parameters)
{
string urlToRun = url;
bool firstParam = true;
if (parameters.Count > 0)
{
foreach (KeyValuePair<string, string> parameter in parameters)
{
if (firstParam)
{
urlToRun += "?" + parameter.Key + "=" + parameter.Value;
firstParam = false;
}
else
{
urlToRun += "&" + parameter.Key + "=" + parameter.Value;
}
}
}
return getScriptReturn(urlToRun);
}
}
}