ppshobi /
openweathermap
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Shobi\Weatherapp\Endpoints; |
||
| 4 | |||
| 5 | use Shobi\Weatherapp\Http\Client; |
||
| 6 | use Shobi\Weatherapp\Weather\Weather; |
||
| 7 | use Shobi\Weatherapp\Contracts\Endpoint; |
||
| 8 | |||
| 9 | class Current implements Endpoint |
||
| 10 | { |
||
| 11 | const ENDPOINT = 'weather'; |
||
| 12 | |||
| 13 | private $client; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Current constructor. |
||
| 17 | * @param Client $client |
||
| 18 | */ |
||
| 19 | public function __construct(Client $client) |
||
| 20 | { |
||
| 21 | $this->client = $client; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $location |
||
| 26 | * @return Shobi\Weatherapp\Weather\Weather |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 27 | * |
||
| 28 | * @throws GuzzleHttp\Exception\ClientException\ClientException |
||
| 29 | * fetches the current weather data from the api |
||
| 30 | */ |
||
| 31 | public function get($location = "london") : Weather |
||
| 32 | { |
||
| 33 | $reponse = json_decode($this->client->get(self::ENDPOINT, ['q' => $location]), true); |
||
| 34 | |||
| 35 | $description = $reponse['weather'][0]['description']; |
||
| 36 | $temparature = $reponse['main']['temp']; |
||
| 37 | $location = $reponse['name']; |
||
| 38 | |||
| 39 | return new Weather($description, $temparature, $location); |
||
|
0 ignored issues
–
show
|
|||
| 40 | } |
||
| 41 | } |