示例#1
0
        private T GetPersonMethod <T>(int personId, PersonMethods personMethod, string dateFormat = null, string country = null, string language = null,
                                      int page = 0, DateTime?startDate = null, DateTime?endDate = null) where T : new()
        {
            RestRequest req = new RestRequest("person/{personId}/{method}");

            req.AddUrlSegment("personId", personId.ToString());
            req.AddUrlSegment("method", personMethod.GetDescription());

            if (dateFormat != null)
            {
                req.DateFormat = dateFormat;
            }

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

            if (page >= 1)
            {
                req.AddParameter("page", page);
            }
            if (startDate.HasValue)
            {
                req.AddParameter("startDate", startDate.Value.ToString("yyyy-MM-dd"));
            }
            if (endDate != null)
            {
                req.AddParameter("endDate", endDate.Value.ToString("yyyy-MM-dd"));
            }

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

            return(resp.Data);
        }
示例#2
0
        private async Task <T> GetPersonMethodInternal <T>(int personId, PersonMethods personMethod, string dateFormat = null, string country = null, string language = null,
                                                           int page = 0, DateTime?startDate = null, DateTime?endDate = null, CancellationToken cancellationToken = default) where T : new()
        {
            RestRequest req = _client.Create("person/{personId}/{method}");

            req.AddUrlSegment("personId", personId.ToString());
            req.AddUrlSegment("method", personMethod.GetDescription());

            // TODO: Dateformat?
            //if (dateFormat != null)
            //    req.DateFormat = dateFormat;

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

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

            if (page >= 1)
            {
                req.AddParameter("page", page.ToString());
            }
            if (startDate.HasValue)
            {
                req.AddParameter("startDate", startDate.Value.ToString("yyyy-MM-dd"));
            }
            if (endDate != null)
            {
                req.AddParameter("endDate", endDate.Value.ToString("yyyy-MM-dd"));
            }

            T resp = await req.GetOfT <T>(cancellationToken).ConfigureAwait(false);

            return(resp);
        }