/** * @param SlackConfig $slackConfig */ public function __construct(SlackConfig $slackConfig) { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $this->slackConfig = $slackConfig; $this->commander = new Commander($slackConfig->getApiKey(), $interactor); }
/** * Execute the console command. * * @return mixed */ public function fire() { // $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($_ENV['SLACK_KEY'], $interactor); $response = $commander->execute('channels.list'); $responseBody = $response->getBody(); if (!$responseBody or !$responseBody['ok']) { throw new Exception('Sth Error Happened!'); } foreach ($responseBody['channels'] as $chan) { if (!$chan['is_channel']) { continue; } $chanData = ['sid' => $chan['id'], 'name' => $chan['name'], 'created' => $chan['created'], 'creator' => $chan['creator'], 'purpose' => (object) $chan['purpose'], 'is_archived' => $chan['is_archived'], 'is_member' => $chan['is_member'], 'num_members' => $chan['num_members'], 'members' => $chan['members'], 'topic' => (object) $chan['topic']]; if ($channel = Channel::where('sid', $chan['id'])->first()) { foreach ($chanData as $k => $v) { $channel->{$k} = $v; } $channel->save(); } else { $chanData['latest'] = 0; Channel::create($chanData); } } }
/** * Execute the console command. * * @return mixed */ public function fire() { // $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($_ENV['SLACK_KEY'], $interactor); $channels = Channel::where('is_member', true)->get(); foreach ($channels as $channel) { $latest = $channel->latest ?: 0; do { $response = $commander->execute('channels.history', ['channel' => $channel->sid, 'oldest' => $latest, 'count' => 1000]); $responseBody = $response->getBody(); foreach ($responseBody['messages'] as $msg) { $latest = $msg['ts'] > $latest ? $msg['ts'] : $latest; $message = new Message(); foreach ($msg as $k => $v) { $message->{$k} = is_string($v) ? $v : (object) $v; } $message->channel = $channel->sid; $message->save(); } } while ($responseBody['has_more']); $channel->latest = $latest; $channel->save(); } }
/** * @return array */ protected function _getData() { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($this->_token, $interactor); $x = $commander->execute('channels.list'); return Arrays::value($x->getBody(), 'channels', []); }
/** * @return mixed */ protected function _getData() { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($this->_token, $interactor); $x = $commander->execute('channels.history', ['channel' => $this->_channelId, 'inclusive' => 1, 'count' => 100]); return Arrays::value($x->getBody(), 'messages', []); }
function report($message) { global $config; $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($config['slack'], $interactor); $commander->execute('chat.postMessage', ['username' => 'Backup validator', 'icon_emoji' => ':x:', 'channel' => '#server', 'text' => $message]); }
public function __construct($base_url, Logger $logger) { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $this->client = new Commander('xoxp-no-token', $interactor); $this->logger = $logger == null ? new Logger(LOG_DIR) : $logger; $this->base_url = $base_url; }
public function postSlack() { $request = $this->_getRequest()->request; $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($this->getConfigItem('slack', 'token'), $interactor); $response = $commander->execute('users.admin.invite', ['first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'set_active' => 'true', '_attempts' => 1]); return $this->slack($response); }
/** * Query the Slack API * * @param string $command * @param array $params * @return OauthTokenError|mixed */ public static final function execute($command, $params = []) { if (!Cache::has('slack_token')) { return new Util\OauthTokenError('Slack', url('auth/slack')); } try { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander(Cache::get('slack_token'), $interactor); $response = $commander->execute($command, $params); return $response->getBody(); } catch (\Exception $e) { } return false; }
/** * Execute the console command. * * @return mixed */ public function fire() { // $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); $commander = new Commander($_ENV['SLACK_KEY'], $interactor); $response = $commander->execute('users.list'); $responseBody = $response->getBody(); if (!$responseBody or !$responseBody['ok']) { throw new Exception('Sth Error Happened!'); } foreach ($responseBody['members'] as $member) { $userData = ['sid' => $member['id'], 'name' => $member['name'], 'deleted' => $member['deleted'], 'color' => array_get($member, 'color'), 'profile' => (object) $member['profile']]; if ($user = User::where('sid', $member['id'])->first()) { foreach ($userData as $k => $v) { $user->{$k} = $v; } $user->save(); } else { User::create($userData); } } }
$transport->setPort($conf->get('smtp.port')); $transport->setUsername($conf->get('smtp.username')); $transport->setPassword($conf->get('smtp.password')); $transport->setEncryption($conf->get('smtp.security')); $mailer = new Swift_Mailer($transport); $mailer->registerPLugin(new CssInlinerPlugin()); return $mailer; }; $app['rfc.builder'] = function ($app) { return new RfcBuilder($app['config']->get('storagePath')); }; $app['rfc.service'] = function ($app) { return new RfcService($app['rfc.builder'], $app['config']->get('rfcUrl')); }; $app['diff.service'] = function ($app) { return new DiffService(); }; $app['slack.api'] = function ($app) { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); return new Commander(null, $interactor); }; $app['notifier.rfc.notifiers'] = function ($app) { return [new SlackRfcNotifier($app['orm.em']->getRepository('MikeyMike\\RfcDigestor\\Entity\\SlackSubscriber'), $app['slack.api']), new \MikeyMike\RfcDigestor\Notifier\EmailRfcNotifier($app['orm.em']->getRepository('MikeyMike\\RfcDigestor\\Entity\\Subscriber'), $app['swift'], $app['twig'], $app['config'])]; }; $app['notifier.rfc'] = function ($app) { return new \MikeyMike\RfcDigestor\RfcNotifier($app['config'], $app['rfc.service'], $app['diff.service'], $app['notifier.rfc.notifiers']); }; $app['cli'] = new Application('PHP RFC Digestor', '0.1.0'); $app['cli']->addCommands(array(new Rfc\Digest($app['rfc.service']), new Rfc\Summary($app['rfc.service']), new Rfc\RfcList($app['rfc.service']), new Notify\Rfc($app['notifier.rfc']), new Notify\Voting($app['config'], $app['rfc.service']), new Notify\RfcList($app['config'], $app['rfc.service'], $app['diff.service'], $app['swift'], $app['twig']), new Test\Email($app['config'], $app['swift'], $app['twig']))); return $app;
/** * Get a Instance of Interactor * * @return CurlInteractor */ private function getInteractor() { $interactor = new CurlInteractor(); $interactor->setResponseFactory(new SlackResponseFactory()); return $interactor; }