Ejemplo n.º 1
0
        public Collection GetCollection(int collectionId, string language, CollectionMethods extraMethods = CollectionMethods.Undefined)
        {
            RestRequest req = new RestRequest("collection/{collectionId}");

            req.AddUrlSegment("collectionId", collectionId.ToString());

            language = language ?? DefaultLanguage;
            if (!String.IsNullOrWhiteSpace(language))
            {
                req.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(CollectionMethods))
                                         .OfType <CollectionMethods>()
                                         .Except(new[] { CollectionMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                req.AddParameter("append_to_response", appends);
            }

            req.DateFormat = "yyyy-MM-dd";

            IRestResponse <Collection> resp = _client.Get <Collection>(req);

            return(resp.Data);
        }
Ejemplo n.º 2
0
        public async Task <Collection> GetCollectionAsync(int collectionId, string language, string includeImageLanguages, CollectionMethods extraMethods = CollectionMethods.Undefined, CancellationToken cancellationToken = default)
        {
            RestRequest req = _client.Create("collection/{collectionId}");

            req.AddUrlSegment("collectionId", collectionId.ToString());

            language ??= DefaultLanguage;
            if (!string.IsNullOrWhiteSpace(language))
            {
                req.AddParameter("language", language);
            }

            includeImageLanguages ??= DefaultImageLanguage;
            if (!string.IsNullOrWhiteSpace(includeImageLanguages))
            {
                req.AddParameter("include_image_language", includeImageLanguages);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(CollectionMethods))
                                         .OfType <CollectionMethods>()
                                         .Except(new[] { CollectionMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                req.AddParameter("append_to_response", appends);
            }

            //req.DateFormat = "yyyy-MM-dd";

            RestResponse <Collection> response = await req.Get <Collection>(cancellationToken).ConfigureAwait(false);

            if (!response.IsValid)
            {
                return(null);
            }

            Collection item = await response.GetDataObject().ConfigureAwait(false);

            if (item != null)
            {
                item.Overview = WebUtility.HtmlDecode(item.Overview);
            }

            return(item);
        }