private static string FromListStatus(ApiEntry.ListStatuses status) { // ReSharper disable once SwitchStatementMissingSomeCases switch (status) { case ApiEntry.ListStatuses.Completed: return("completed"); case ApiEntry.ListStatuses.Current: return("current"); case ApiEntry.ListStatuses.Dropped: return("dropped"); case ApiEntry.ListStatuses.Planned: return("planned"); case ApiEntry.ListStatuses.OnHold: return("on_hold"); // NotInList - this should never be sent to the server default: Debug.Fail($"Invalid list status '{status}'"); throw new ArgumentOutOfRangeException(nameof(status), status, null); } }
/// <summary> /// Add a manga to the authenticated user's list. /// </summary> /// <param name="id">The MAL ID of the given manga.</param> /// <param name="listStatus">The list status of the manga (default is currently reading).</param> /// <returns>true on success</returns> /// <exception cref="ApiFormatException">if the request times out.</exception> /// <exception cref="WebException">if a connection cannot be established.</exception> public async Task <bool> AddManga(int id, ApiEntry.ListStatuses listStatus = ApiEntry.ListStatuses.Current) { var data = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("data", "<?xml version =\"1.0\" encoding=\"UTF-8\"?>" + "<entry>" + "<chapter>0</chapter>" + "<volume>0</volume>" + "<status>" + (int)listStatus + "</status>" + "</entry>") }); var response = await _client.PostAsync(Path.Combine(UrlBase, "mangalist", "add", id + ".xml"), data); if (response.StatusCode == HttpStatusCode.RequestTimeout) { throw new ApiRequestException("The request timed out."); } return(response.StatusCode == HttpStatusCode.Created); }
/// <summary> /// Add an anime to the anime list /// </summary> /// <param name="id">The AniList media ID</param> /// <param name="listStatus">The list status of the anime</param> /// <returns>True on success</returns> public async Task <bool> AddAnime(int id, ApiEntry.ListStatuses listStatus) { const string q = @" { mutation($id: Int, $status: MediaListStatus) { SaveMediaListEntry (mediaId: $id, status: $status) { mediaId } } " ; var v = new JsonObject() { ["id"] = id, ["status"] = FromListStatus(listStatus) }; var json = await SendRequest(q, v); return(id == json?["data"]?["SaveMediaListEntry"]["mediaId"]); }
public async Task <bool> AddManga(int id, ApiEntry.ListStatuses status) { await AuthenticationCheck(); var data = new JsonObject() { ["data"] = new JsonObject { ["type"] = "libraryEntries", ["attributes"] = new JsonObject() { ["status"] = FromListStatus(status) }, ["relationships"] = new JsonObject() { ["user"] = new JsonObject() { ["data"] = new JsonObject() { ["id"] = _userId, ["type"] = "users" } } }, ["media"] = new JsonObject() { ["data"] = new JsonObject() { ["type"] = "manga", ["id"] = id } } } }; var response = await _client.SendAsync(new HttpRequestMessage(HttpMethod.Post, LibraryEntries) { Content = new StringContent(data.ToString(), Encoding.UTF8, ContentType), }); Debug.WriteLineIf(!response.IsSuccessStatusCode, await response.Content.ReadAsStringAsync(), "Kitsu WARNING"); return(response.StatusCode == HttpStatusCode.Created); }
/// <summary> /// Add an anime to the authenticated user's list. /// </summary> /// <param name="id">The MAL ID number of the given anime</param> /// <param name="listStatus">The listStatus to add it under (default is Currently Watching)</param> /// <returns>true on success (201), false on failure (400).</returns> /// <exception cref="ArgumentException">If the anime list status is set to be "not in list".</exception> /// <exception cref="ApiFormatException">if the request times out.</exception> /// <exception cref="WebException">if a connection cannot be established.</exception> public async Task <bool> AddAnime(int id, ApiEntry.ListStatuses listStatus = ApiEntry.ListStatuses.Current) { if (listStatus == ApiEntry.ListStatuses.NotInList) { throw new ArgumentException("Cannot add a list item that is set to not be in the list"); } var data = new FormUrlEncodedContent(new [] { new KeyValuePair <string, string>("data", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<entry>" + "<episode>0</episode>" + "<status>" + (int)listStatus + "</status>" + "</entry>") }); var response = await _client.PostAsync(Path.Combine(UrlBase, "animelist", "add", id + ".xml"), data); if (response.StatusCode == HttpStatusCode.RequestTimeout) { throw new ApiRequestException("The request timed out."); } return(response.StatusCode == HttpStatusCode.Created); }
private static string FromListStatus(ApiEntry.ListStatuses status) { switch (status) { case ApiEntry.ListStatuses.Current: return("CURRENT"); case ApiEntry.ListStatuses.Planned: return("PLANNING"); case ApiEntry.ListStatuses.Completed: return("COMPLETED"); case ApiEntry.ListStatuses.Dropped: return("DROPPED"); case ApiEntry.ListStatuses.OnHold: return("PAUSED"); default: Debug.WriteLine("Invalid list status encountered: NotInList!", "AniList ListStatus WARNING"); throw new InvalidEnumArgumentException(nameof(status), (int)status, typeof(ApiEntry.ListStatuses)); } }
/// <summary> /// Get specific list (watching, planned, etc.) /// </summary> public List <Manga> this[ApiEntry.ListStatuses i] { get { return(_entries.Where(x => x.ListStatus == i).ToList()); } }
/// <summary> /// Add a manga to the list. /// </summary> /// <param name="id">The AniList media ID</param> /// <param name="listStatus">The manga list status</param> /// <returns>True on success</returns> public async Task <bool> AddManga(int id, ApiEntry.ListStatuses listStatus) { return(await AddAnime(id, listStatus)); // Exact same request, anime and manga ids are unique! }