Exemplo n.º 1
0
        internal static string GET(string url, Shikimori user, params KeyValuePair <string, string>[] parametrs)
        {
            if (user == null)
            {
                throw new Exception("Shiki api is null");
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.AccessToken);
                httpClient.DefaultRequestHeaders.Add("User-Agent", user.Application.Name);

                if (parametrs.Length <= 0)
                {
                    return(httpClient.GetStringAsync(url).Result);
                }

                var builder = new UriBuilder(url);
                var query   = new StringBuilder();
                foreach (var keyValuePair in parametrs)
                {
                    query.Append(keyValuePair.Key);
                    query.Append("=");
                    query.Append(keyValuePair.Value);
                    query.Append("&");
                }

                query.Remove(query.Length - 1, 1);
                builder.Query = query.ToString();
                url           = builder.ToString();

                return(httpClient.GetStringAsync(url).Result);
            }
        }
Exemplo n.º 2
0
        internal static HttpStatusCode DELETE(string url, Shikimori user = null)
        {
            if (user == null)
            {
                throw new Exception("Shiki api is null");
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.AccessToken);
                httpClient.DefaultRequestHeaders.Add("User-Agent", user.Application.Name);

                var response = httpClient.DeleteAsync(url);
                return(response.Result.StatusCode);
            }
        }
Exemplo n.º 3
0
        internal static T POST <T>(string url, StringContent args, Shikimori user)
        {
            if (user == null)
            {
                throw new Exception("Shiki api is null");
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.AccessToken);
                httpClient.DefaultRequestHeaders.Add("User-Agent", user.Application.Name);

                var response = httpClient.PostAsync(url, args).Result.Content.ReadAsStringAsync().Result;
                var result   = JsonConvert.DeserializeObject <T>(response);
                return(result);
            }
        }
Exemplo n.º 4
0
        public static Anime[] ToAnime(this UserListItem[] array, Shikimori shiki)
        {
            var result = new List <Anime>();
            var pages  = (int)Math.Ceiling((float)array.Length / 50) + 1;
            var ids    = new IdsPicker(array.Select(x => x.TargetId));

            for (int i = 1; i < pages; i++)
            {
                result.AddRange(shiki.GetAnimes(new AnimeListRequest
                {
                    Ids   = ids,
                    Limit = 50,
                    Page  = i
                }));
            }

            return(result.ToArray());
        }
Exemplo n.º 5
0
        internal static T PUT <T>(string url, Shikimori user, params KeyValuePair <string, string>[] parametrs)
        {
            if (user == null)
            {
                throw new Exception("Shiki api is null");
            }

            var content = new StringContent(parametrs.ConvertToJsonString(), Encoding.UTF8, "application/json");

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.AccessToken);
                httpClient.DefaultRequestHeaders.Add("User-Agent", user.Application.Name);

                var response = httpClient.PutAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                var result   = JsonConvert.DeserializeObject <T>(response);
                return(result);
            }
        }
Exemplo n.º 6
0
        internal static T GET <T>(string url, Shikimori user, params KeyValuePair <string, string>[] parametrs)
        {
            if (user == null)
            {
                throw new Exception("Shiki api is null");
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.AccessToken);
                httpClient.DefaultRequestHeaders.Add("User-Agent", user.Application.Name);

                if (parametrs.Length > 0)
                {
                    var builder = new UriBuilder(url);
                    var query   = new StringBuilder();
                    foreach (var keyValuePair in parametrs)
                    {
                        query.Append(keyValuePair.Key);
                        query.Append("=");
                        query.Append(keyValuePair.Value);
                        query.Append("&");
                    }

                    query.Remove(query.Length - 1, 1);
                    builder.Query = query.ToString();
                    url           = builder.ToString();
                }

                var response = httpClient.GetStringAsync(url).Result;
                var settings = new JsonSerializerSettings()
                {
                    Converters = new[] { new PersonGrouppedRoleConverter(), }
                };
                var result = JsonConvert.DeserializeObject <T>(response, settings);
                return(result);
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <Anime> ToAnime(this IEnumerable <UserListItem> list, Shikimori shiki)
        {
            var result = new List <Anime>();
            var pages  = (int)Math.Ceiling((float)list.Count() / 50) + 1;
            var ids    = new IdsPicker(list.Select(x => x.TargetId));

            for (int i = 1; i < pages; i++)
            {
                result.AddRange(shiki.GetAnimes(new AnimeListRequest
                {
                    Ids   = ids,
                    Limit = 50,
                    Page  = i
                }));
            }

            return(result);
        }
Exemplo n.º 8
0
 internal static T POST <T>(string url, Shikimori user)
 {
     return(POST <T>(url, user, new KeyValuePair <string, string> [0]));
 }
Exemplo n.º 9
0
 public MangaInfo GetFullInfo(Shikimori shiki)
 {
     return(shiki.GetMangaById(Id));
 }
Exemplo n.º 10
0
 public AnimeInfo GetFullInfo(Shikimori shiki)
 {
     return(shiki.GetAnimeById(Id));
 }
        public static IEnumerable <Anime> ToAnime(this IEnumerable <AnimeFranchiseNode> nodes, Shikimori shiki)
        {
            var result = new List <Anime>();
            var pages  = (int)Math.Ceiling((float)nodes.Count() / 50) + 1;
            var ids    = new IdsPicker(nodes.Select(x => x.Id));

            for (var i = 1; i < pages; i++)
            {
                result.AddRange(shiki.GetAnimes(new AnimeListRequest
                {
                    Ids   = ids,
                    Limit = 50,
                    Page  = i
                }));
            }

            return(result);
        }