/** * Generated by APIlite * https://gitea.tpsoft.org/TPsoft.org/APIlite * * */ class apiName; ?> { endpoint = endpoint, 0, 4) == 'http' ? '"%s"' : '%s', $this->endpoint); ?>; /* ---------------------------------------------------- * General API call */ call(method, data, callback) { var xhttp = new XMLHttpRequest(); xhttp.withCredentials = true; xhttp.onreadystatechange = function() { if (this.readyState == 4) { if (this.status == 200) { if (callback != null) callback(JSON.parse(this.responseText)); } else { if (callback != null) callback({'status': 'ERROR', 'message': 'HTTP STATUS ' + this.status}); } } } var form_data = new FormData(); Object.keys(data).forEach(key => { let val = data[key]; if (typeof val == 'object') val = JSON.stringify(val); form_data.append(key, val); }); xhttp.open('POST', this.endpoint + '?action=' + method); xhttp.send(form_data); } callPromise(method, data) { return new Promise((resolve, reject) => { this.call(method, data, function(response) { if (response.status == 'OK') { resolve(response.data); } else { reject(response.msg); } }); }) } /* ---------------------------------------------------- * API actions */ help() { return this.callPromise('__HELP__', {}); } methods)) foreach ($this->methods as $method) { echo "\t".$method['name'].'('.implode(', ', array_map(function($param) { return $param['name']; }, $method['params'])).') {'; echo "\n\t\treturn this.callPromise('".$method['name']."', {".implode(', ', array_map(function($param) { return $param['name'].': '.$param['name']; }, $method['params']))."});"; echo "\n\t}\n\n"; } ?> }; export default new apiName; ?>();