{"size": 880, "ext": "js", "max_stars_repo_path": "weather.js", "max_stars_repo_name": "CarlosPGraciano/weather-js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "weather.js", "max_issues_repo_name": "CarlosPGraciano/weather-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "weather.js", "max_forks_repo_name": "CarlosPGraciano/weather-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5925925926, "max_line_length": 144, "alphanum_fraction": 0.6931818182}
class Weather {
  constructor() {
    this.apiKey = '11a5db272ecfa35656c61f42c6f7b9a5';
    this.city = '';
  }
  // Change Weather Location By Name
  setLocationByName(city) {
    this.city = city;
  }

  // Fetch Geolocation API
  async getPosition() {
    return await new Promise((resolve) => navigator.geolocation.getCurrentPosition((position) => resolve(position.coords)));
  }

  // Fetch weather API
  async getWeatherByName() {
    const rawApiResponse = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${this.city}&APPID=${this.apiKey}`);
    return await rawApiResponse.json();
  }

  async getWeatherByLatLon(coords) {
    const { latitude, longitude } = coords;
    const rawApiResponse = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&APPID=${this.apiKey}`);
    return await rawApiResponse.json();
  }
}