コード例 #1
0
 /**
  * Make the call
  *
  * @param  string $url           API url to call
  * @param  array  $parameters    Parameters for the request
  * @param  bool   $authenticate  Shall we use authentication?
  * @param  bool   $usePost       Uses POST method instead of GET
  *
  * @return mixed
  *
  * @throws InvalidArgumentException   if the type provided is not supported
  * @throws TwitterApiServerException  if the request fails for any reason
  * @throws RuntimeException           if the xml response is invalid
  */
 protected function doCall($url, $parameters = array(), $authenticate = false, $usePost = true, $type = 'entity')
 {
     $response = $this->server->request(sprintf('%s.xml', $url), $parameters, $usePost ? 'POST' : 'GET');
     switch ($type) {
         case 'entity':
             $dom = new DOMDocument();
             $dom->loadXML($response);
             return TwitterEntity::createFromXml($dom);
             break;
         case 'boolean':
             if (!($xml = @simplexml_load_string($response))) {
                 throw new RuntimeException('XML error');
             }
             return (bool) ((string) $xml === 'true');
             break;
         case 'hash':
             if (!($xml = @simplexml_load_string($response))) {
                 throw new RuntimeException('XML error');
             }
             return (array) $xml;
             break;
         case 'search_results':
             return TweetCollection::createFromJSON($response);
             break;
         default:
             throw new InvalidArgumentException(sprintf('Type "%s" is not supported', $type));
             break;
     }
 }
コード例 #2
0
<?php

require_once dirname(__FILE__) . '/../../vendor/lime/lime.php';
require_once dirname(__FILE__) . '/../../lib/TweetCollection.class.php';
$t = new lime_test(3, new lime_output_color());
// Sample data
$xmlTweets = DOMDocument::load(dirname(__FILE__) . '/xml/server/statuses/replies.xml');
// createFromXml()
$t->diag('createFromXML()');
try {
    $tweets = TweetCollection::createFromXML($xmlTweets);
    $t->pass('createFromXml() creates a TweetCollection instance from an XML element without throwing an exception');
} catch (Exception $e) {
    $t->fail('createFromXml() creates a TweetCollection instance from an XML element without throwing an exception');
    $t->diag(sprintf('    %s: %s', get_class($e), $e->getMessage()));
}
$t->isa_ok($tweets, 'TweetCollection', 'createFromXML() creates a TweetCollection instance');
$t->is($tweets[0]->text, "@n1k0 Les gens ne supportent pas les bonnes intentions parce qu'ils se sentent coupables de ne rien faire de leur côté. #home, c'est bien.", 'createFromXml() retrieves first tweet ok');