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;
}
}