Example #1
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;
 }
Example #2
0
 /**
  * @covers \Klout\Model\Identity::setNetworkName
  * @covers \Klout\Model\Identity::getNetworkName
  */
 public function testGetNetworkName()
 {
     $identity = new Identity();
     $this->assertNull($identity->getNetworkName());
     $identity->setNetworkName($this->identityData['network']);
     $this->assertEquals($this->identityData['network'], $identity->getNetworkName());
 }
Example #3
0
 /**
  * Add a new Identity to the Collection of identities for the user
  *
  * @param  Klout\Model\Identity $identity
  * @return \Klout\Model\User
  */
 public function addIdentity(Klout\Model\Identity $identity)
 {
     $this->identities[$identity->getNetworkName()] = $identity;
     return $this;
 }