/** * 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()); } }
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"]); }
/** * 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.'); } }
/** * 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."); } }
/** * @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)); }
/** * 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()); }
/** * 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(); }
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(); }