/** * @covers \Klout\Model\Score::populate */ public function testPopulateWithoutScoreDelta() { $data = $this->scoreData; unset($data['scoreDelta']); $score = new Score(); $score->populate($this->kloutId, $data); $this->assertEquals($this->kloutId, $score->getKloutId()); $this->assertEquals($this->scoreData['score'], $score->getScore()); $this->assertEquals($this->scoreData['bucket'], $score->getBucket()); $this->assertNull($score->getDeltas()); }
/** * Get the Klout user's score * * @param Numeric $kloutId * @return \Klout\Model\Score */ public function getScoreByKloutId($kloutId) { $this->assertValidUserIdForNetwork(self::NETWORK_KLOUT, $kloutId); /* @var $request Request */ $request = $this->client->get('user.json/' . $kloutId . '/score'); try { $scoreData = $request->send()->json(); $score = new Score(); $score->populate($kloutId, $scoreData); } catch (HttpRequestException $e) { $this->handleHttpRequestException($e); } return $score; }
/** * 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; }