Пример #1
0
$XBOPTS['realm'] = "";
//$XBOPTS['profile'] = true;
global $XBAR;
$XBAR = new CrossBar($XBOPTS);
// See if we can make a connection
$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);