Example #1
0
        public IActionResult Start()
        {
            List <YelpModel> bars      = GetBars();
            LongAndLat       a         = new LongAndLat();
            decimal          latitude  = a.Latitude;
            decimal          longitude = a.Longitude;

            HttpWebRequest request = WebRequest.CreateHttp($"https://api.yelp.com/v3/businesses/search?term=bars&location=grand rapids&radius=1000&longitude={longitude}&latitude={latitude}");

            request.Headers.Add("Authorization", "Bearer 5AZ1TMhzZzb52DbbAMkydLPjNRSURY3x-DtC2o7qDjNTa2n96PSxuLZMmQoBy3WtX5q4EWUh4KQWVG1GG_nq_x2YLEssXjh5WF5kYw8E_VPmyRVMRfDHLwOYM0bXXXYx");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    rd       = new StreamReader(response.GetResponseStream());
            string          ApiText  = rd.ReadToEnd();
            JToken          tokens   = JToken.Parse(ApiText);

            List <JToken> ts = tokens["businesses"].ToList();

            List <YelpModel> longlat = new List <YelpModel>();

            foreach (JToken t in ts)
            {
                YelpModel b = new YelpModel(t);
                longlat.Add(b);
            }

            return(longlat);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            if (!req.Query.ContainsKey("IP"))
            {
                return((ActionResult) new OkObjectResult("{Error: IP param required}"));
            }
            string     IP           = req.Query["IP"].ToString();
            LongAndLat long_and_lat = await GetLongitudeAndLatitude(IP, log);

            string          latitude  = long_and_lat.latitude;
            string          longitude = long_and_lat.longitude;
            WeatherResponse weather   = await GetWeather(latitude, longitude);

            var weather_string = JsonConvert.SerializeObject(weather);

            log.LogInformation(weather_string);
            return((ActionResult) new OkObjectResult(weather_string));
        }