public List <SniperInfo> FindAll()
 {
     try
     {
         var userAgent = UserAgentHelper.GetRandomUseragent();
         var content   = getContent(userAgent);
         return(GetJsonList(content));
     }
     catch (Exception e)
     {
         return(FallbackFindAll());
     }
 }
        private static ScanResult QuerySkipLagged(double boundLowerLeftLat, double boundLowerLeftLng, double boundUpperRightLat, double boundUpperRightLng)
        {
            var uri =
                $"http://skiplagged.com/api/pokemon.php?bounds={boundLowerLeftLat.ToString(CultureInfo.InvariantCulture)},{boundLowerLeftLng.ToString(CultureInfo.InvariantCulture)},{boundUpperRightLat.ToString(CultureInfo.InvariantCulture)},{boundUpperRightLng.ToString(CultureInfo.InvariantCulture)}";

            ScanResult scanResult;

            try
            {
                var request = WebRequest.CreateHttp(uri);
                request.UserAgent        = UserAgentHelper.GetRandomUseragent();
                request.Accept           = "application/json";
                request.Method           = "GET";
                request.Timeout          = 15000;
                request.ReadWriteTimeout = 32000;
                request.CookieContainer  = new CookieContainer();

                using (var resp = request.GetResponse())
                {
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        var fullresp =
                            reader.ReadToEnd()
                            .Replace(" M", "Male")
                            .Replace(" F", "Female")
                            .Replace("Farfetch'd", "Farfetchd")
                            .Replace("Mr.Maleime", "MrMime");
                        scanResult = JsonConvert.DeserializeObject <ScanResult>(fullresp);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Error querying skiplagged", ex);
                scanResult = new ScanResult
                {
                    Status   = "fail",
                    pokemons = new List <PokemonLocation>()
                };
            }
            return(scanResult);
        }
 public List <SniperInfo> FallbackFindAll()
 {
     try
     {
         var userAgent = UserAgentHelper.GetRandomUseragent();
         var content   = getContent(userAgent);
         var cookie    = CreateCookie(content);
         if (cookie != null)
         {
             content = getContent(userAgent, cookie);
             return(GetJsonList(content));
         }
         else
         {
             Log.Debug("Could find a cookie for PokeWatchers");
         }
     }
     catch (Exception e)
     {
         Log.Debug("Pokewatchers API error: {0}", e.Message);
     }
     return(null);
 }
        private static ScanResult ScanLocation(GeoCoordinates location)
        {
            var formatter = new NumberFormatInfo {
                NumberDecimalSeparator = "."
            };

            var offset = 0.003;

            // 0.003 = half a mile; maximum 0.06 is 10 miles
            if (offset < 0.001)
            {
                offset = 0.003;
            }
            if (offset > 0.06)
            {
                offset = 0.06;
            }

            var boundLowerLeftLat  = location.Latitude - offset;
            var boundLowerLeftLng  = location.Longitude - offset;
            var boundUpperRightLat = location.Latitude + offset;
            var boundUpperRightLng = location.Longitude + offset;

            var uri =
                $"http://skiplagged.com/api/pokemon.php?bounds={boundLowerLeftLat.ToString(formatter)},{boundLowerLeftLng.ToString(formatter)},{boundUpperRightLat.ToString(formatter)},{boundUpperRightLng.ToString(formatter)}";

            ScanResult scanResult;

            try
            {
                var request = WebRequest.CreateHttp(uri);
                request.UserAgent        = UserAgentHelper.GetRandomUseragent();
                request.Accept           = "application/json";
                request.Method           = "GET";
                request.Timeout          = 15000;
                request.ReadWriteTimeout = 32000;

                using (var resp = request.GetResponse())
                {
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        var fullresp =
                            reader.ReadToEnd()
                            .Replace(" M", "Male")
                            .Replace(" F", "Female")
                            .Replace("Farfetch'd", "Farfetchd")
                            .Replace("Mr.Maleime", "MrMime");
                        scanResult = JsonConvert.DeserializeObject <ScanResult>(fullresp);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Error querying skiplagged", ex);
                scanResult = new ScanResult
                {
                    Status   = "fail",
                    pokemons = new List <PokemonLocation>()
                };
            }
            return(scanResult);
        }