let config = require('../../config.js');

class HeWeather {
  constructor(key) {
    this.cityAPIUrl = HeWeather.cityAPIUrl.replace("{key}", key);
  }
  
  fetchDataByCityId(cityId, successCallback, errorCallback) {
    let url = this.cityAPIUrl.replace("{cityId}", window.encodeURIComponent(cityId));
    return fetch(url).then(res => {
      if(res.headers.get("content-type") && res.headers.get("content-type").toLowerCase().indexOf("application/json") >= 0) {
        return res.json();
      } else {
        throw new TypeError();
      }
    }).then(successCallback, errorCallback).done();
  }
}

HeWeather.cityAPIUrl = "https://api.heweather.com/x3/weather?cityid={cityId}&key={key}";

module.exports = new HeWeather(config.vendorOptions.key);
@@ -550,16 +550,41 @@
 %7D).then(
+this.parseCityData).then(
 successC
@@ -619,16 +619,1388 @@
 ();%0A  %7D%0A
+  %0A  parseCityData(jsonData) %7B%0A    %0A    let result = %7B%7D;%0A    let rawData = jsonData%5B%22HeWeather data service 3.0%22%5D;%0A    if (rawData && rawData%5B0%5D && rawData%5B0%5D.status === %22ok%22) %7B%0A      let data = rawData%5B0%5D;%0A      result.lastBuildDate = data.basic.update.loc;%0A      result.location = %7B%0A        %22cityId%22: data.basic.id,%0A        %22cityName%22: data.basic.city,%0A        %22country%22: data.basic.cnty%0A      %7D;%0A      result.units = %7B%0A        %22pressure%22: %22pa%22, // TODO%0A        %22speed%22: %22Kmph%22,%0A        %22temperature%22: %22C%22%0A      %7D;%0A      result.weather = %7B%7D;%0A      result.weather.today = %7B%0A        %22temperature%22: data.now.tmp,%0A        %22conditionText%22: data.now.cond.txt,%0A        %22conditionCode%22: data.now.cond.code,%0A        %22lowTemperature%22: data.daily_forecast%5B0%5D.tmp.min,%0A        %22highTemperature%22: data.daily_forecast%5B0%5D.tmp.max,%0A        %22daylightCondition%22: data.daily_forecast%5B0%5D.cond.txt_d,%0A        %22tonightCondition%22: data.daily_forecast%5B0%5D.cond.txt_n,%0A        %22temperatureFeel%22: data.now.fl,%0A        %22humidity%22: data.now.hum,%0A        %22visibility%22: data.now.vis,%0A        %22pressure%22: data.now.pres,%0A        %22windSpeed%22: data.now.wind.spd,%0A        %22windDirection%22: data.now.wind.dir,%0A        %22uvIndex%22: data.suggestion.uv.brf,%0A        %22aqi%22: data.aqi.city.aqi,%0A        %22aqiLevel%22: data.aqi.city.qlty%0A      %7D;%0A      return result;%0A    %7D else %7B%0A      throw new TypeError();%0A    %7D%0A  %7D%0A
 %7D%0A%0AHeWea

Update heweather.js