-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiClass.php
101 lines (93 loc) · 3.32 KB
/
ApiClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
class WindyApi
{
private $apiKeyCam = 'J8lrm1QEzevtGO5nLI9OuJUvzkZZ7SQp';
public function getCityCam($latitude,$longitude,$perim): ?array
{
$curl = curl_init("https://api.windy.com/api/webcams/v2/list/nearby=". $latitude .','. $longitude .','. $perim ."/limit=20?show=webcams:player,image&key=".$this->apiKeyCam);
curl_setopt_array($curl,[
CURLOPT_RETURNTRANSFER=> true,
CURLOPT_TIMEOUT => 1
]);
$data = curl_exec($curl);
if($data === false) {
return null;
}else {
$results = [];
$data = json_decode($data, true);
foreach ($data['result']['webcams'] as $cam) {
$results = [
'camId' => $cam['id'],
'camTitle' => $cam['title'],
'camEmbed'=> $cam['player']['day']['embed'],
'camLink' => $cam['player']['day']['link']
];
}
return $results;
}
}
// public function getWeather($latitude,$longitude,$perim) : ?array
// {
//
// $curl = curl_init("https://api.windy.com/api/webcams/v2/list/nearby=" . $latitude . ',' . $longitude . ',' . $perim . "/limit=20?show=webcams:player,image&key=" . $this->apiKeyCam);
// curl_setopt_array($curl, [
// CURLOPT_RETURNTRANSFER => true,
//
// CURLOPT_TIMEOUT => 1
// ]);
// $data = curl_exec($curl);
// if ($data === false) {
// return null;
// } else {
// $results = [];
// $data = json_decode($data, true);
// foreach ($data['result']['webcams'] as $cam) {
// $results = [
// 'camId' => $cam['id'],
// 'camTitle' => $cam['title'],
// 'camEmbed' => $cam['player']['day']['embed'],
// 'camLink' => $cam['player']['day']['link']
// ];
// }
// return $results;
// }
// }
public function getPhoto($id): ?array
{
$curl = curl_init("https://api.windy.com/api/webcams/v2/list/webcam=" . $id . "?show=webcams:player,image&key=" . $this->apiKeyCam);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 1
]);
$data = curl_exec($curl);
if ($data === false) {
return null;
} else {
$results = [];
$data = json_decode($data, true);
foreach ($data['result']['webcams'] as $cam) {
$results = [
'image' => $cam['image']['daylight']['preview']
];
}
return $results;
}
}
public function getweather(float $lat, float $lng)
{
$curl = curl_init("api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lng."&appid=e7f6120a803061ba4f9c2d3c149bd8cd&units=metric&lang=fr");
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 1
]);
$data = curl_exec($curl);
if ($data === false) {
return null;
} else {
$data = json_decode($data, true);
$resultTemp = $data['main']['temp'];
$results= $resultTemp;
return $results;
}
}
}