Пример #1
0
function WebHelpDesk_Command($resource = '', $params = array(), $qualifier = null, $configName = CONFIG_Tech_Key)
{
    if (is_null($resource) || strlen($resource) == 0) {
        throw new \Exception('No request resource specified');
    }
    $config = testConfig($configName);
    if (is_array($config) && isset($config[CONFIG_base])) {
        $reqParams = array("login" => $config[CONFIG_user], "password" => $config[CONFIG_password]);
        if (is_array($params)) {
            $reqParams = array_merge($params, $reqParams);
        }
        $q = '';
        if (is_string($qualifier)) {
            $q = "&" . Qualifier_Operation::OP . "=" . $qualifier;
        }
        $url = $config[CONFIG_base] . "/ra/" . $resource . "?" . http_build_query($reqParams) . $q;
        echo $url . PHP_EOL;
        list($data, $headers) = performGET($url);
        if ($data != false) {
            $json = json_decode($data, true);
            if (json_last_error() != 0) {
                throw new \Exception(jsonErrorString(json_last_error()));
            }
            return array($json, $headers);
        }
    }
    throw new \Exception('Please update the configuration for ' . $configName);
}
Пример #2
0
function testConfig($name = '')
{
    $filename = test_path(CONFIG);
    if (test_isFile(CONFIG) == false) {
        $config = array(CONFIG_Client_Key => array(CONFIG_name => "My Web Helpdesk", CONFIG_base => "https://localhost/helpdesk/WebObjects/Helpdesk.woa", CONFIG_user => "client", CONFIG_password => "password"), CONFIG_Tech_Key => array(CONFIG_name => "My Web Helpdesk", CONFIG_base => "https://localhost/helpdesk/WebObjects/Helpdesk.woa", CONFIG_user => "technician", CONFIG_password => "password", CONFIG_apikey => "apikey"));
        $returnValue = file_put_contents($filename, json_encode($config, JSON_PRETTY_PRINT));
        if (json_last_error() != 0) {
            throw new \Exception(jsonErrorString(json_last_error()));
        }
        echo "Created new configuration at {$filename}, please update with your parameters" . PHP_EOL . PHP_EOL;
        exit(1);
    }
    $config = json_decode(file_get_contents($filename), true);
    if (json_last_error() != 0) {
        throw new \Exception(jsonErrorString(json_last_error()));
    }
    if (is_array($config) && isset($config[$name])) {
        return $config[$name];
    }
    return null;
}