public async Task <ImgurCreateAlbum> CreateAlbumAnonymous(IEnumerable <string> imageIds, string title, string description, ImgurAlbumPrivacy privacy, ImgurAlbumLayout layout, string coverImageId) { using (HttpClient client = new HttpClient()) { SetHeaders(client); var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("deletehashes", imageIds.Aggregate((a, b) => a + "," + b)), }); HttpResponseMessage response = await client.PostAsync(new Uri(BaseUrl + "album"), formContent); string content = await response.Content.ReadAsStringAsync(); ImgurRootObject <ImgurCreateAlbum> createRoot = JsonConvert.DeserializeObject <ImgurRootObject <ImgurCreateAlbum> >(content); return(createRoot.Data); } }
/// <summary> /// Updates ImgurAlbum /// </summary> /// <param name="deleteHash">DeleteHash, obtained at creation</param> /// <param name="imageIds">List images in the album</param> /// <param name="title">New title</param> /// <param name="description">New description</param> /// <param name="privacy">New privacy level, use NONE for standard</param> /// <param name="layout">New layout, use NONE for standard</param> /// <param name="cover">new coverImage, imageId</param> /// <returns>bool of result</returns> public async Task <bool> UpdateAlbumAnonymous(string deleteHash, IEnumerable <string> imageIds, string title, string description, ImgurAlbumPrivacy privacy, ImgurAlbumLayout layout, string cover) { using (HttpClient client = new HttpClient()) { SetHeaders(client); var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("ids", imageIds.Aggregate((a, b) => a + "," + b)), new KeyValuePair <string, string>("title", title), new KeyValuePair <string, string>("description", description), new KeyValuePair <string, string>("privacy", GetNameFromEnum <ImgurAlbumPrivacy>((int)privacy)), new KeyValuePair <string, string>("layout", GetNameFromEnum <ImgurAlbumLayout>((int)layout)), new KeyValuePair <string, string>("cover", cover), }); HttpResponseMessage response = await client.PutAsync(new Uri(baseUrl + "album/" + deleteHash), formContent); await CheckHttpStatusCode(response); string content = await response.Content.ReadAsStringAsync(); ImgurRootObject <bool> updateRoot = JsonConvert.DeserializeObject <ImgurRootObject <bool> >(content); return(updateRoot.Data); } }
/// <summary> /// Creates an Album on Imgur /// </summary> /// <param name="imageIds">List of string, ImageIds</param> /// <param name="title">Title of album</param> /// <param name="description">Description of album</param> /// <param name="privacy">Privacy level, use NONE for standard</param> /// <param name="layout">Layout, use NONE for standard</param> /// <param name="coverImageId">Cover image of album, imageId. Should be in the album</param> /// <param name="token">Token account</param> /// <returns>ImgurCreateAlbum which contains deletehash and link</returns> public async Task <ImgurCreateAlbum> CreateAlbum(IEnumerable <string> imageIds, string title, string description, ImgurAlbumPrivacy privacy, ImgurAlbumLayout layout, string coverImageId, ImgurToken token = null) { using (HttpClient client = new HttpClient()) { SetHeader(client, token); var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("ids", imageIds.Aggregate((a, b) => a + "," + b)), new KeyValuePair <string, string>("title", title), new KeyValuePair <string, string>("description", description), new KeyValuePair <string, string>("privacy", GetNameFromEnum <ImgurAlbumPrivacy>((int)privacy)), new KeyValuePair <string, string>("layout", GetNameFromEnum <ImgurAlbumLayout>((int)layout)), new KeyValuePair <string, string>("cover", coverImageId), }); HttpResponseMessage response = await client.PostAsync(new Uri(BaseUrl + "album"), formContent); await CheckHttpStatusCode(response); string content = await response.Content.ReadAsStringAsync(); ImgurRootObject <ImgurCreateAlbum> createRoot = JsonConvert.DeserializeObject <ImgurRootObject <ImgurCreateAlbum> >(content); return(createRoot.Data); } }