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