generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command to list & delete webhooks in Surveyhero
- Loading branch information
1 parent
3ed4f01
commit 3d5e692
Showing
7 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Statikbe\Surveyhero\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Statikbe\Surveyhero\Contracts\SurveyContract; | ||
use Statikbe\Surveyhero\Services\SurveyWebhookService; | ||
use Statikbe\Surveyhero\SurveyheroRegistrar; | ||
|
||
class SurveyheroWebhookDeleteCommand extends Command | ||
{ | ||
public $signature = 'surveyhero:delete-webhook | ||
{--survey= : The Surveyhero survey ID} | ||
{--webhook= : The Surveyhero webhook ID}'; | ||
|
||
public $description = 'Delete Surveyhero webhooks'; | ||
|
||
/** | ||
* @var \Statikbe\Surveyhero\Services\SurveyWebhookService | ||
*/ | ||
private SurveyWebhookService $webhookService; | ||
|
||
public function __construct(SurveyWebhookService $webhookService) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->webhookService = $webhookService; | ||
} | ||
|
||
public function handle(): int | ||
{ | ||
$surveyId = trim($this->option('survey')); | ||
$webhookId = trim($this->option('webhook')); | ||
|
||
$surveys = app(SurveyheroRegistrar::class)->getSurveyClass()::query()->where('surveyhero_id', $surveyId)->get(); | ||
|
||
foreach ($surveys as $survey) { | ||
/* @var SurveyContract $survey */ | ||
try { | ||
$this->webhookService->deleteWebhook($survey, $webhookId); | ||
$this->comment('Webhook #'.$webhookId.' for survey #'.$surveyId.' deleted'); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return self::FAILURE; | ||
} | ||
} | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Statikbe\Surveyhero\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Statikbe\Surveyhero\Contracts\SurveyContract; | ||
use Statikbe\Surveyhero\Services\SurveyWebhookService; | ||
use Statikbe\Surveyhero\SurveyheroRegistrar; | ||
|
||
class SurveyheroWebhookListCommand extends Command | ||
{ | ||
public $signature = 'surveyhero:list-webhooks | ||
{--survey=all : The Surveyhero survey ID}'; | ||
|
||
public $description = 'List webhooks for Surveyhero surveys'; | ||
|
||
/** | ||
* @var \Statikbe\Surveyhero\Services\SurveyWebhookService | ||
*/ | ||
private SurveyWebhookService $webhookService; | ||
|
||
public function __construct(SurveyWebhookService $webhookService) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->webhookService = $webhookService; | ||
} | ||
|
||
public function handle(): int | ||
{ | ||
$surveyId = trim($this->option('survey')); | ||
|
||
$surveyQuery = app(SurveyheroRegistrar::class)->getSurveyClass()::query(); | ||
if ($surveyId !== 'all') { | ||
$surveyQuery->where('surveyhero_id', $surveyId); | ||
} | ||
$surveys = $surveyQuery->get(); | ||
|
||
foreach ($surveys as $survey) { | ||
/* @var SurveyContract $survey */ | ||
try { | ||
$webhooks = $this->webhookService->listWebhooks($survey); | ||
$webhookData = []; | ||
foreach($webhooks as $webhook) { | ||
$webhookData[] = [ | ||
$webhook->webhook_id, | ||
$webhook->event_type, | ||
$webhook->url, | ||
$webhook->status, | ||
$webhook->created_on, | ||
]; | ||
} | ||
$this->table( | ||
['Webhook id','Event type','Url','Status','Created'], | ||
$webhookData | ||
); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return self::FAILURE; | ||
} | ||
} | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters