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

Commit

Permalink
Improve design of notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Chekalskiy committed Jun 3, 2015
1 parent 45b0fbf commit 88e11be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "@stable",
"maknz/slack": "~1.5",
"maknz/slack": "~1.7",
"fire015/flintstone": "~1.9",
"psr/log": "~1.0"
},
Expand Down
30 changes: 17 additions & 13 deletions src/Reviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ public function getReviewsByCountry($appId, $countryCode, $countryName)

$applicationData = [];
foreach ($reviewsData['feed']['entry'] as $reviewEntry) {
if (isset($reviewEntry['im:name']) && isset($reviewEntry['im:image'])) {
if (isset($reviewEntry['im:name']) && isset($reviewEntry['im:image']) && isset($reviewEntry['link'])) {
// First element is always an app metadata
$applicationData = [
'name' => $reviewEntry['im:name']['label'],
'image' => end($reviewEntry['im:image'])['label']
'image' => end($reviewEntry['im:image'])['label'],
'link' => $reviewEntry['link']['attributes']['href']
];
continue;
}
Expand Down Expand Up @@ -260,27 +261,30 @@ public function sendReviews($reviews)
return false;
}

$config = [
'username' => 'Reviewer',
'icon_emoji' => ':rocket:'
];

if (isset($this->slackSettings['channel'])) {
$config['channel'] = $this->slackSettings['channel'];
}

$slack = new Slack($this->slackSettings['endpoint'], $config);

foreach ($reviews as $review) {
$ratingText = '';
for ($i = 1; $i <= 5; $i++) {
$ratingText .= ($i <= $review['rating']) ? "" : "";
}

$config = [
'username' => $review['application']['name'],
'icon' => $review['application']['image']
];

if (isset($this->slackSettings['channel'])) {
$config['channel'] = $this->slackSettings['channel'];
}

try {
$slack = new Slack($this->slackSettings['endpoint'], $config);

if ($this->firstTime === false) {
$slack->attach([
'fallback' => "{$ratingText} {$review['author']['name']}: {$review['title']}{$review['content']}",
'author_name' => $review['application']['name'],
'author_icon' => $review['application']['image'],
'author_link' => $review['application']['link'],
'color' => ($review['rating'] >= 4) ? 'good' : (($review['rating'] == 3) ? 'warning' : 'danger'),
'pretext' => "{$ratingText} Review for {$review['application']['version']} from <{$review['author']['uri']}|{$review['author']['name']}> ({$review['country']})",
'fields' => [
Expand Down

0 comments on commit 88e11be

Please sign in to comment.