コード例 #1
0
        public async Task <Person> GetPersonAsync(int personId, string language, PersonMethods extraMethods = PersonMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken))
        {
            RestRequest req = _client.Create("person/{personId}");

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

            if (language != null)
            {
                req.AddParameter("language", language);
            }

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

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

            // TODO: Dateformat?
            //req.DateFormat = "yyyy-MM-dd";

            RestResponse <Person> response = await req.ExecuteGet <Person>(cancellationToken).ConfigureAwait(false);

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

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

            // Patch up data, so that the end user won't notice that we share objects between request-types.
            if (item != null)
            {
                if (item.Images != null)
                {
                    item.Images.Id = item.Id;
                }

                if (item.TvCredits != null)
                {
                    item.TvCredits.Id = item.Id;
                }

                if (item.MovieCredits != null)
                {
                    item.MovieCredits.Id = item.Id;
                }
            }

            return(item);
        }
コード例 #2
0
        public Person GetPerson(int personId, PersonMethods extraMethods = PersonMethods.Undefined)
        {
            RestRequest req = new RestRequest("person/{personId}");

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

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(PersonMethods))
                                         .OfType <PersonMethods>()
                                         .Except(new[] { PersonMethods.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 <Person> resp = _client.Get <Person>(req);

            // Patch up data, so that the end user won't notice that we share objects between request-types.
            if (resp.Data != null)
            {
                if (resp.Data.Images != null)
                {
                    resp.Data.Images.Id = resp.Data.Id;
                }

                if (resp.Data.Credits != null)
                {
                    resp.Data.Credits.Id = resp.Data.Id;
                }
            }

            return(resp.Data);
        }