|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bakerkretzmar\LaravelMapbox; |
|
4
|
|
|
|
|
5
|
|
|
use RunTimeException; |
|
6
|
|
|
|
|
7
|
|
|
use Zttp\Zttp; |
|
8
|
|
|
|
|
9
|
|
|
class Features extends MapboxRequest |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Create a new Features request instance. |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $dataset_id |
|
15
|
|
|
* @param string|null $feature_id |
|
16
|
|
|
*/ |
|
17
|
18 |
|
public function __construct(string $dataset_id, string $feature_id = null) |
|
18
|
|
|
{ |
|
19
|
18 |
|
$this->dataset_id = $dataset_id; |
|
20
|
18 |
|
$this->feature_id = $feature_id; |
|
21
|
18 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* List Features. |
|
25
|
|
|
* |
|
26
|
|
|
* @see https://docs.mapbox.com/api/maps/#list-features |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
2 |
|
public function list() |
|
30
|
|
|
{ |
|
31
|
2 |
|
return Zttp::get($this->url(Mapbox::DATASETS_ENDPOINT, $this->dataset_id, [ |
|
32
|
2 |
|
Mapbox::FEATURES_ENDPOINT, |
|
33
|
2 |
|
]))->json(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Create or update a Feature. |
|
38
|
|
|
* |
|
39
|
|
|
* @see https://docs.mapbox.com/api/maps/#insert-or-update-a-feature |
|
40
|
|
|
* @param mixed $feature |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
18 |
|
public function insert($feature) |
|
44
|
|
|
{ |
|
45
|
18 |
|
if (! $this->feature_id) { |
|
46
|
|
|
throw new RunTimeException('Feature ID required'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
18 |
|
return Zttp::put($this->url(Mapbox::DATASETS_ENDPOINT, $this->dataset_id, [ |
|
50
|
18 |
|
Mapbox::FEATURES_ENDPOINT, |
|
51
|
18 |
|
$this->feature_id, |
|
52
|
18 |
|
]), $feature)->json(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Retrieve a Feature. |
|
57
|
|
|
* |
|
58
|
|
|
* @see https://docs.mapbox.com/api/maps/#retrieve-a-feature |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
4 |
|
public function get() |
|
62
|
|
|
{ |
|
63
|
4 |
|
if (! $this->feature_id) { |
|
64
|
|
|
throw new RunTimeException('Feature ID required'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
return Zttp::get($this->url(Mapbox::DATASETS_ENDPOINT, $this->dataset_id, [ |
|
68
|
4 |
|
Mapbox::FEATURES_ENDPOINT, |
|
69
|
4 |
|
$this->feature_id, |
|
70
|
4 |
|
]))->json(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Delete a Feature. |
|
75
|
|
|
* |
|
76
|
|
|
* @see https://docs.mapbox.com/api/maps/#delete-a-feature |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
2 |
|
public function delete() |
|
80
|
|
|
{ |
|
81
|
2 |
|
if (! $this->feature_id) { |
|
82
|
|
|
throw new RunTimeException('Feature ID required'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
return Zttp::delete($this->url(Mapbox::DATASETS_ENDPOINT, $this->dataset_id, [ |
|
86
|
2 |
|
Mapbox::FEATURES_ENDPOINT, |
|
87
|
2 |
|
$this->feature_id, |
|
88
|
2 |
|
]))->status() === Mapbox::DELETE_SUCCESS_STATUS; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|