/** * Send reviews to Slack * * @param array $reviews list of reviews to send * @return boolean successful sending */ public function sendReviews($reviews) { if (!is_array($reviews) || !count($reviews)) { return false; } if (!isset($this->slackSettings['endpoint'])) { if ($this->logger) { $this->logger->error('Reviewer: you should set endpoint in Slack settings'); } return false; } $config = ['username' => 'TJ Reviewer', 'icon' => 'https://i.imgur.com/GX1ASZy.png']; 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'] ? "★" : "☆"; } try { if ($this->firstTime === false) { $slack->attach(['fallback' => "{$ratingText} {$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'), 'fields' => [['title' => $review['title'], 'value' => $review['content']], ['title' => 'Rating', 'value' => $ratingText, 'short' => true], ['title' => 'Author', 'value' => "<{$review['author']['uri']}|{$review['author']['name']}>", 'short' => true], ['title' => 'Version', 'value' => $review['application']['version'], 'short' => true], ['title' => 'Country', 'value' => $review['country'], 'short' => true]]])->send(); } $this->storage->set("r{$review['id']}", 1); } catch (Exception $e) { if ($this->logger) { $this->logger->error('Reviewer: exception while sending reviews', ['exception' => $e]); } } } return true; }
/** * @expectedException \AdammBalogh\KeyValueStore\Exception\InternalException */ public function testFlushWithNotReadableDatabase() { $flintstoneDb = Flintstone::load('okke', ['dir' => vfsStream::url('root')]); $kvs = new KeyValueStore(new FileAdapter($flintstoneDb)); chmod(vfsStream::url('root/okke.dat'), 0500); $kvs->flush(); }
public static function getProvider($type, $params, $accessTokenParams = []) { $provider = new Pdffiller($params); $tz = 'America/New_York'; $kvs = new KeyValueStore(new FileAdapter(Flintstone::load('usersDatabase', ['dir' => '/tmp']))); $accessTokenKey = 'access_token'; if (!$kvs->has($accessTokenKey)) { $accessToken = $provider->getAccessToken(self::$names[$type], $accessTokenParams); $liveTimeInSec = Carbon::createFromTimestamp($accessToken->getExpires(), $tz)->diffInSeconds(Carbon::now($tz)); $kvs->set($accessTokenKey, $accessToken->getToken()); $kvs->expire($accessTokenKey, $liveTimeInSec); $accessTokenString = $accessToken->getToken(); } else { $accessTokenString = $kvs->get($accessTokenKey); } $provider->setAccessTokenHash($accessTokenString); return $provider; }
public function put($key, $value) { $this->cache->set($key, $value); }
protected function runOperationsTests($config) { $db = new Flintstone('test', $config); $arr = array('foo' => "new\nline"); $this->assertFalse($db->get('foo')); $db->set('foo', 1); $db->set('name', 'john'); $db->set('arr', $arr); $this->assertEquals(1, $db->get('foo')); $this->assertEquals('john', $db->get('name')); $this->assertEquals($arr, $db->get('arr')); $db->set('foo', 2); $this->assertEquals(2, $db->get('foo')); $this->assertEquals('john', $db->get('name')); $this->assertEquals($arr, $db->get('arr')); $db->delete('name'); $this->assertFalse($db->get('name')); $this->assertEquals($arr, $db->get('arr')); $keys = $db->getKeys(); $this->assertEquals(2, count($keys)); $this->assertEquals('foo', $keys[0]); $this->assertEquals('arr', $keys[1]); $data = $db->getAll(); $this->assertEquals(2, count($data)); $this->assertEquals(2, $data['foo']); $this->assertEquals($arr, $data['arr']); $db->flush(); $this->assertFalse($db->get('foo')); $this->assertFalse($db->get('arr')); $this->assertEquals(0, count($db->getKeys())); $this->assertEquals(0, count($db->getAll())); unlink($db->getDatabase()->getPath()); }
/** * Unload the test database and remove */ public function tearDown() { Flintstone::unload($this->dbName); @unlink($this->db->getFile()); clearstatcache(); }
public function tearDown() { $this->flintstoneDb->flush(); Flintstone::unload('testDb'); unset($this->kvs); }