private async Task Run()
        {
            // Create the service.
            var service = new PagespeedonlineService(new BaseClientService.Initializer()
            {
                ApiKey          = GetApiKey(),
                ApplicationName = "PageSpeedOnline API Sample",
            });

            string url = "http://example.com";

            Console.Write("Enter a URL to search [{0}]: ", url);
            var input = Console.ReadLine();

            if (!string.IsNullOrEmpty(input))
            {
                url = input;
            }

            Console.WriteLine();

            // Run the request.
            Console.WriteLine("Measuring page score ...");
            var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();

            // Display the results.
            Console.WriteLine("Page score: " + result.Score);
        }
        /// <summary>
        /// Runs PageSpeed analysis on the page at the specified URL, and returns a PageSpeed score, a list of suggestions to make that page faster, and other information.
        /// Documentation https://developers.google.com/pagespeedonline/v1/reference/pagespeedapi/runpagespeed
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Pagespeedonline service.</param>
        /// <param name="url">The URL to fetch and analyze</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ResultResponse</returns>
        public static Result Runpagespeed(PagespeedonlineService service, string url, PagespeedapiRunpagespeedOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (url == null)
                {
                    throw new ArgumentNullException(url);
                }

                // Building the initial request.
                var request = service.Pagespeedapi.Runpagespeed(url);

                // Applying optional parameters to the request.
                request = (PagespeedapiResource.RunpagespeedRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Pagespeedapi.Runpagespeed failed.", ex);
            }
        }
        private async Task Run()
        {
            // Create the service.
            var service = new PagespeedonlineService(new BaseClientService.Initializer()
                {
                    ApiKey = GetApiKey(),
                    ApplicationName = "PageSpeedOnline API Sample",
                });

            string url = "http://example.com";
            Console.Write("Enter a URL to search [{0}]: ", url);
            var input = Console.ReadLine();
            if (!string.IsNullOrEmpty(input))
            {
                url = input;
            }

            Console.WriteLine();

            // Run the request.
            Console.WriteLine("Measuring page score ...");
            var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();

            // Display the results.
            Console.WriteLine("Page score: " + result.Score);
        }
Exemplo n.º 4
0
        public void ExecutePerformanceTest(IReadOnlyCollection <Sitemap> sitemaps)
        {
            _logger.Debug("Starting the Google Page Speed performance test for {sitemapsCount} sitemap(s).",
                          sitemaps.Count);

            var service = new PagespeedonlineService(new BaseClientService.Initializer
            {
                ApiKey          = _apiKey,
                ApplicationName = _applicationName
            });

            foreach (var sitemap in sitemaps)
            {
                ExecutePerformanceTestForSitemap(sitemap);
            }

            _logger.Debug("Finished the Google Page Speed performance test for {sitemapsCount} sitemap(s).",
                          sitemaps.Count);

            void ExecutePerformanceTestForSitemap(Sitemap sitemap)
            {
                foreach (var page in sitemap.Pages)
                {
                    _logger.Information("Executing the page speed test for {pageUrl}.", page.ToString());

                    var result = service.Pagespeedapi.Runpagespeed(page.ToString()).Execute();

                    _logger.Information("The page result was {score}.", result.Score);
                    _logger.Information("The page report was {@report}", result.FormattedResults);
                }
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Page Speed Online API");

            // Create the service.

            var service = new PagespeedonlineService() { Key = GetApiKey() };
            RunSample(service);
            CommandLine.PressAnyKeyToExit();
        }
Exemplo n.º 6
0
        private static void RunSample(PagespeedonlineService service)
        {
            string url = "http://example.com";
            CommandLine.RequestUserInput("URL to test", ref url);
            CommandLine.WriteLine();

            // Run the request.
            CommandLine.WriteAction("Measuring page score ...");
            var result = service.Pagespeedapi.Runpagespeed(url).Fetch(); 
            
            // Display the results.
            CommandLine.WriteResult("Page score", result.Score);
        }
Exemplo n.º 7
0
        private static void RunSample(PagespeedonlineService service)
        {
            string url = "http://example.com";

            CommandLine.RequestUserInput("URL to test", ref url);
            CommandLine.WriteLine();

            // Run the request.
            CommandLine.WriteAction("Measuring page score ...");
            var result = service.Pagespeedapi.Runpagespeed(url).Fetch();

            // Display the results.
            CommandLine.WriteResult("Page score", result.Score);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            // Display the header and initialize the sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Page Speed Online API");

            // Create the service.

            var service = new PagespeedonlineService()
            {
                Key = GetApiKey()
            };

            RunSample(service);
            CommandLine.PressAnyKeyToExit();
        }