Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Commit

Permalink
Guzzle-related code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Chekalskiy committed Jul 23, 2015
1 parent 9d2fa73 commit cfafb90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "@stable",
"guzzlehttp/guzzle": "~6.0",
"maknz/slack": "~1.7",
"fire015/flintstone": "~1.9",
"psr/log": "~1.0"
Expand Down
17 changes: 8 additions & 9 deletions src/Reviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Flintstone\Flintstone;
use Flintstone\FlintstoneException;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Pool as Pool;
use GuzzleHttp\Promise;
use Maknz\Slack\Client as Slack;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -153,27 +153,26 @@ public function getReviewsByCountry($appId, $countryCode, $countryName)
{
$reviews = [];

$requests = [];
$promises = [];
for ($i = 1; $i <= $this->maxPages; $i++) {
array_push($requests, $this->client->createRequest("GET", "https://itunes.apple.com/{$countryCode}/rss/customerreviews/page={$i}/id={$appId}/sortBy=mostRecent/json"));
$promises['page' . $i] = $this->client->getAsync("https://itunes.apple.com/{$countryCode}/rss/customerreviews/page={$i}/id={$appId}/sortBy=mostRecent/json");
}

try {
$responses = Pool::batch($this->client, $requests);
$responses = Promise\unwrap($promises);

foreach ($responses->getSuccessful() as $page => $response) {
$realPage = $page + 1;
$reviewsData = $response->json();
for ($page = 1; $page <= $this->maxPages; $page++) {
$reviewsData = json_decode((string) $responses['page' . $page]->getBody(), true);

if (!isset($reviewsData['feed']) || !isset($reviewsData['feed']['entry']) || count($reviewsData['feed']['entry']) == 0) {
// Received empty page
if ($this->logger) {
$this->logger->debug("#{$appId}: Received 0 entries for page {$realPage} in {$countryName}");
$this->logger->debug("#{$appId}: Received 0 entries for page {$page} in {$countryName}");
}
} else {
if ($this->logger) {
$countEntries = count($reviewsData['feed']['entry']) - 1;
$this->logger->debug("#{$appId}: Received {$countEntries} entries for page {$realPage} in {$countryName}");
$this->logger->debug("#{$appId}: Received {$countEntries} entries for page {$page} in {$countryName}");
}

$applicationData = [];
Expand Down

0 comments on commit cfafb90

Please sign in to comment.