HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/ijzerenman.komma.pro/app/Custom/Weather/WeatherApi.php
<?php


namespace Komma\Weather;
use Komma\Curl\CurlService;

/**
 * Api: http://openweathermap.org/
 *
 * Class WeatherApi
 * @package Komma\Weather
 */

class WeatherApi
{
    /**
     * @var
     */
    private $curlService;

    /**
     * @param CurlService $curlService
     */
    public function __construct(CurlService $curlService)
    {
        $this->curlService = $curlService;
    }

    /**
     * @var string
     */
    private $apiKey = '1cdb70fdeb3956aab4c96afeca7d8b57';

    /**
     * Request weather forecast
     * @param $cityId
     * @return String
     */
    public function request($cityId)
    {
        // Build url
        $url = 'api.openweathermap.org/data/2.5/forecast/city';
        // Append city id
        $url .= '?id=' . $cityId;
        // Append api key
        $url .= '&APPID=' . $this->apiKey;
        // Set units to Celsius
        $url .= '&units=metric';

        // Make a curl request
        list($httpCode, $response, $error) = $this->curlService->get($url);

        return $response;
    }
}