Example #1
0
 /**
  * @covers \Klout\Model\Topic::createTopicCollection
  */
 public function testCreateTopicCollectionWithInvalidData()
 {
     $this->setExpectedException('InvalidArgumentException');
     $data = $this->topicData;
     unset($data[1]['id']);
     $collection = Topic::createTopicCollection($data);
     $this->assertInstanceOf('Klout\\Collection\\Topic', $collection);
     $this->assertCount(3, $collection);
 }
Example #2
0
 /**
  * Populate the object with an array of data
  * Allows passing in the influence data array from the API
  * Allows passing in the topics data array from the API
  *
  * @param  array             $userData
  * @param  array             $influenceData (optional)
  * @param  array             $topicsData    (optional)
  * @return \Klout\Model\User
  */
 public function populate(array $userData, array $influenceData = null, array $topicsData = null)
 {
     if (empty($userData) && (!empty($influenceData) || !empty($topicsData))) {
         throw new InvalidArgumentException('Must have userData if you have influence or topic data.');
     } elseif (empty($userData)) {
         return $this;
     }
     if (empty($userData['kloutId'])) {
         throw new InvalidArgumentException('userData does not contain a kloutId.');
     }
     $this->setKloutId($userData['kloutId']);
     $this->setNickname($userData['nick']);
     $score = new Score();
     $scoreData = array();
     if (!empty($userData['score'])) {
         // Need to change the score data becauce the call to user.json
         // will return the 'score' as an array but the user.json/score call
         // will return the score data in a different format
         $scoreData = array('score' => $userData['score']['score'], 'bucket' => isset($userData['score']['bucket']) ? $userData['score']['bucket'] : null, 'scoreDeltas' => $userData['scoreDeltas']);
         $score->populate($userData['kloutId'], $scoreData);
     }
     $this->setScore($score);
     $influencers = new UserCollection();
     $influencees = new UserCollection();
     if (!empty($influenceData)) {
         if (isset($influenceData['myInfluencers']) && !empty($influenceData['myInfluencers'])) {
             $influencersData = array();
             foreach ($influenceData['myInfluencers'] as $value) {
                 if (empty($value['entity']) || empty($value['entity']['payload'])) {
                     continue;
                 }
                 $influencersData[] = array('userData' => $value['entity']['payload']);
             }
             $influencers = self::createUserCollection($influencersData);
         }
         if (isset($influenceData['myInfluencees']) && !empty($influenceData['myInfluencees'])) {
             $influenceesData = array();
             foreach ($influenceData['myInfluencees'] as $value) {
                 if (empty($value['entity']) || empty($value['entity']['payload'])) {
                     continue;
                 }
                 $influenceesData[] = array('userData' => $value['entity']['payload']);
             }
             $influencees = self::createUserCollection($influenceesData);
         }
     }
     $this->setInfluencers($influencers);
     $this->setInfluencees($influencees);
     if (!empty($topicsData)) {
         $this->setTopics(Topic::createTopicCollection($topicsData));
     }
     return $this;
 }