コード例 #1
0
ファイル: MyAnimeListApi.cs プロジェクト: naps250/mal-api
        /// <summary>
        /// Updates a user's anime list entry.
        /// </summary>
        /// <param name="animeId">ID of the anime</param>
        /// <param name="updateInfo">The updated information</param>
        /// <param name="cancellationToken"></param>
        /// <param name="user">MAL username</param>
        /// <param name="password">MAL password</param>
        /// <returns></returns>
        public async Task <string> UpdateAnimeForUserAsync(int animeId, AnimeUpdate updateInfo, string user, string password, CancellationToken cancellationToken)
        {
            const string malAnimeUpdateUriFormatString = "https://myanimelist.net/api/animelist/update/{0}.xml";

            string userInfoUri = string.Format(malAnimeUpdateUriFormatString, Uri.EscapeDataString(animeId.ToString()));

            Logging.Log.InfoFormat("Updating anime entry for MAL anime ID {0}, user {1} using URI {2}", animeId, 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 anime entry for anime ID {0}, user {1} using url {2}", animeId, user, userInfoUri)).ConfigureAwait(continueOnCapturedContext: false);

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

                return(result);
            }
            catch (OperationCanceledException)
            {
                Logging.Log.InfoFormat("Canceled updating anime entry for MAL anime ID {0} and user {1}", animeId, user);
                throw;
            }
        }
コード例 #2
0
ファイル: MyAnimeListApi.cs プロジェクト: naps250/mal-api
 /// <summary>
 /// Updates a user's anime entry. Required username and password or a base64 encrypted username and password.
 /// </summary>
 /// <param name="animeId">ID of the updated anime</param>
 /// <param name="xml">Required data to update the anime</param>
 /// <param name="user">Username</param>
 /// <param name="password">Password</param>
 /// <param name="base64Credentials">base64 encrypted username and password</param>
 /// <returns></returns>
 public string UpdateAnimeForUser(int animeId, AnimeUpdate updateInfo, string user, string password)
 {
     return(UpdateAnimeForUserAsync(animeId, updateInfo, user, password).ConfigureAwait(continueOnCapturedContext: false).GetAwaiter().GetResult());
 }
コード例 #3
0
ファイル: MyAnimeListApi.cs プロジェクト: naps250/mal-api
 /// <summary>
 /// Updates a user's anime list entry.
 /// </summary>
 /// <param name="animeId">ID of the anime</param>
 /// <param name="updateInfo">The updated information</param>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public Task <string> UpdateAnimeForUserAsync(int animeId, AnimeUpdate updateInfo, string user, string password)
 {
     return(UpdateAnimeForUserAsync(animeId, updateInfo, user, password, CancellationToken.None));
 }