1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NStack\Clients; |
4
|
|
|
|
5
|
|
|
use NStack\Exceptions\FailedToParseException; |
6
|
|
|
use NStack\Models\Timezone; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class TimezoneClient |
10
|
|
|
* |
11
|
|
|
* @package NStack\Clients |
12
|
|
|
* @author Tiago Araujo <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class TimezoneClient extends NStackClient |
15
|
|
|
{ |
16
|
|
|
/** @var string */ |
17
|
|
|
protected $path = 'geographic/time_zones'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* index |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
* @throws FailedToParseException |
24
|
|
|
*/ |
25
|
1 |
|
public function index(): array |
26
|
|
|
{ |
27
|
1 |
|
$response = $this->client->get($this->buildPath($this->path)); |
28
|
1 |
|
$contents = $response->getBody()->getContents(); |
29
|
1 |
|
$data = json_decode($contents, true); |
30
|
|
|
|
31
|
1 |
|
$array = []; |
32
|
1 |
|
foreach ($data['data'] as $object) { |
33
|
1 |
|
$array[] = new Timezone($object); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
return $array; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* show |
41
|
|
|
* |
42
|
|
|
* @param $id |
43
|
|
|
* @return Timezone |
44
|
|
|
* @throws FailedToParseException |
45
|
|
|
*/ |
46
|
1 |
|
public function show($id): Timezone |
47
|
|
|
{ |
48
|
1 |
|
$response = $this->client->get($this->buildPath($this->path . '/' . $id)); |
49
|
1 |
|
$contents = $response->getBody()->getContents(); |
50
|
1 |
|
$data = json_decode($contents, true); |
51
|
1 |
|
return new Timezone($data['data']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* show |
56
|
|
|
* |
57
|
|
|
* @param float $lat |
58
|
|
|
* @param float $lng |
59
|
|
|
* @return Timezone |
60
|
|
|
* @throws FailedToParseException |
61
|
|
|
*/ |
62
|
1 |
|
public function showByLatLng(float $lat, float $lng): Timezone |
63
|
|
|
{ |
64
|
1 |
|
$response = $this->client->get( |
65
|
1 |
|
$this->buildPath($this->path . '/by_lat_lng?=lat_lng' . $lat . ',' . $lng) |
66
|
|
|
); |
67
|
1 |
|
$contents = $response->getBody()->getContents(); |
68
|
1 |
|
$data = json_decode($contents, true); |
69
|
1 |
|
return new Timezone($data['data']); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |