using System; using System.Net; using System.IO; using System.Collections.Specialized; namespace MWAPI { public class MW_API { private string apiKey; private string apiUrl; public MW_API(string aKey, string aUrl = "https://api.microworkers.com") { apiKey = aKey; apiUrl = aUrl; } public string getRequest (string action) { WebClient client = new WebClient (); client.Headers.Add ("MicroworkersApiKey", apiKey); Stream data = client.OpenRead (apiUrl + action); StreamReader reader = new StreamReader (data); string s = reader.ReadToEnd (); data.Close (); reader.Close (); return s; } public string deleteRequest (string action, NameValueCollection dataCollection) { WebClient client = new WebClient (); client.Headers.Add ("MicroworkersApiKey", apiKey); byte[] b = client.UploadValues(apiUrl + action, "DELETE", dataCollection); string s = System.Text.Encoding.UTF8.GetString(b); return s; } public string putRequest (string action, NameValueCollection dataCollection) { WebClient client = new WebClient (); client.Headers.Add ("MicroworkersApiKey", apiKey); byte[] b = client.UploadValues(apiUrl + action, "PUT", dataCollection); string s = System.Text.Encoding.UTF8.GetString(b); return s; } public string postRequest (string action, NameValueCollection dataCollection) { WebClient client = new WebClient (); client.Headers.Add ("MicroworkersApiKey", apiKey); byte[] b = client.UploadValues(apiUrl + action, "POST", dataCollection); string s = System.Text.Encoding.UTF8.GetString(b); return s; } } }