-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhosting_restapi.site-config.inc
78 lines (64 loc) · 1.47 KB
/
hosting_restapi.site-config.inc
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
<?php
/**
* @file
* Hosting REST API functions, and Drupal hooks.
*/
/**
* Implements the 'site/config' API.
*/
function hosting_restapi_site_config() {
$method = strtolower($_SERVER['REQUEST_METHOD']);
$f = 'hosting_restapi_site_config_' . $method;
try {
if (function_exists($f)) {
$result = $f();
}
else {
$result = array(
'status' => 'error',
'message' => 'Unknown method for site_config: ' . $_SERVER['REQUEST_METHOD'],
);
}
}
catch (Exception $e) {
$result = array(
'status' => 'error',
'message' => $e->getMessage(),
);
}
echo json_encode($result);
drupal_exit();
}
/**
* Implements the 'site/config GET' API.
*/
function hosting_restapi_site_config_get() {
$url = $_GET['url'];
$token = $_GET['token'];
if (! $url) {
throw new Exception(t('The "url" parameter was empty.'));
}
if (! $token) {
throw new Exception(t('The "token" parameter was empty.'));
}
$invoice_id = hosting_restapi_get_invoice_id_from_token($url, $token);
if (! $invoice_id) {
throw new Exception(t('Invalid token.'));
}
$api = hosting_restapi_civicrmapi();
$api->Symbiocivicrm->Getconfig([
'invoice_id' => $invoice_id,
]);
$settings = $api->result->values;
if ($api->is_error()) {
return [
'status' => 'error',
'invoice_id' => $invoice_id,
'data' => $api->errorMsg(),
];
}
return [
'status' => 'success',
'data' => $settings,
];
}