diff options
| author | Grant Limberg <glimberg@gmail.com> | 2015-10-21 20:29:03 -0700 |
|---|---|---|
| committer | Grant Limberg <glimberg@gmail.com> | 2015-10-21 20:29:03 -0700 |
| commit | 5b6ddaa2d744dfc726829da0893a7f03c9043c8a (patch) | |
| tree | 76b67a8ed02152597e81fd2366c0e5e7a83bc2e2 /windows/WinUI/APIHandler.cs | |
| parent | 6471c1f4e26c0230b40bf0102a52493aa78236b9 (diff) | |
| download | infinitytier-5b6ddaa2d744dfc726829da0893a7f03c9043c8a.tar.gz infinitytier-5b6ddaa2d744dfc726829da0893a7f03c9043c8a.zip | |
Base windows UI is working.
* No joining/leaving networks yet, but they do display.
* Nothing is updated yet after first load of the app. Need to set up a background task to run updates.
Diffstat (limited to 'windows/WinUI/APIHandler.cs')
| -rw-r--r-- | windows/WinUI/APIHandler.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs new file mode 100644 index 00000000..c13bca53 --- /dev/null +++ b/windows/WinUI/APIHandler.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net; +using System.IO; +using Newtonsoft.Json; + +namespace WinUI +{ + + + public class APIHandler + { + static string authtoken = "p3ptrzds5jkr2hbx5ipbyf04"; // delete me! + + private string url = null; + + public APIHandler() + { + url = "http://127.0.0.1:9993"; + } + + public APIHandler(string host, int port) + { + url = "http://" + host + ":" + port; + } + + public ZeroTierStatus getStatus() + { + var request = WebRequest.Create(url + "/status" + "?auth=" + authtoken) as HttpWebRequest; + if (request != null) + { + request.Method = "GET"; + request.ContentType = "application/json"; + } + + var httpResponse = (HttpWebResponse)request.GetResponse(); + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + + ZeroTierStatus status = JsonConvert.DeserializeObject<ZeroTierStatus>(responseText); + return status; + } + } + + public List<ZeroTierNetwork> getNetworks() + { + var request = WebRequest.Create(url + "/network" + "?auth=" + authtoken) as HttpWebRequest; + if (request != null) + { + request.Method = "GET"; + request.ContentType = "application/json"; + } + + var httpResponse = (HttpWebResponse)request.GetResponse(); + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + Console.WriteLine(responseText); + + List<ZeroTierNetwork> networkList = JsonConvert.DeserializeObject<List<ZeroTierNetwork>>(responseText); + return networkList; + } + } + } +} |
