public async Task <bool> create_notification(Notification note) { try { string endp = $"{api_endp}/notifications"; var header = new Dictionary <string, string>() { { "Authorization", $"Token {token}" } }; var json = new JavaScriptSerializer().Serialize(note); string resp = await WRequest.post_response(endp, json, header); return(true); } catch (Exception ex) { MainApp.log_error("Creating notification failed. " + ex.Message); } return(false); }
// login using the credential given by the setting file // return: true on success false on failure public async Task <bool> login() { try { string endp = $"{api_endp}/auth"; string data = "{" + $"\"username\":\"{MainApp.g_setting.api_credential.user}\"," + $"\"password\":\"{MainApp.g_setting.api_credential.pwd}\"" + "}"; string resp = await WRequest.post_response(endp, data); var json = JObject.Parse(resp); token = json["token"].ToString(); return(true); } catch (Exception ex) { MainApp.log_error("Login failed." + ex.Message); } return(false); }