示例#1
0
文件: api.php 项目: pritcham/XenAPI
 * (at your option) any later version.
 *
 * XenAPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// To change the API key, replace the REPLACE_THIS_WITH_AN_API_KEY with your desired API key.
$restAPI = new RestAPI('REPLACE_THIS_WITH_AN_API_KEY');
# DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS
# YOU REALLY KNOW WHAT ARE YOU DOING
// Process the request
if ($restAPI->getAPIKey() !== NULL && $restAPI->isDefaultAPIKey()) {
    // API is set but not changed from the default API key.
    $restAPI->throwError(17);
} else {
    if ($restAPI->getAPIKey() !== NULL && !$restAPI->hasRequest('hash') && !$restAPI->isPublicAction()) {
        // Hash argument is required and was not found, throw error.
        $restAPI->throwError(3, 'hash');
    } else {
        if (!$restAPI->getHash() && !$restAPI->isPublicAction()) {
            // Hash argument is empty or not set, throw error.
            $restAPI->throwError(1, 'hash');
        } else {
            if (!$restAPI->isAuthenticated() && !$restAPI->isPublicAction()) {
                // Hash is not valid and action is not public, throw error.
                $restAPI->throwError(6, $restAPI->getHash(), 'hash');
            } else {