-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_reviews.php
More file actions
52 lines (40 loc) · 1.3 KB
/
get_reviews.php
File metadata and controls
52 lines (40 loc) · 1.3 KB
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
<?php
/**
* This example requires a restaurant's ID, and lists some reviews.
*
* Usage: open a terminal and execute the script, for example using
* `php list_menu.php <id>`.
*/
require_once __DIR__.'/../vendor/autoload.php';
use Takeaway\Takeaway;
use Takeaway\Http\Requests\GetReviewsRequest;
// Parse arguments
if ($argc < 3) {
echo 'Usage: php '.$argv[0].' <countryCode> <id>'.PHP_EOL;
die(1);
}
$countryCode = $argv[1];
$restaurantId = $argv[2];
// Set base URL
Takeaway::setConfigValue(Takeaway::CFG_BASE_URL, 'https://' . $countryCode . '.citymeal.com/android/android.php');
// Find country by given locale code
$country = Takeaway::getCountryByLocale($countryCode);
if (!$country) {
echo 'Unknown country: '.$countryCode.PHP_EOL;
die(1);
}
// Update language
Takeaway::setConfigValue(Takeaway::CFG_LANGUAGE, $country->languages[0]);
// Request reviews for restaurant
$req = new GetReviewsRequest($restaurantId, 1);
$reviews = $req->getData();
foreach ($reviews['reviews'] as $review) {
echo 'Review by '.($review->name ?: 'Anonymous').' - Q: ' .$review->quality.' D: '.$review->delivery.PHP_EOL;
if ($review->description) {
echo $review->description.PHP_EOL;
}
if ($review->sunday) {
echo '(This review was placed on a Sunday.)'.PHP_EOL;
}
echo PHP_EOL;
}