Example #1
0
        /// <summary>
        /// Push update/add details to MAL
        /// </summary>
        /// <param name="details">Update details</param>
        /// <param name="username">Username for authentication</param>
        /// <param name="password">Password for authentication</param>
        /// <param name="isupdate">Indicate if this is an update or an add</param>
        /// <returns>True - Update succeeded, otherwise false</returns>
        private async Task <DataPushResponseWrapper> UpdateAnimeDetails(AnimeUpdate details, string username, string password,
                                                                        bool isupdate = false)
        {
            try
            {
                var url = isupdate
                    ? MalRouteBuilder.UpdateAnime(details.AnimeId)
                    : MalRouteBuilder.AddAnime(details.AnimeId);
                var client = _httpClientFactory.GetHttpClient(username, password);
                var result = await client.PostAsync(url, new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("data", _xmlHelper.SerializeData(details))
                }));

                return(new DataPushResponseWrapper(result.StatusCode, result.IsSuccessStatusCode));
            }
            catch (Exception exception)
            {
                return(new DataPushResponseWrapper(exception));
            }
        }