Exemplo n.º 1
0
        public float getCurrentWeather(string cityName, EndpointType endpoint)
        {
            AccuWeatherController accuweatherController = new AccuWeatherController();

            List <float> coordinates = accuweatherController.getCoordinates(cityName);



            float temperature = 0f;

            restClient.endpoint = climaCellEndpoint.getByCityNameEndpoint(coordinates[0], coordinates[1], EndpointType.CURRENT);
            string response = restClient.makeRequest();

            JSONParser <ClimaCellWeatherModel> jsonParser = new JSONParser <ClimaCellWeatherModel>();

            ClimaCellWeatherModel deserialisedClimaCellModel = new ClimaCellWeatherModel();

            deserialisedClimaCellModel = jsonParser.parseJSON(response, Parser.Version.NETCore2);

            temperature = deserialisedClimaCellModel.temp.value;

            climaCellEndpoint.getByCityNameEndpointForecast(coordinates[0], coordinates[1], EndpointType.FORECAST);

            return(temperature);
        }
Exemplo n.º 2
0
        public List <DarkSkyForecast> getForecast(string cityName, EndpointType endpoint)
        {
            List <DarkSkyForecast> forecastList = new List <DarkSkyForecast>();

            AccuWeatherController accuweatherController = new AccuWeatherController();

            List <float> coordinates = accuweatherController.getCoordinates(cityName);

            restClient.endpoint = darkSkyEndpoint.getByCityNameEndpointForecast(coordinates[0], coordinates[1], EndpointType.FORECAST);
            string response = restClient.makeRequest();

            JSONParser <DarkSkyForecastModel> jsonParser = new JSONParser <DarkSkyForecastModel>();

            var deserialisedAccuWeatherModel = jsonParser.parseJSON(response, Parser.Version.NETCore2);

            foreach (DailyForecastDaily model in deserialisedAccuWeatherModel.daily.data)
            {
                forecastList.Add(new DarkSkyForecast(model.temperatureHigh, model.temperatureLow));
            }

            return(forecastList);
        }
Exemplo n.º 3
0
        public List <ClimaCellForecast> getForecast(string cityName, EndpointType endpoint)
        {
            List <ClimaCellForecast> forecastList = new List <ClimaCellForecast>();

            AccuWeatherController accuweatherController = new AccuWeatherController();

            List <float> coordinates = accuweatherController.getCoordinates(cityName);

            restClient.endpoint = climaCellEndpoint.getByCityNameEndpointForecast(coordinates[0], coordinates[1], EndpointType.FORECAST);
            string response = restClient.makeRequest();

            JSONParser <List <ClimaCellForecastModel> > jsonParser = new JSONParser <List <ClimaCellForecastModel> >();

            var deserialisedAccuWeatherModel = jsonParser.parseJSON(response, Parser.Version.NETCore2);

            foreach (ClimaCellForecastModel model in deserialisedAccuWeatherModel)
            {
                forecastList.Add(new ClimaCellForecast(model.temp[0].min.value, model.temp[1].max.value));
            }

            return(forecastList);
        }