• Roman Regmi 7
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
public with sharing class WeatherWrapper {

    @AuraEnabled

    public Forecast forecast;

    public class Forecast{

        @AuraEnabled

        public List<Forecastday> forecastday;

    }

    public class Forecastday {

        @AuraEnabled

        public List<Hour> hour;

    }

    public class Hour {

        @AuraEnabled

        @SerializedName('time')

        public String time_Z;

        @AuraEnabled

        public Condition condition;

        @AuraEnabled

        public Integer humidity;

        @AuraEnabled

        public Double temp_c;

        @AuraEnabled

        public Double wind_mph;

    }

    public class Condition {

        @AuraEnabled

        public String text;

        @AuraEnabled

        public String icon;

    }

    public static WeatherWrapper parse(String json) {

        return (WeatherWrapper) System.JSON.deserialize(json, WeatherWrapper.class);

    }

}
public static WeatherWrapper forecastWeather1(String city){

        List<WeatherWrapper.Forecast> forecast = new List<WeatherWrapper.Forecast>();

        Http http = new Http();

        HttpRequest req = new HttpRequest();

        req.setEndpoint('callout:WeatherAPI/forecast.json?q=' + city);

        req.setMethod('GET');

        HttpResponse res = http.send(req);

        WeatherWrapper weatherResponse = WeatherWrapper.parse(res.getBody());

        return weatherResponse;

    }