private function parseUser($entry) { $user = new TwitterUser(); $user->setUserID($entry['id_str']); $user->setName('@' . $entry['screen_name']); $user->setImageURL(ImageLoader::cacheImage(IS_SECURE ? $entry['profile_image_url_https'] : $entry['profile_image_url'], array())); return $user; }
public function getUser($login) { if (empty($login)) { return new AnonymousUser(); } //use the cache if available if ($this->useCache) { $cacheFilename = "user_$login"; if ($this->cache === NULL) { $this->cache = new DiskCache(CACHE_DIR . "/Twitter", $this->cacheLifetime, TRUE); $this->cache->setSuffix('.json'); $this->cache->preserveFormat(); } if ($this->cache->isFresh($cacheFilename)) { $data = $this->cache->read($cacheFilename); } else { //cache isn't fresh, load the data if ($data = $this->oauthRequest('GET', $this->API_URL .'/users/show.json', array('screen_name'=>$login))) { $this->cache->write($data, $cacheFilename); } } } else { //load the data $data = $this->oauthRequest('GET', $this->API_URL . '/users/show.json', array('screen_name'=>$login)); } // make the call if ($data) { $json = @json_decode($data, true); if (isset($json['screen_name'])) { $user = new TwitterUser($this); $user->setTwitterUserID($json['id']); $user->setUserID($json['screen_name']); $user->setFullName($json['name']); return $user; } } return false; }
public static function parse($response) { if (Tag::setof($tag, $response, "error")) { throw new Exception($tag->value()); } if (Tag::setof($tag, $response, "status")) { $hash = $tag->hash(); $obj = new self(); $obj->user(TwitterUser::parse($hash["user"])); unset($hash["user"]); return $obj->cp($hash); } throw new Exception("invalid data"); }
public static function parse($response) { if (Tag::setof($tag, $response, "error")) { throw new Exception($tag->value()); } $result = array(); if (Tag::setof($tag, $response, "direct_message")) { $re = $status->hash(); $obj = new self(); $obj->sender(TwitterUser::parse($re["sender"])); $obj->recipient(TwitterUser::parse($re["recipient"])); unset($re["recipient"], $re["sender"]); return $obj->cp($re); } throw new Exception("invalid data"); }
/** * Create an instance of Tweet by passing an array of properties. * This is mainly used by the TwitterRest to convert it's raw * feed data into a more usable collection of Tweet instances. * * @param string[] $args An array of properties to turn into a Tweet * * @return Tweet */ public static function create(array $args) { $instance = new self(); foreach ($args as $property => $value) { if (in_array($property, self::$properties)) { if ($property == 'user') { $instance->{$property} = TwitterUser::create($value); } elseif ($property == 'created_at') { $instance->{$property} = new \DateTime($value); } else { $instance->{$property} = $value; } } } if (array_key_exists('retweeted_status', $args)) { $instance->retweeted = true; } return $instance; }
<?php require_once dirname(__FILE__) . '/../../vendor/lime/lime.php'; require_once dirname(__FILE__) . '/../../lib/TwitterUser.class.php'; $t = new lime_test(8, new lime_output_color()); // Sample data $xmlUser = DOMDocument::load(dirname(__FILE__) . '/xml/server/users/show/6896142.xml'); // createFromXml() $t->diag('createFromXML()'); try { $message = TwitterUser::createFromXML($xmlUser); $t->pass('createFromXml() creates a TwitterUser instance from an XML element without throwing an exception'); } catch (Exception $e) { $t->fail('createFromXml() creates a TwitterUser instance from an XML element without throwing an exception'); $t->diag(sprintf(' %s: %s', get_class($e), $e->getMessage())); } $t->isa_ok($message, 'TwitterUser', 'createFromXML() creates a TwitterUser instance'); $t->is($message->id, 6896142, 'createFromXML() populated XML nodes values to object properties'); $t->is($message->name, 'Antoine Cailliau', 'createFromXML() retrieves name property'); $t->is($message->screen_name, 'ancailliau', 'createFromXML() retrieves name property'); $t->is($message->location, 'Louvain-la-Neuve', 'createFromXML() retrieves name property'); $t->isa_ok($message->status, 'Tweet', 'createFromXML() converted status as a Tweet'); $t->is($message->status->text, 'Damn, two books, one topic. One consider light is a continuum and the other a quantum... Two differents derivations to understand and map...', 'createFromXML() created the Tweet correctly');
/** * ブロックしたユーザを解除する * * @param string $user_id * @return TwitterUser */ public function blocks_destroy($user_id) { $this->do_post("blocks/destroy/" . $user_id . ".xml"); return TwitterUser::parse($this->body()); }