Ejemplo n.º 1
0
<?php

require './inc/config.inc.php';
require './inc/header.php';
// @todo add proper error reporting
if (empty($_VARS['week_num']) || empty($_VARS['league_key'])) {
    echo 'Error: A week number and league key is required for matchup information';
    exit;
}
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
    exit;
}
$query = "league/{$_VARS['league_key']}/scoreboard;week={$_VARS['week_num']}/matchups/teams/roster;week={$_VARS['week_num']}/players/stats;type=week;week={$_VARS['week_num']}";
// For single team
// $query = "team/{$team_key}/roster;week={$week_num}/players/stats;type=week;week={$week_num}
$minfo = $m->retrieve($query);
// @todo fix questionable error handling
if (empty($minfo)) {
    echo "FAIL";
    exit;
}
echo '<h1>Matchup information for week ', $minfo->league->scoreboard->week, '</h1>';
// @todo remove this hack
// @todo show more info
foreach ($minfo->league->scoreboard->matchups->matchup as $key => $values) {
    $team_name_0 = $values->teams->team[0]->name;
    $team_name_1 = $values->teams->team[1]->name;
    // @todo Assuming one manager for now
<?php

require './inc/config.inc.php';
require './inc/header.php';
if (empty($_GET['lk'])) {
    echo 'A league key is required', PHP_EOL;
    exit;
}
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
    exit;
}
// @todo Make output prettier and not print_r() everywhere
try {
    echo '<h3>Local Messages</h3>';
    $rows = $m->getLocalMessages($_GET['lk']);
    foreach ($rows as $row) {
        echo '<p>Subject: ', $row['subject'], '</p>';
        echo '<p>', nl2br(makeClickableLinks($row['text'])), '</p>';
        echo '<p>By: ', $row['display_name'], ' (', $row['team_name'], ') on ', date('F d, Y', $row['timestamp']);
        echo '<hr />';
    }
    // @todo test this, make it possible to export
    //exportToCsv( (array) $rows, '/tmp/tmp.csv');
    echo '<h3>Remote Messages</h3>';
    echo '<p>Disabled, See code.</p>';
    /*
    echo '<pre>';
    $rows = $m->getMessages( 0, 100, $_GET['lk'] );
Ejemplo n.º 3
0
<?php

require './inc/config.inc.php';
require './inc/header.php';
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo "ERROR: Response: " . $e->lastResponse . PHP_EOL;
    exit;
}
// @todo make output prettier instead of print_r() everywhere
try {
    $info = $m->getStoredInfo();
    echo '<h3>Stored authentication information</h3>', PHP_EOL;
    echo '<p>GUID of user: '******'xoauth_yahoo_guid'], '</p>', PHP_EOL;
    echo '<p>Additional information is saved.</p>';
    echo '<h3>All leagues you have played in</h3>', PHP_EOL;
    $ids = $m->getLeagueIds(FALSE);
    echo '<dl>';
    foreach ($ids as $id) {
        // @todo A few are missing this, research this
        if (FALSE === strpos($id['url'], 'http://')) {
            $id['url'] = 'http://football.fantasysports.yahoo.com' . $id['url'];
        }
        echo '<dt><a href="', $id['url'], '">', $id['name'], '</a></dt>', PHP_EOL;
        echo '<dd>League Key: ', $id['league_key'], ' with ', $id['num_teams'], ' teams</dd>', PHP_EOL;
        // @todo Somtimes an empty object, research this, because league has not started? What does 'update' mean?
        $time = $id['league_update_timestamp'];
        if (is_object($time)) {
            $time = 'unknown';
        } else {
Ejemplo n.º 4
0
<?php

require './inc/config.inc.php';
require './inc/header.php';
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
    exit;
}
$ids = $m->getLeagueIds(TRUE);
if (!$ids) {
    echo 'Error: Unable to find league ids for you.', PHP_EOL;
    exit;
}
if (isset($_GET['a']) && $_GET['a'] === '1' && isset($_GET['lk'])) {
    echo 'Hello, I am inserting messages now. ', PHP_EOL;
    $count = 0;
    $data = $m->getMessages(1, 200, $_GET['lk']);
    foreach ($data->league->messages->message as $message) {
        if ($m->insertMessage($_GET['lk'], $message)) {
            $count++;
        } else {
            // @todo :)
            echo 'FAIL', PHP_EOL;
        }
    }
    echo 'I inserted ', $count, ' messages', PHP_EOL;
}
$linfos = $m->getLeagueInfo($ids);
// @todo reduce number of rest calls
<?php

/*	Authentication flow. Requests and stores an OAuth based token. See the following for details:
	- http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html
*/
require './inc/config.inc.php';
try {
    $o = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $o->enableDebug();
    $m = new YahooMessageArchiver(FALSE);
    /********************************************************************************************************************************************
    	/** Stage #1: Request Token
    	/********************************************************************************************************************************************/
    if (empty($_GET['oauth_token']) && empty($_GET['oauth_verifier'])) {
        $response = $o->getRequestToken('https://api.login.yahoo.com/oauth/v2/get_request_token', APPLICATION_URL . $_SERVER['SCRIPT_NAME']);
        if ($response && is_array($response)) {
            if (!$m->saveRequest($response)) {
                echo "Unable to save response.";
                $m->printR($m->getLog());
                exit;
            }
            // @todo add error reporting
            if (empty($response['xoauth_request_auth_url'])) {
                $m->printR($m->getLog());
                echo 'Error: Did not receive authentication url. Hmm...', PHP_EOL;
                exit;
            }
            header('Location: ' . $response['xoauth_request_auth_url']);
            exit;
        } else {
            // @todo add error reporting
Ejemplo n.º 6
0
<?php

require './inc/config.inc.php';
require './inc/header.php';
define('PHP_SELF', htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'));
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
    exit;
}
$guid = $m->retrieve('http://social.yahooapis.com/v1/me/guid');
if (!$guid->value) {
    $guid = 'unknown';
} else {
    $guid = (string) $guid->value;
}
?>

<h1>Run Yahoo arbritrary REST commands</h1>
<p>Note: The "http://fantasysports.yahooapis.com/fantasy/v2/" part is optional and the default.</p>
<p>Note: We determined your GUID is: <strong><?php 
echo $guid;
?>
</strong> so replace {guid} with it where needed.</p>
<p>Note: This OAuth token is specific to Fantasy Sports although a lot of other (but not all) information can be accessed here too. Like your profile.</p>
<p>Examples:</p>
<ul>
 <li>View your team(s) info: users;use_login=1/games;game_keys=nfl,mlb,nba,nhl/teams [<a href="<?php 
echo PHP_SELF;
?>
<?php

// Types: add, drop, commish, trade
// @todo Do something useful here with transactions although they are archived at Yahoo alrady (no 100 limit)
require './inc/config.inc.php';
require './inc/header.php';
try {
    $m = new YahooMessageArchiver(TRUE);
} catch (OauthException $e) {
    echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL;
    exit;
}
// @todo verify lid format (x.x.x)
// @todo verify proper type (add, drop, commish, trade, ... others?)
$lid = empty($_GET['lid']) ? FALSE : trim($_GET['lid']);
$type = empty($_GET['type']) ? 'add' : trim($_GET['type']);
/*
if (empty($lids)) {
	$lids = $m->getLeagueIds( TRUE );
	if ( !$lids ) {
		echo 'Error: Unable to find league ids for you.', PHP_EOL;
		exit;
	}
}
*/
if (empty($lid)) {
    $lid = '238.l.627060';
    // public baseball league, for testing
}
$transactions = $m->retrieve("http://fantasysports.yahooapis.com/fantasy/v2/league/{$lid}/transactions;type={$type}");
echo "<p>Query is for league id '{$lid}' searching for transaction types '{$type}'</p>";