Beispiel #1
0
<?php

require dirname(__FILE__) . '/../Brush.php';
use Brush\Accounts\Account;
use Brush\Accounts\Developer;
use Brush\Exceptions\BrushException;
$account = new Account('<user session key>');
$developer = new Developer('<developer key>');
try {
    // retrieve the first 10 account pastes
    $pastes = $account->getPastes($developer, 10);
    // print out the name of each paste and its content
    foreach ($pastes as $paste) {
        echo '## ', $paste->getTitle(), PHP_EOL, PHP_EOL;
        echo $paste->getContent($developer), PHP_EOL, PHP_EOL;
    }
} catch (BrushException $e) {
    echo $e->getMessage(), PHP_EOL;
}
Beispiel #2
0
 /**
  * Retrieve a user's information from their account.
  * @param \Brush\Accounts\Account $account The account whose corresponding information to retrieve.
  * @param \Brush\Accounts\Developer $developer The developer account to use for the request.
  * @return \Brush\Accounts\User A user instance containing the account's information.
  */
 public static final function fromAccount(Account $account, Developer $developer)
 {
     $key = $account->getCacheKey($developer);
     if (self::getCache()->isCached($key)) {
         // user cache hit
         return self::getCache()->get($key);
     }
     $pastebin = new ApiRequest($developer, self::ENDPOINT);
     $pastebin->setOption('userdetails');
     $account->sign($pastebin->getRequest(), $developer);
     $user = self::fromXml(ApiRequest::toElement($pastebin->send()));
     self::getCache()->set($key, $user);
     return $user;
 }
Beispiel #3
0
     * Authenticate a request from this user.
     * @param \Crackle\Requests\POSTRequest $request The request to authenticate.
     * @param \Brush\Accounts\Developer $developer The developer account to use if the key needs to be fetched.
     */
    public function sign(POSTRequest $request, Developer $developer)
    {
        $request->getVariables()->set('api_user_key', $this->getKey($developer));
    }
    /**
     * Retrieve pastes created by this account in descending order of date created.
     * @param \Brush\Accounts\Developer $developer The developer account to use for the request.
     * @param int $limit The maximum number of pastes to retrieve. 1 <= $number <= 1000. Defaults to 50.
     * @throws \Brush\Exceptions\ArgumentException If the number of pastes is outside the allowed range.
     * @return \Brush\Pastes\Paste[] This account's pastes, up to the limit.
     */
    public function getPastes(Developer $developer, $limit = 50)
    {
        // check 1 <= $number <= 1000
        if ($limit < 1 || $limit > 1000) {
            throw new ArgumentException('The number of pastes must be in the range 1 to 1000 inclusive.');
        }
        $pastebin = new ApiRequest($developer, self::PASTES_ENDPOINT);
        $pastebin->setOption('list');
        $request = $pastebin->getRequest();
        $this->sign($request, $developer);
        $request->getVariables()->set('api_results_limit', $limit);
        return Paste::parsePastes($pastebin->send(), $this);
    }
}
Account::initialise();