Example #1
0
 /**
  * @param null $connection
  * @return bool
  * @throws \Exception
  */
 public function send($connection = null)
 {
     $notifiers = Config::get('notifiers');
     if (!is_null($connection) && array_has($notifiers, $connection)) {
         $notifiers = array_only($notifiers, [$connection]);
     }
     $factory = new NotifyMeFactory();
     $successes = 0;
     foreach ($notifiers as $notifier) {
         if ($this->sender) {
             array_set($notifier, 'from', $this->sender);
         }
         $service = $factory->make($notifier);
         switch (array_get($notifier, 'driver')) {
             case 'hipchat':
                 $response = $service->notify(array_get($notifier, 'room'), $this->message);
                 break;
             default:
                 throw new \Exception("Driver not yet supported.");
         }
         if ($response->isSent()) {
             $successes++;
         } else {
             throw new \Exception($response->message());
         }
     }
     return $successes == count($notifiers);
 }
 /**
  * Create the connection instance.
  *
  * @param string[] $config
  *
  * @return \NotifyMeHQ\Contracts\GatewayInterface
  */
 protected function createConnection(array $config)
 {
     return $this->factory->make($config);
 }