示例#1
0
        private IDictionary <long, Genre> ListGenres()
        {
            var client = new RestSharp.RestClient("https://api.themoviedb.org/3");

            IDictionary <long, Genre> dict = new Dictionary <long, Genre>();
            // client.Authenticator = new HttpBasicAuthenticator(username, password);
            var request = new RestSharp.RestRequest("genre/tv/list");

            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            request.AddHeader("Accept", "application/json");
            request.AddParameter("api_key", "ad332258020257fb88e2cc468225dcb0");
            request.JsonSerializer = new NewtonsoftJsonSerializer();

            var response = client.ExecuteAsGet <GenreResponse>(request, "GET");

            response.Data.Genres.ForEach((Genre obj) => dict.Add(obj.Id, obj));
            request = new RestSharp.RestRequest("genre/movie/list");
            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            request.AddHeader("Accept", "application/json");
            request.AddParameter("api_key", "ad332258020257fb88e2cc468225dcb0");
            request.JsonSerializer = new NewtonsoftJsonSerializer();

            response = client.ExecuteAsGet <GenreResponse>(request, "GET");
            response.Data.Genres.ForEach((Genre obj) => {
                if (!dict.ContainsKey(obj.Id))
                {
                    dict.Add(obj.Id, obj);
                }
            });
            return(dict);
        }
        public IList <Objects> GetObjects(int page, int pageSize)
        {
            logger.LogInformation($"Get objects request");
            var request = new RestSharp.RestRequest("objects");

            request.AddQueryParameter("page", page.ToString());
            request.AddQueryParameter("pageSize", pageSize.ToString());
            var result = restClient.ExecuteAsGet <List <Objects> >(request, "GET");

            return(result.Data);
        }
示例#3
0
        PagedResult <TVShow> ITVShowsStore.ListPopular(int page)
        {
            var client = new RestSharp.RestClient("https://api.themoviedb.org/3");

            // client.Authenticator = new HttpBasicAuthenticator(username, password);
            var request = new RestSharp.RestRequest("tv/popular");

            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            request.AddHeader("Accept", "application/json");
            request.AddParameter("api_key", "ad332258020257fb88e2cc468225dcb0");
            request.AddParameter("language", "en");
            request.AddParameter("page", page);
            request.JsonSerializer = new NewtonsoftJsonSerializer();
            var response = client.ExecuteAsGet <PagedResult <TVShowResponse> >(request, "GET");

            return(new PagedResult <TVShow>
            {
                Results = from showResponse in response.Data.Results
                          select new TVShow
                {
                    Id = showResponse.Id,
                    Genres = String.Join(", ", from genreId in showResponse.GenreIds select GetGenreById(genreId).Name),
                    Name = showResponse.Name,
                    Overview = showResponse.Overview,
                    PosterThumb = "https://image.tmdb.org/t/p/w92" + showResponse.PosterPath,
                    PosterImage = "https://image.tmdb.org/t/p/w300" + showResponse.PosterPath,
                    Popularity = showResponse.Popularity,
                    VoteAverage = showResponse.VoteAverage
                },
                TotalPages = response.Data.TotalPages,
                Page = response.Data.Page,
                TotalResults = response.Data.TotalResults
            });
        }
示例#4
0
        public ActionResult ExportExcelWithBackgroundUserList(SearchBackgroundUserListInput input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);
            RestSharp.RestClient  client  = new RestSharp.RestClient();
            RestSharp.RestRequest request = new RestSharp.RestRequest();
            client.BaseUrl = new Uri(GetCurrentUrl(this));

            foreach (var para in ModelHelper.GetPropertyDictionary <SearchBackgroundUserListInput>(input))
            {
                request.AddParameter(para.Key, para.Value.IsNullOrEmpty() ? null : para.Value);
            }

            if (request.Parameters.Count(p => p.Name == DataKey.UserId) == 0)
            {
                request.AddParameter(DataKey.UserId, GetLoginInfo().User.Id.ToString());
            }

            var responseResult = client.ExecuteAsGet(request, "GET");

            if (responseResult.Content == "no data")
            {
                return(Content("<script>alert('没有符合条件的数据可被导出!');history.go(-1)</script>"));
            }
            var contentDispositionHeader = responseResult.Headers.First(p => p.Name == "Content-Disposition").Value.ToString().Replace(" ", string.Empty);
            var attachFileName           = contentDispositionHeader.Replace("attachment;filename=", string.Empty);

            return(File(responseResult.RawBytes, responseResult.ContentType, attachFileName));
        }
示例#5
0
        protected InformationModel LoadWeatherInformation(string airportCode)
        {
            var restClient  = new RestSharp.RestClient("https://api.checkwx.com");
            var restRequest = new RestSharp.RestRequest($"/metar/{airportCode}/decoded");

            restRequest.AddHeader("X-API-Key", "5babb887735bba5bbc7438b455");
            var response = restClient.ExecuteAsGet <InformationModel>(restRequest, "get");

            return(response.Data);
        }
示例#6
0
        /// <summary>
        /// This method gets called right after the recording has been started.
        /// It can be used to execute recording specific initialization code.
        /// </summary>
        private void Practitest()

        {
            RestSharp.RestClient  client  = new RestSharp.RestClient(new Uri("https://eu1-prod-api.practitest.app"));
            RestSharp.RestRequest request = new RestSharp.RestRequest("/api/v2/projects.json", RestSharp.Method.GET);
            request.AddHeader("PTToken", "a076fa47503cc3080423c35a4857663c97260acc");
            RestSharp.IRestResponse response = client.ExecuteAsGet(request, "Get");
            Report.Log(ReportLevel.Info, "Website", "Ramya Test", new RecordItemIndex(0));

            // Your recording specific initialization code goes here.
        }
示例#7
0
        public TVShow GetTVShowDetails(int id)
        {
            var client = new RestSharp.RestClient("https://api.themoviedb.org/3");

            // client.Authenticator = new HttpBasicAuthenticator(username, password);
            var request = new RestSharp.RestRequest("tv/" + id);

            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            request.AddHeader("Accept", "application/json");
            request.AddParameter("api_key", "ad332258020257fb88e2cc468225dcb0");
            request.JsonSerializer = new NewtonsoftJsonSerializer();
            var response = client.ExecuteAsGet <TVShowDetailsResponse>(request, "GET");

            return(new TVShow
            {
                ReleaseDate = DateTime.ParseExact(response.Data.FirstAirDate, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")
            });
        }
示例#8
0
        public ActionResult ExportExcelWithUserList(SearchUserListInputDto input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);
            RestSharp.RestClient  client  = new RestSharp.RestClient();
            RestSharp.RestRequest request = new RestSharp.RestRequest();
            client.BaseUrl = new Uri(GetCurrentUrl(this));
            WhereModel wheremodel;

            wheremodel = new WhereModel()
            {
                RoleId      = Convert.ToInt32(Request["RoleId"].DefaultIfEmpty("0")),
                Province    = Request["Province"].DefaultIfEmpty("0"),
                City        = Request["City"].DefaultIfEmpty("0"),
                Region      = Request["Region"].DefaultIfEmpty("0"),
                PhoneNumber = Request["PhoneNumber"].DefaultIfEmpty(string.Empty),
            };
            Dictionary <string, string> parameters;

            GetSearchParameters(input.pageIndex.Value, input.pageSize.Value, out wheremodel, out parameters);
            foreach (var para in parameters)
            {
                request.AddParameter(para.Key, para.Value.IsNullOrEmpty() ? null : para.Value);
            }

            if (request.Parameters.Count(p => p.Name == DataKey.UserId) == 0)
            {
                request.AddParameter(DataKey.UserId, GetLoginInfo().User.Id.ToString());
            }

            var responseResult = client.ExecuteAsGet(request, "GET");

            if (responseResult.Content == "no data")
            {
                return(Content("<script>alert('没有符合条件的数据可被导出!');history.go(-1)</script>"));
            }
            var contentDispositionHeader = responseResult.Headers.First(p => p.Name == "Content-Disposition").Value.ToString().Replace(" ", string.Empty);
            var attachFileName           = contentDispositionHeader.Replace("attachment;filename=", string.Empty);

            return(File(responseResult.RawBytes, responseResult.ContentType, attachFileName));
        }
示例#9
0
 private void PopulateImageUrls(List <Category> categories)
 {
     Parallel.ForEach(categories, c =>
     {
         try
         {
             var url         = string.Format(GoogleImageSearchUrl, c.Name);
             var restClient  = new RestSharp.RestClient(url);
             var restRequest = new RestSharp.RestRequest(RestSharp.Method.GET);
             var result      = restClient.ExecuteAsGet <GoogleResult>(restRequest, "GET");
             if (result != null &&
                 result.Data != null &&
                 result.Data.Items != null &&
                 result.Data.Items.Count > 0)
             {
                 c.ImageUrl = result.Data.Items[0].Link;
             }
         }
         catch
         {
         }
     });
 }