29 lines
897 B
Java
29 lines
897 B
Java
package model;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import java.io.IOException;
|
|
|
|
/*
|
|
Klasa odczytujaca z odpowiedzi API wyamagane informacje o prognozie pogody.
|
|
*/
|
|
|
|
public class ForecastPreparation {
|
|
|
|
|
|
public static weatherForecast fetchForecastData(String cityName, String response) throws IOException {
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
JsonNode rootNode = objectMapper.readTree(response);
|
|
|
|
String description = rootNode.get("weather").get(0).get("description").asText();
|
|
double temperature = rootNode.get("main").get("temp").asDouble();
|
|
int pressure = rootNode.get("main").get("pressure").asInt();
|
|
int humidity = rootNode.get("main").get("humidity").asInt();
|
|
|
|
return new weatherForecast(cityName, description, temperature, pressure, humidity);
|
|
|
|
}
|
|
}
|