/// <summary> /// Deletes the profile /// </summary> /// <param name="id"></param> /// <param name="token"></param> /// <returns></returns> public static async Task DeleteProfileAsync(ApiProfile profile) { using (var client = new HttpClient()) { // Authorize the request. await AuthorizeRequest(client); // Send request and get a response var response = await client.DeleteAsync(GetUrl($"api/profiles/{profile.Id}")); // Deserialize the object based on the result if (!response.IsSuccessStatusCode) { throw await CreateException(response); } } }
/// <summary> /// Creates a new profile /// </summary> /// <param name="profile"></param> /// <param name="passphrase"></param> /// <returns></returns> public static async Task<ApiProfile> CreateProfileAsync(CreateProfileRequest profile) { using (var client = new HttpClient()) { // Authorize the request. await AuthorizeRequest(client); // Create JSON content. var content = JsonContent(profile); // Send request and get a response var response = await client.PostAsync(GetUrl($"api/profiles"), content); // Deserialize the object based on the result if (response.IsSuccessStatusCode) { // Read the data var data = await response.Content.ReadAsStringAsync(); // Create an ApiProfile object var p = new ApiProfile() { Name = profile.Name, Id = Convert.ToInt32(data) }; // Return the profile object return p; } else { throw await CreateException(response); } } }
/// <summary> /// Creates a new profile /// </summary> /// <param name="profile"></param> /// <param name="passphrase"></param> /// <returns></returns> public static async Task<SuccessResponse> SaveProfileAsync(ApiProfile profile) { using (var client = new HttpClient()) { // Authorize the request. await AuthorizeRequest(client); // Create JSON content. var content = JsonContent(profile); // Send request and get a response var response = await client.PutAsync(GetUrl($"api/profiles/{profile.Id}"), content); // Deserialize the object based on the result if (response.IsSuccessStatusCode) { // Read the data var data = await response.Content.ReadAsStringAsync(); // Deserialize the response as an ApiResponse object return new SuccessResponse(Convert.ToInt32(data)); } else { throw await CreateException(response); } } }
/// <summary> /// Gets a specific profile for the authenticated user /// </summary> /// <param name="profile"></param> /// <param name="passphrase"></param> /// <returns></returns> public static async Task LoadProfileAsync(ApiProfile profile, string passphrase) { using (var client = new HttpClient()) { //authorize the request await AuthorizeRequest(client); // Add passphrase to message AddPassphraseHeader(client, passphrase); //send request and get a response var response = await client.GetAsync(GetUrl($"api/profiles/{profile.Id}")); //deserialize the object based on the result if (response.IsSuccessStatusCode) { //read the data var data = await response.Content.ReadAsStringAsync(); // Deserialize the response as an ApiResponse object var profileResp = JsonConvert.DeserializeObject<ProfileResponse>(data); // Set current profile and passphrase if (profileResp != null && profileResp.Profiles.Length > 0) { CurrentProfile = profileResp.Profiles.SingleOrDefault(); Passphrase = passphrase; } } else { throw await CreateException(response); } } }