public async Task Remove(AuthorizedNetwork address) { var request = CreateHttpJsonPost(URL_BASE + "security/whitelist/remove.json", URL_BASE + "security/settings", cookies); var post = string.Format("{{\"ip\":\"{0}\",\"prefix\":\"{1}\",\"location\":\"undefined\"}}", address.Address, address.NetworkPrefix); using (var rs = request.GetRequestStream()) { var buffer = Encoding.UTF8.GetBytes(post); rs.Write(buffer, 0, buffer.Length); } try { using (var response = await request.GetResponseAsync()) { OnHeadersReceived(response.Headers); using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var data = await reader.ReadToEndAsync(); } } } catch (WebException e) { ThrowForWebException(e); throw; } }
public async Task <AuthorizedNetwork[]> GetAuthorizedNetworks() { var request = CreateHttp(URL_BASE + "security/settings.json", URL_BASE + "overview", this.cookies); try { using (var response = await request.GetResponseAsync()) { OnHeadersReceived(response.Headers); using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var data = await reader.ReadToEndAsync(); var json = (Dictionary <string, object>)Api.Json.Decode(data); var whitelist = (List <object>)json["whitelist"]; var networks = new AuthorizedNetwork[whitelist.Count]; int i = 0; foreach (Dictionary <string, object> entry in whitelist) { networks[i++] = new AuthorizedNetwork((string)entry["address"], int.Parse((string)entry["network_prefix"])); } return(networks); } } } catch (WebException e) { ThrowForWebException(e); throw; } }