Inheritance: extends Illuminate\Database\Eloquent\Model
コード例 #1
0
ファイル: AddWebhook.php プロジェクト: mpociot/captainhook
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $hook = new Webhook();
     $hook->url = $this->argument('url');
     $hook->event = $this->argument('event');
     try {
         $hook->save();
         $this->info('The webhook was saved successfully.');
         $this->info('Event: ' . $hook->event);
         $this->info('URL: ' . $hook->url);
     } catch (Exception $e) {
         $this->error("The webhook couldn't be added to the database " . $e->getMessage());
     }
 }
コード例 #2
0
ファイル: CommandsTest.php プロジェクト: sschlein/captainhook
 public function testCanDeleteWebhook()
 {
     $webhook = \Mpociot\CaptainHook\Webhook::create(["url" => "http://foo.baz", "event" => "DeleteWebhook"]);
     $cmd = m::mock("\\Mpociot\\CaptainHook\\Commands\\DeleteWebhook[argument,info]");
     $cmd->shouldReceive("argument")->with("id")->andReturn($webhook->getKey());
     $cmd->shouldReceive("info")->with(m::type("string"));
     $cmd->handle();
     $this->notSeeInDatabase("webhooks", ["url" => "http://foo.baz", "event" => "DeleteWebhook"]);
 }
コード例 #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $id = $this->argument('id');
     $hook = Webhook::find($id);
     if ($hook === null) {
         $this->error('Webhook with ID ' . $id . ' could not be found.');
     } else {
         $hook->delete();
         $this->info('The webhook was deleted successfully.');
     }
 }
コード例 #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $id = $this->argument("id");
     $hook = Webhook::find($id);
     if ($hook === null) {
         $this->error("Webhook with ID " . $id . " could not be found.");
     } else {
         $hook->delete();
         $this->info("The webhook was deleted successfully.");
     }
 }
コード例 #5
0
 /**
  * @return \Illuminate\Support\Collection
  */
 public function getWebhooks()
 {
     if (!$this->getCache()->has(Webhook::CACHE_KEY)) {
         $this->getCache()->rememberForever(Webhook::CACHE_KEY, function () {
             return Webhook::all();
         });
     }
     return collect($this->getCache()->get(Webhook::CACHE_KEY));
 }
コード例 #6
0
ファイル: ListWebhooks.php プロジェクト: mpociot/captainhook
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $all = Webhook::select('id', 'tenant_id', 'url', 'event')->get();
     $this->table(['id', 'tenant_id', 'url', 'event'], $all->toArray());
 }
コード例 #7
0
 /**
  * Delete the given webhook.
  *
  * @param  Request  $request
  * @param  string  $webhookId
  * @return Response
  */
 public function destroy(Request $request, $webhookId)
 {
     Webhook::where('tenant_id', $this->getTenantId($request))->where('id', $webhookId)->firstOrFail()->delete();
 }
コード例 #8
0
 public function testCanFilterWebhooks()
 {
     $webhook = new Webhook();
     $webhook->tenant_id = 1;
     $webhook->url = "http://test.foo/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 2;
     $webhook->url = "http://test.bar/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 3;
     $webhook->url = "http://test.baz/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $client = m::mock("GuzzleHttp\\Client");
     $client->shouldReceive("postAsync")->once();
     $client->shouldReceive("postAsync")->with("http://test.bar/saved", m::any());
     $config = m::mock("stdClass");
     $config->shouldReceive("get")->with("captain_hook.filter", null)->andReturn(function ($item) {
         return $item->tenant_id == 2;
     });
     $provider = $this->app->getProvider("Mpociot\\CaptainHook\\CaptainHookServiceProvider");
     $provider->setClient($client);
     $provider->setConfig($config);
     $obj = new TestModel();
     $obj->name = "Test";
     $obj->save();
 }