1 | <?php |
||
5 | abstract class Resource |
||
6 | { |
||
7 | /** |
||
8 | * @var \Vindi\ApiRequester |
||
9 | */ |
||
10 | public $apiRequester; |
||
11 | |||
12 | /** |
||
13 | * Resource constructor. |
||
14 | * |
||
15 | * @param array $arguments |
||
16 | */ |
||
17 | 448 | public function __construct($arguments = []) |
|
29 | |||
30 | /** |
||
31 | * The endpoint at default state that will hit the API. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract public function endpoint(); |
||
36 | |||
37 | /** |
||
38 | * Build url that will hit the API. |
||
39 | * |
||
40 | * @param int $id The resource's id. |
||
41 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 322 | public function url($id = null, $additionalEndpoint = null) |
|
58 | |||
59 | /** |
||
60 | * Retrieve all resources. |
||
61 | * |
||
62 | * @param array $params Pagination and Filter parameters. |
||
63 | * |
||
64 | * @return mixed |
||
65 | * @throws Exceptions\RateLimitException |
||
66 | * @throws Exceptions\RequestException |
||
67 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
68 | */ |
||
69 | 42 | public function all(array $params = []) |
|
73 | |||
74 | /** |
||
75 | * Create a new resource. |
||
76 | * |
||
77 | * @param array $form_params The request body. |
||
78 | * |
||
79 | * @return mixed |
||
80 | * @throws Exceptions\RateLimitException |
||
81 | * @throws Exceptions\RequestException |
||
82 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
83 | */ |
||
84 | 42 | public function create(array $form_params = []) |
|
88 | |||
89 | /** |
||
90 | * Retrieve a specific resource. |
||
91 | * |
||
92 | * @param int $id The resource's id. |
||
93 | * |
||
94 | * @return mixed |
||
95 | * @throws Exceptions\RateLimitException |
||
96 | * @throws Exceptions\RequestException |
||
97 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
98 | */ |
||
99 | 42 | public function retrieve($id = null) |
|
103 | |||
104 | /** |
||
105 | * Update a specific resource. |
||
106 | * |
||
107 | * @param int $id The resource's id. |
||
108 | * @param array $form_params The request body. |
||
109 | * |
||
110 | * @return mixed |
||
111 | * @throws Exceptions\RateLimitException |
||
112 | * @throws Exceptions\RequestException |
||
113 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
114 | */ |
||
115 | 42 | public function update($id = null, array $form_params = []) |
|
119 | |||
120 | /** |
||
121 | * Delete a specific resource. |
||
122 | * |
||
123 | * @param int $id The resource's id. |
||
124 | * @param array $form_params The request body. |
||
125 | * |
||
126 | * @return mixed |
||
127 | * @throws Exceptions\RateLimitException |
||
128 | * @throws Exceptions\RequestException |
||
129 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
130 | */ |
||
131 | 42 | public function delete($id = null, array $form_params = []) |
|
135 | |||
136 | /** |
||
137 | * Make a GET request to an additional endpoint for a specific resource. |
||
138 | * |
||
139 | * @param int $id The resource's id. |
||
140 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
141 | * |
||
142 | * @return mixed |
||
143 | * @throws Exceptions\RateLimitException |
||
144 | * @throws Exceptions\RequestException |
||
145 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
146 | */ |
||
147 | 44 | public function get($id = null, $additionalEndpoint = null) |
|
151 | |||
152 | /** |
||
153 | * Make a POST request to an additional endpoint for a specific resource. |
||
154 | * |
||
155 | * @param int $id The resource's id. |
||
156 | * @param string $additionalEndpoint Additional endpoint that will be appended to the URL. |
||
157 | * @param array $form_params The request body. |
||
158 | * |
||
159 | * @return mixed |
||
160 | * @throws Exceptions\RateLimitException |
||
161 | * @throws Exceptions\RequestException |
||
162 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
163 | */ |
||
164 | 68 | public function post($id = null, $additionalEndpoint = null, array $form_params = []) |
|
168 | |||
169 | /** |
||
170 | * Return the last response from a preview request |
||
171 | * |
||
172 | * @return mixed |
||
173 | */ |
||
174 | 84 | public function getLastResponse() |
|
178 | } |
||
179 |