diff --git a/CampusAppWP8/CampusAppWP8/Utility/RestApi.cs b/CampusAppWP8/CampusAppWP8/Utility/RestApi.cs index af5bd7f9..49a94bbe 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/RestApi.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/RestApi.cs @@ -1,12 +1,10 @@ - -//----------------------------------------------------------------------- -// +//----------------------------------------------------------------------- +// // Company copyright tag. // // stubbfel -// 03.05.2013 +// 10.06.2013 //----------------------------------------------------------------------using System; - namespace CampusAppWP8.Utility { using System; @@ -16,27 +14,172 @@ namespace CampusAppWP8.Utility using System.Text; using System.Threading.Tasks; + /// + /// Class realize the access of restful RestAPI + /// public class RestApi { #region Members - WebClient client; + + /// + /// the WebClient, which send the requests + /// + private WebClient client; + #endregion #region Constructor + + /// + /// Initializes a new instance of the class. + /// public RestApi() { - client = new WebClient(); + this.client = new WebClient(); } + + /// + /// Initializes a new instance of the class. + /// + /// the url of the RestAPI base address + public RestApi(Uri apiBaseAddress) + { + this.client = new WebClient(); + this.client.BaseAddress = apiBaseAddress.AbsoluteUri; + } + #endregion #region Methods #region public - public void HttpGet(Uri url, Action action) + + /// + /// Method realize the http-get-method resource + /// + /// Url of the resource + /// callback method + public void HttpGet(Uri url, Action action) { - client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(action); - client.DownloadStringAsync(url); + this.client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(action); + this.client.DownloadStringAsync(url); + } + + /// + /// Method realize the http-delete-method + /// + /// + /// is not supported by WebClient + /// + /// Url of the resource + /// callback method + public void HttpDelete(Uri url, Action action) + { + throw new NotSupportedException(); + } + + /// + /// Method realize the http-delete-method + /// + /// + /// is not supported by WebClient + /// + /// Url of the resource + /// callback method + public void HttpHead(Uri url, Action action) + { + throw new NotSupportedException(); + } + + /// + /// Method realize the http-delete-method + /// + /// + /// is not supported by WebClient + /// + /// Url of the resource + /// callback method + public void HttpOptions(Uri url, Action action) + { + throw new NotSupportedException(); + } + + /// + /// Method realize the http-delete-method + /// + /// + /// is not supported by WebClient + /// + /// Url of the resource + /// callback method + public void HttpConnect(Uri url, Action action) + { + throw new NotSupportedException(); + } + + /// + /// Method realize the http-delete-method + /// + /// + /// is not supported by WebClient + /// + /// Url of the resource + /// callback method + public void HttpTrace(Uri url, Action action) + { + throw new NotSupportedException(); + } + + /// + /// Method realize the http-post-method + /// + /// Url of the resource + /// callback method + /// Data which are sending via post to the RestAPI + public void HttpPost(Uri url, Action action, string postData) + { + this.UploadData(url, action, "POST", postData); + } + + /// + /// Method realize the http-get-method + /// + /// Url of the resource + /// callback method + /// Data which are sending via put to the RestAPI + public void HttpPut(Uri url, Action action, string putData) + { + this.UploadData(url, action, "PUT", putData); + } + + /// + /// Method realize the http-get-method + /// + /// Url of the resource + /// callback method + /// Data which are sending via patch to the RestAPI + public void HttpPatch(Uri url, Action action, string patchData) + { + this.UploadData(url, action, "PATCH", patchData); + } + + #endregion + + #region private + + /// + /// Method uploaded Data to the RestAPI + /// + /// Url of the resource + /// callback method + /// name of APIMethod, how the data will be uploaded + /// Data which are sending to the RestAPI + private void UploadData(Uri url, Action action, string method, string data) + { + this.client.UploadStringCompleted += new UploadStringCompletedEventHandler(action); + this.client.UploadStringAsync(url, method, data); } #endregion + #endregion } } diff --git a/CampusAppWP8/CampusAppWP8/utility/Feed.cs b/CampusAppWP8/CampusAppWP8/utility/Feed.cs index 3a69c342..456ad521 100644 --- a/CampusAppWP8/CampusAppWP8/utility/Feed.cs +++ b/CampusAppWP8/CampusAppWP8/utility/Feed.cs @@ -119,8 +119,6 @@ namespace CampusAppWP8.Utility /// public void LoadFeed() { - this.DownloadFeed(); - return; if (this.IsModelUpToDate()) { return;