[#32] improved documentation
This commit is contained in:
parent
2207a95c2b
commit
f044515feb
|
|
@ -111,7 +111,7 @@ $rest_allowed_actions = array(
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'123.45.678.1' => array(
|
'123.45.67.8' => array(
|
||||||
'Contact' => array(
|
'Contact' => array(
|
||||||
'getsingle' => array(
|
'getsingle' => array(
|
||||||
'first_name' => 'string',
|
'first_name' => 'string',
|
||||||
|
|
@ -124,3 +124,35 @@ $rest_allowed_actions = array(
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
** WebHook2API CONFIGURATIONS **
|
||||||
|
****************************************************************/
|
||||||
|
# remove if you don't want this feature or rename to $webhook2api to activate
|
||||||
|
$_webhook2api = [
|
||||||
|
"configurations" => [
|
||||||
|
"default" => [
|
||||||
|
"name" => "Example",
|
||||||
|
"ip_sources" => ['172.10.0.1/24', '192.168.1.1/24'], // only accept source ID from the given range
|
||||||
|
"data_sources" => ["POST/json", "REQUEST"], // POST/json json-decodes the post data, REQUEST is PHP's $_REQUEST array
|
||||||
|
"sentinel" => [["type", "equal:customer.created"]], // only execute if all of these are true
|
||||||
|
"entity" => "Contact",
|
||||||
|
"action" => "create",
|
||||||
|
"api_key" => "api key",
|
||||||
|
"parameter_mapping" => [
|
||||||
|
[["data", "object", "metadata", "salutation"], ["prefix_id"]],
|
||||||
|
[["data", "object", "metadata", "first_name"], ["first_name"]],
|
||||||
|
[["data", "object", "metadata", "last_name"], ["last_name"]],
|
||||||
|
[["data", "object", "metadata", "street"], ["street_address"]],
|
||||||
|
[["data", "object", "metadata", "zip_code"], ["postal_code"]],
|
||||||
|
[["data", "object", "metadata", "city"], ["city"]],
|
||||||
|
[["data", "object", "metadata", "country"], ["country_id"]],
|
||||||
|
[["data", "object", "metadata", "telephone"], ["phone"]],
|
||||||
|
[["data", "object", "metadata", "birthday"], ["birth_date"]],
|
||||||
|
[["data", "object", "metadata", "email"], ["email"]]
|
||||||
|
],
|
||||||
|
"parameter_sanitation" => [],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
@ -129,7 +129,8 @@ function webhook2api_processConfiguration($configuration, $post_input) {
|
||||||
|
|
||||||
// run modifiers
|
// run modifiers
|
||||||
foreach ($modifiers as $modifier) {
|
foreach ($modifiers as $modifier) {
|
||||||
// TODO:
|
// TODO: implement
|
||||||
|
civiproxy_log("Webhook2API.modifiers: not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set to target
|
// set to target
|
||||||
|
|
@ -142,6 +143,7 @@ function webhook2api_processConfiguration($configuration, $post_input) {
|
||||||
// sanitise data
|
// sanitise data
|
||||||
if (!empty($configuration['parameter_sanitation']) && is_array($configuration['parameter_sanitation'])) {
|
if (!empty($configuration['parameter_sanitation']) && is_array($configuration['parameter_sanitation'])) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
civiproxy_log("Webhook2API.sanitation: not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// send to target REST API
|
// send to target REST API
|
||||||
|
|
@ -161,6 +163,7 @@ function webhook2api_processConfiguration($configuration, $post_input) {
|
||||||
// process result
|
// process result
|
||||||
if (!empty($configuration['response_mapping']) && is_array($configuration['response_mapping'])) {
|
if (!empty($configuration['response_mapping']) && is_array($configuration['response_mapping'])) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
civiproxy_log("Webhook2API.response_mapping: not implemented!");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// default behaviour:
|
// default behaviour:
|
||||||
|
|
@ -221,7 +224,7 @@ function webhook2api_getValue($data, $path) {
|
||||||
function webhook2api_setValue(&$data, $target_path, $value) {
|
function webhook2api_setValue(&$data, $target_path, $value) {
|
||||||
if (is_array($target_path)) {
|
if (is_array($target_path)) {
|
||||||
if (count($target_path) == 0) {
|
if (count($target_path) == 0) {
|
||||||
// error - bad spec
|
civiproxy_log("Webhook2API.setValue: Empty target path!");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} elseif (count($target_path) == 1) {
|
} elseif (count($target_path) == 1) {
|
||||||
|
|
@ -237,7 +240,7 @@ function webhook2api_setValue(&$data, $target_path, $value) {
|
||||||
if (is_array($data[$element])) {
|
if (is_array($data[$element])) {
|
||||||
webhook2api_setValue($data[$element], $target_path, $value);
|
webhook2api_setValue($data[$element], $target_path, $value);
|
||||||
} else {
|
} else {
|
||||||
// error - bad spec (path element is not array)
|
civiproxy_log("Webhook2API.setValue: path node is not an array!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,6 +248,6 @@ function webhook2api_setValue(&$data, $target_path, $value) {
|
||||||
webhook2api_setValue($data, [$target_path], $value);
|
webhook2api_setValue($data, [$target_path], $value);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error - bad spec
|
civiproxy_log("Webhook2API.setValue: path neither string nor array!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue