Пример #1
0
$USER_ID = '';
$ACCOUNT_ID = '';
$DEVICE_ID = '';
printf("{$bldblu}TEST: Authentication{$txtrst}\n");
if ($XBAR->is_authenticated()) {
    printf("{$bldgrn}PASS: Authentication Success.{$txtrst}\n\n");
    $TEMPLATE['name'] = 'supermegamega';
    $TEMPLATE['realm'] = 'supermega.example.com';
    $TEMPLATE['owner_id'] = $XBAR->auth_account_id;
    //Which ever user authed we will use that account is attached to
    $realm_id = $XBAR->get_account_id_by_realm($TEMPLATE['realm']);
    if (strlen($realm_id)) {
        printf("{$bldylw}WARN: {$bldred}Existing Account SKIPPING CREATION!{$txtrst}\n");
    } else {
        printf("{$bldblu}TEST: Create Account{$txtrst}\n");
        $resp = $XBAR->put_account($TEMPLATE);
        if ($resp['status'] == 'success') {
            printf("{$bldgrn}PASS: Account Creation Successful.{$txtrst}\n");
            $realm_id = $XBAR->get_account_id_by_realm($TEMPLATE['realm']);
        } else {
            printf("{$bldred}FAIL: Account Creation Failure.  ( {$bldpur} {$resp['message']} {$bldwht} ) {$txtrst}\n\n");
            //Without an account it's difficult to test the REST of the api. bwahaha I'm so punneh \(O.O)/
            exit(-1);
        }
    }
    $acct = $XBAR->get_account($realm_id);
    //Sanity check
    if ($TEMPLATE['realm'] != $acct['realm']) {
        printf("{$bldred}FATAL: {$bldwht}Response failed sanity check {$bldwht}( {$bldpur}possibly developers sanity too {$bldwht}){$txtrst}\n");
        exit(-1);
    }