-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
46 lines (36 loc) · 1.06 KB
/
main.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
<?php
require 'vendor/autoload.php';
use Alfred\Workflow;
$query = intval($argv[1]);
$ch = curl_init( 'http://api.eztable.com/v2/restaurant/get_info/'.$query.'/');
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);
curl_setopt_array( $ch, $options );
$restaurantInfo = json_decode(curl_exec($ch), true);
// Pass a Bundle ID
$w = new Workflow();
$resultArray = array(
'uid' => 'itemuid',
// 'arg' => 'itemarg',
'valid' => 'yes',
'autocomplete' => 'autocomplete',
'icon' => 'icon.png',
'title' => 'EZTABLE restaurant name',
);
if (is_null($restaurantInfo)) {
// network error
$resultArray['subtitle'] = 'Can not conntect to API!';
$w->result($resultArray);
echo $w->toXML();
exit;
}
if ($restaurantInfo['status'] == "OK") {
$resultArray['subtitle'] = $restaurantInfo['data']['name'];
$resultArray['arg'] = $query;
} else {
$resultArray['subtitle'] = 'API error!';
}
$w->result($resultArray);
echo $w->toXML();