This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForecastController.php
70 lines (59 loc) · 2.17 KB
/
ForecastController.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
<?php
namespace App\Http\Controllers\Vxml;
use App\VoiceXml;
use GuzzleHttp\Client;
use App\Http\Controllers\Controller;
class ForecastController extends Controller
{
protected $towns = [
'1' => 'bolgatanga',
'2' => 'tamale',
'3' => 'sunyani',
'4' => 'kumasi',
'5' => 'accra',
'6' => 'ho',
];
public function index($town, $time)
{
$vxml = new VoiceXml();
$client = new Client();
$res = $client->request('GET', 'https://api.openweathermap.org/data/2.5/forecast', [
'query' => [
'APPID' => env('WEATHER_API'),
'q' => $this->towns[$town] . ',gh'
]
]);
$data = json_decode($res->getBody(), true);
// This data can be used to forecast weather. The calculation algorithm
// for generating appropriate response is still being figured out.
// FUTURE WORK!
if ($time == '1') {
$vxml->prompt(asset('audio/en/4_4.wav'));
$vxml->prompt(asset('audio/en/4_2_1.wav'));
$vxml->prompt(asset('audio/en/4_2_1_2.wav'));
$vxml->prompt(asset('audio/en/C_2.wav'));
$vxml->prompt(asset('audio/en/4_2_1_3.wav'));
$vxml->prompt(asset('audio/en/4_7.wav'));
$vxml->prompt(asset('audio/en/4_2_1.wav'));
$vxml->prompt(asset('audio/en/4_2_1_1.wav'));
$vxml->prompt(asset('audio/en/c_2.wav'));
$vxml->prompt(asset('audio/en/4_2_1_2.wav'));
} elseif($time == '2') {
$vxml->prompt(asset('audio/en/5_2.wav'));
$vxml->prompt(asset('audio/en/5_2_4.wav'));
$vxml->prompt(asset('audio/en/C_2.wav'));
$vxml->prompt(asset('audio/en/5_2_5.wav'));
} else {
$vxml->prompt(asset('audio/en/6_1.wav'));
}
$response = $vxml->response('vxml', url('/vxml'));
return response($response->asXml(), '200')
->header('Content-Type', 'text/xml');
}
public function create($option)
{
$vxml = new VoiceXml();
return response($vxml->disconnect()->asXml(), '200')
->header('Content-Type', 'text/xml');
}
}