forked from apixu/apixu-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.php
31 lines (25 loc) · 832 Bytes
/
history.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
<?php declare(strict_types = 1);
use Apixu\Exception\ApixuException;
use Apixu\Exception\InternalServerErrorException;
use Apixu\Exception\ErrorException;
require dirname(__DIR__) . '/vendor/autoload.php';
try {
$language = 'unknown'; // defaults to English
$api = \Apixu\Factory::create($_SERVER['APIXUKEY'], $language);
} catch (ApixuException $e) {
die($e->getMessage());
}
$q = 'London';
$since = new \DateTime();
$since->modify('-1 day');
$until = new \DateTime(); // paid license only
try {
$history = $api->history($q, $since, $until);
} catch (InternalServerErrorException $e) {
die($e->getMessage());
} catch (ErrorException $e) {
die($e->getMessage());
} catch (ApixuException $e) {
die($e->getMessage());
}
print_r(\Serializer\SerializerBuilder::instance()->build()->toArray($history));