示例#1
0
 /**
  * @covers \Klout\Model\Identity::setKloutId
  * @covers \Klout\Model\Identity::getKloutId
  */
 public function testGetKloutId()
 {
     $identity = new Identity();
     $this->assertNull($identity->getKloutId());
     $identity->setKloutId($this->kloutId);
     $this->assertEquals($this->kloutId, $identity->getKloutId());
 }
示例#2
0
 /**
  * Get a Klout\Model\User by their Klout ID.
  *
  * @param  String                    $kloutId
  * @param  Boolean                   $fullData
  * @throws InvalidArgumentException
  * @throws ResourceNotFoundException
  * @return \Klout\Model\User
  */
 public function getUser($kloutId, $fullData = true)
 {
     $this->assertValidUserIdForNetwork(self::NETWORK_KLOUT, $kloutId);
     try {
         // Get the data for the user
         $requests = array($this->client->get('user.json/' . $kloutId));
         if ($fullData) {
             $requests[] = $this->client->get('user.json/' . $kloutId . '/influence');
             $requests[] = $this->client->get('user.json/' . $kloutId . '/topics');
         }
         $responses = $this->client->send($requests);
     } catch (HttpRequestException $e) {
         // If there are partial responses then the method
         // will return those responses
         $responses = $this->handleHttpRequestException($e);
     }
     $influenceData = array();
     $topicsData = array();
     $userData = array();
     /* @var $response Response */
     foreach ($responses as $response) {
         if (stripos($response->getEffectiveUrl(), '/influence') !== false) {
             $influenceData = $response->json();
         } elseif (stripos($response->getEffectiveUrl(), '/topics') !== false) {
             $topicsData = $response->json();
         } else {
             $userData = $response->json();
         }
     }
     if (empty($userData)) {
         throw new ResourceNotFoundException('Could not find the user information for Klout user ID: ' . $kloutId);
     }
     $user = new User();
     $user->populate($userData, $influenceData, $topicsData);
     $identity = new Identity();
     $identity->setKloutId($kloutId);
     $identity->setNetworkName(self::NETWORK_KLOUT);
     $identity->setNetworkUserId($kloutId);
     $user->addIdentity($identity);
     return $user;
 }