Skip to content

Commit

Permalink
LDT-51: Implementation of Third-Party API for Weather Information.
Browse files Browse the repository at this point in the history
  • Loading branch information
axelabhay committed May 6, 2024
1 parent 3a52047 commit 433ddad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
13 changes: 8 additions & 5 deletions Drupal/modules/custom/weather/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Integrate Third-Party API for Weather Data (Programmatically, Guzzle)
# Integrate Third-Party API for Weather Information

## Description:
Help our visitors plan as per weather conditions. Fetch weather data from a third-party API and display it on the site’s contact us page using a custom block.
Improve the experience of visitors to our office by offering real-time weather updates on the homepage of our website. This feature enables our visitors to effectively plan their activities according to the prevailing weather conditions.

## Acceptance Criteria:
- Weather data is updated every hour.
- Display includes temperature, wind, and precipitation.
- Store data in cache and create a block to display it.
- Use third party Weather API to fetch the weather details
- On home page show weather details like temperature, wind and precipitation
- Implement caching to retain weather data for a duration of one hour.
- Implement robust error handling to manage failed API requests or data parsing errors, ensuring the site’s front page remains functional

## Solution
Course Link:
Troubleshoot:
Raise Issue: https://github.com/axelerant-trainings/project-usecases/issues/new
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ class WeatherDisplay extends BlockBase implements ContainerFactoryPluginInterfac
* @param \Drupal\weather\Services\Weather $weather
* The weather service.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
Weather $weather,
) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Weather $weather) {
parent::__construct($configuration, $plugin_id, $plugin_definition);

$this->weather = $weather;
}

Expand Down
1 change: 0 additions & 1 deletion Drupal/modules/custom/weather/src/Services/Weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function getTodaysWeather($city): mixed {
'query' => [
'key' => $weather_settings->get('api_key'),
'q' => $city,
'units' => 'metric',
],
]);

Expand Down
11 changes: 11 additions & 0 deletions Drupal/modules/custom/weather/templates/weather-display.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{#
/**
* @file
* Theme implementation to display weather report over a block.
*
* Available variables:
* - weather_data: weather data received from thirtd party.
*
* @ingroup themeable
*/
#}
<div class="weather-widget">
<p id="location" style="font-weight: bold;">{{ weather_data.location }}</p>
<div style="display: flex; align-items: center;">
Expand Down

0 comments on commit 433ddad

Please sign in to comment.