-
Notifications
You must be signed in to change notification settings - Fork 3
/
brapi.api.php
265 lines (255 loc) · 8.46 KB
/
brapi.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
use Drupal\brapi\Entity\BrapiDatatype;
use Drupal\Core\Entity\EntityStorageInterface;
/**
* @file
* Hooks specific to the Hooks Example module.
*/
/**
* BrAPI hook documentation.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* The CALL_SIGNATURE is composed by the method + the BrAPI major version +
* the call name all in lower case with any consecutive non-word characters
* replaced by underscores and with trailing underscores removed.
* ex.: "get_v2_lists_listdbid" is the signature for the GET method of the call
* /lists/{listDbId} of BrAPI v2.
*
*/
/**
* Replace any default BrAPI call implementation.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* @param &$json_array
* Should be not set unless a previous hook implementation set it.
* It should return a full BrAPI result structure including metadata.
*
* @param array &$context
* An array containing the following:
* - 'request': a \Symfony\Component\HttpFoundation\Request object;
* - 'config' : a \Drupal\Core\Config\ImmutableConfig object;
* - 'version': a version string, either 'v1' or 'v2';
* - 'call' : the call name string. ex.: '/lists/{listDbId}'
* - 'method' : the lowercase method string ex.: 'get', 'post', 'put',...
*/
function hook_brapi_call_alter(&$json_array, array &$context) {
}
/**
* Replaces the given BrAPI call implementation.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* @param &$json_array
* Should be not set unless a previous hook implementation set it.
* It should return a full BrAPI result structure including metadata.
*
* @param array &$context
* An array containing the following:
* - 'request': a \Symfony\Component\HttpFoundation\Request object;
* - 'config' : a \Drupal\Core\Config\ImmutableConfig object;
* - 'version': a version string, either 'v1' or 'v2';
* - 'call' : the call name string. ex.: '/lists/{listDbId}'
* - 'method' : the lowercase method string ex.: 'get', 'post', 'put',...
*
* @see main BrAPI hook documentation for CALL_SIGNATURE format details.
*/
function hook_brapi_call_CALL_SIGNATURE_alter(&$json_array, array &$context) {
}
/**
* Supports missing BrAPI call implementations.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* @param &$json_array
* Should be not set unless a previous hook implementation set it.
* It should return a full BrAPI result structure including metadata.
*
* @param array &$context
* An array containing the following:
* - 'request': a \Symfony\Component\HttpFoundation\Request object;
* - 'config' : a \Drupal\Core\Config\ImmutableConfig object;
* - 'version': a version string, either 'v1' or 'v2';
* - 'call' : the call name string. ex.: '/lists/{listDbId}'
* - 'method' : the lowercase method string ex.: 'get', 'post', 'put',...
*/
function hook_brapi_unsupported_call_alter(&$json_array, array &$context) {
}
/**
* Alter any call result array.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* @param &$json_array
* Should contain a call result.
*
* @param array &$context
* An array containing the following:
* - 'request': a \Symfony\Component\HttpFoundation\Request object;
* - 'config' : a \Drupal\Core\Config\ImmutableConfig object;
* - 'version': a version string, either 'v1' or 'v2';
* - 'call' : the call name string. ex.: '/lists/{listDbId}'
* - 'method' : the lowercase method string ex.: 'get', 'post', 'put',...
*/
function hook_brapi_call_result_alter(&$json_array, array &$context) {
}
/**
* Alter a given call result array.
*
* If a 'response' key is added to the $context, it will be returned to Drupal.
*
* @param &$json_array
* Should contain a call result.
*
* @param array &$context
* An array containing the following:
* - 'request': a \Symfony\Component\HttpFoundation\Request object;
* - 'config' : a \Drupal\Core\Config\ImmutableConfig object;
* - 'version': a version string, either 'v1' or 'v2';
* - 'call' : the call name string. ex.: '/lists/{listDbId}'
* - 'method' : the lowercase method string ex.: 'get', 'post', 'put',...
*
* @see main BrAPI hook documentation for CALL_SIGNATURE format details.
*/
function hook_brapi_call_CALL_SIGNATURE_result_alter(&$json_array, array &$context) {
// This example changes ['result']['data'] from
// [['value' => '01BEL084609'], ['value' => '01BEL084123']]
// to ['01BEL084609', '01BEL084123'].
if (!empty($json_array['result']['data'])) {
$json_array['result']['data'] = array_map(
function ($d) {
return $d['value'] ?? '';
},
$json_array['result']['data']
);
}
}
/**
* Alter BrAPI data before it is saved.
*
* @param array &$data
* Current BrAPI record data.
*
* @param BrapiDatatype &$data_type
* BrAPI data type mapping instance.
*
* @param EntityStorageInterface &$storage
* Storage.
*/
function hook_brapi_BRAPI_DATA_TYPE_save_alter(
array &$data,
BrapiDatatype &$data_type,
EntityStorageInterface &$storage
) {
}
/**
* Alter BrAPI data before it is saved.
*
* @param array &$versions
* BrAPI definitions. See brapi_get_definition() for details.
*
* @param string &$version_key
* Requested version as a key string. Key structure:
* version_key = version + '#' + subversion
* Note: any character that is neither a word character, a dot or a dash is
* removed from the key.
* ex.: $version_key = 'v2#2.0'
*/
function hook_brapi_definition_alter(
array &$versions,
string &$version_key,
) {
// Adds a delete method to /lists/{listDbId}.
if (empty($versions[$version_key]['calls']['/lists/{listDbId}']['definition']['delete'])) {
$versions[$version_key]['calls']['/lists/{listDbId}']['definition']['delete'] = [
"tags" => [
"Lists",
],
"summary" => "Removes a specific list",
"description" => "Removes a specific list",
"parameters" => [
[
"name" => "listDbId",
"in" => "path",
"description" => "The unique ID of this generic list",
"required" => true,
"style" => "simple",
"explode" => false,
"schema" => [
"type" => "string",
],
],
[
"name" => "Authorization",
"in" => "header",
"description" => "HTTP HEADER - Token used for Authorization\n\n<strong> Bearer {token_string} </strong>",
"required" => false,
"style" => "simple",
"explode" => false,
"schema" => [
"pattern" => "^Bearer .*$",
"type" => "string",
],
"example" => "Bearer XXXX",
],
],
"responses" => [
200 => [
"description" => "OK",
"content" => [
"application/json" => [
"schema" => [
"$ref" => "#/components/schemas/ListsSingleResponse",
],
],
],
],
400 => [
"description" => "Bad Request",
"content" => [
"application/json" => [
"schema" => [
"type" => "string",
],
"example" => "ERROR - 2018-10-08T18:15:11Z - Malformed JSON Request Object\n\nERROR - 2018-10-08T18:15:11Z - Invalid query parameter\n\nERROR - 2018-10-08T18:15:11Z - Required parameter is missing",
],
],
],
401 => [
"description" => "Unauthorized",
"content" => [
"application/json" => [
"schema" => [
"type" => "string",
],
"example" => "ERROR - 2018-10-08T18:15:11Z - Missing or expired authorization token",
],
],
],
403 => [
"description" => "Forbidden",
"content" => [
"application/json" => [
"schema" => [
"type" => "string",
],
"example" => "ERROR - 2018-10-08T18:15:11Z - User does not have permission to perform this action",
],
],
],
404 => [
"description" => "Not Found",
"content" => [
"application/json" => [
"schema" => [
"type" => "string",
],
"example" => "ERROR - 2018-10-08T18:15:11Z - The requested object DbId is not found",
],
],
],
],
];
}
}