1 | <?php |
||
10 | abstract class Resource |
||
11 | { |
||
12 | /** |
||
13 | * @var \Vindi\ApiRequester |
||
14 | */ |
||
15 | public $apiRequester; |
||
16 | |||
17 | /** |
||
18 | * Resource constructor. |
||
19 | * |
||
20 | * @param array $arguments |
||
21 | */ |
||
22 | 448 | public function __construct($arguments = []) |
|
23 | { |
||
24 | 448 | if (key_exists(Vindi::VINDI_API_KEY, $arguments)) { |
|
25 | Vindi::setApiKey($arguments[Vindi::VINDI_API_KEY]); |
||
26 | } |
||
27 | |||
28 | 448 | if (key_exists(Vindi::VINDI_API_URI, $arguments)) { |
|
29 | Vindi::setApiUri($arguments[Vindi::VINDI_API_URI]); |
||
30 | } |
||
31 | 448 | $this->apiRequester = new ApiRequester; |
|
32 | 448 | } |
|
33 | |||
34 | /** |
||
35 | * The endpoint at default state that will hit the API. |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | abstract public function endpoint(); |
||
40 | |||
41 | /** |
||
42 | * Build url that will hit the API. |
||
43 | * |
||
44 | * @param int $id The resource's id. |
||
45 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | 322 | public function url($id = null, $additionalEndpoint = null) |
|
62 | |||
63 | /** |
||
64 | * Retrieve all resources. |
||
65 | * |
||
66 | * @param array $params Pagination and Filter parameters. |
||
67 | * |
||
68 | * @return mixed |
||
69 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
70 | * @throws \Vindi\Exceptions\RateLimitException |
||
71 | * @throws \Vindi\Exceptions\RequestException |
||
72 | */ |
||
73 | 42 | public function all(array $params = []) |
|
77 | |||
78 | /** |
||
79 | * Create a new resource. |
||
80 | * |
||
81 | * @param array $form_params The request body. |
||
82 | * |
||
83 | * @return mixed |
||
84 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
85 | * @throws \Vindi\Exceptions\RateLimitException |
||
86 | * @throws \Vindi\Exceptions\RequestException |
||
87 | */ |
||
88 | 42 | public function create(array $form_params = []) |
|
92 | |||
93 | /** |
||
94 | * Retrieve a specific resource. |
||
95 | * |
||
96 | * @param int $id The resource's id. |
||
97 | * |
||
98 | * @return mixed |
||
99 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
100 | * @throws \Vindi\Exceptions\RateLimitException |
||
101 | * @throws \Vindi\Exceptions\RequestException |
||
102 | */ |
||
103 | 42 | public function retrieve($id = null) |
|
107 | |||
108 | /** |
||
109 | * Update a specific resource. |
||
110 | * |
||
111 | * @param int $id The resource's id. |
||
112 | * @param array $form_params The request body. |
||
113 | * |
||
114 | * @return mixed |
||
115 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
116 | * @throws \Vindi\Exceptions\RateLimitException |
||
117 | * @throws \Vindi\Exceptions\RequestException |
||
118 | */ |
||
119 | 42 | public function update($id = null, array $form_params = []) |
|
123 | |||
124 | /** |
||
125 | * Delete a specific resource. |
||
126 | * |
||
127 | * @param int $id The resource's id. |
||
128 | * @param array $form_params The request body. |
||
129 | * |
||
130 | * @return mixed |
||
131 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
132 | * @throws \Vindi\Exceptions\RateLimitException |
||
133 | * @throws \Vindi\Exceptions\RequestException |
||
134 | */ |
||
135 | 42 | public function delete($id = null, array $form_params = []) |
|
139 | |||
140 | /** |
||
141 | * Make a GET request to an additional endpoint for a specific resource. |
||
142 | * |
||
143 | * @param int $id The resource's id. |
||
144 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
145 | * |
||
146 | * @return mixed |
||
147 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
148 | * @throws \Vindi\Exceptions\RateLimitException |
||
149 | * @throws \Vindi\Exceptions\RequestException |
||
150 | */ |
||
151 | 44 | public function get($id = null, $additionalEndpoint = null) |
|
155 | |||
156 | /** |
||
157 | * Make a POST request to an additional endpoint for a specific resource. |
||
158 | * |
||
159 | * @param int $id The resource's id. |
||
160 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
161 | * @param array $form_params The request body. |
||
162 | * |
||
163 | * @return mixed |
||
164 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
165 | * @throws \Vindi\Exceptions\RateLimitException |
||
166 | * @throws \Vindi\Exceptions\RequestException |
||
167 | */ |
||
168 | 68 | public function post($id = null, $additionalEndpoint = null, array $form_params = []) |
|
172 | |||
173 | /** |
||
174 | * Return the last response from a preview request |
||
175 | * |
||
176 | * @return mixed |
||
177 | */ |
||
178 | 84 | public function getLastResponse() |
|
182 | } |
||
183 |