예제 #1
0
        /// <summary>
        /// Updates a user's manga list entry.
        /// </summary>
        /// <param name="mangaId">ID of the manga</param>
        /// <param name="updateInfo">The updated information</param>
        /// <param name="cancellationToken"></param>
        /// <param name="user">MAL user</param>
        /// <param name="password">MAL password</param>
        /// <returns></returns>
        public async Task <string> UpdateMangaForUserAsync(int mangaId, MangaUpdate updateInfo, string user, string password, CancellationToken cancellationToken)
        {
            const string malMangaUpdateUriFormatString = "https://myanimelist.net/api/mangalist/update/{0}.xml";

            string userInfoUri = string.Format(malMangaUpdateUriFormatString, Uri.EscapeDataString(mangaId.ToString()));

            Logging.Log.InfoFormat("Updating manga entry for MAL manga ID {0}, user {1} using URI {2}", mangaId, user, userInfoUri);

            Func <string, string> responseProcessingFunc = (response) =>
            {
                return(response);
            };

            try
            {
                HttpRequestMessage request = InitNewRequestWithCredentials(userInfoUri, HttpMethod.Post, user, password);

                // Encoding and adding the new information in the content(body) of the request
                string xml = updateInfo.GenerateXml();
                request.Content = new FormUrlEncodedContent(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("data", xml) });

                string result = await ProcessRequestAsync(request, responseProcessingFunc, cancellationToken : cancellationToken,
                                                          baseErrorMessage : string.Format("Failed updating manga entry for manga ID {0}, user {1} using url {2}", mangaId, user, userInfoUri)).ConfigureAwait(continueOnCapturedContext: false);

                Logging.Log.InfoFormat("Successfully updated manga entry for manga ID {0} and user {1}", mangaId, user);

                return(result);
            }
            catch (OperationCanceledException)
            {
                Logging.Log.InfoFormat("Canceled updating manga entry for MAL manga ID {0} and user {1}", mangaId, user);
                throw;
            }
        }
예제 #2
0
 /// <summary>
 /// Updates a user's manga entry. Required username and password or a base64 encrypted username and password.
 /// </summary>
 /// <param name="mangaId">ID of the updated manga</param>
 /// <param name="xml">Required data to update the manga</param>
 /// <param name="user">Username</param>
 /// <param name="password">Password</param>
 /// <param name="base64Credentials">base64 encrypted username and password</param>
 /// <returns></returns>
 public string UpdateMangaForUser(int mangaId, MangaUpdate updateInfo, string user, string password)
 {
     return(UpdateMangaForUserAsync(mangaId, updateInfo, user, password).ConfigureAwait(continueOnCapturedContext: false).GetAwaiter().GetResult());
 }
예제 #3
0
 /// <summary>
 /// Updates a user's manga list entry.
 /// </summary>
 /// <param name="animeId">ID of the manga</param>
 /// <param name="updateInfo">The updated information</param>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public Task <string> UpdateMangaForUserAsync(int mangaId, MangaUpdate updateInfo, string user, string password)
 {
     return(UpdateMangaForUserAsync(mangaId, updateInfo, user, password, CancellationToken.None));
 }