From 835f857a0c3db5b0921bd21a6e798c4c8617de1b Mon Sep 17 00:00:00 2001 From: RobbeReygel Date: Wed, 19 Oct 2022 14:16:41 +0000 Subject: [PATCH] Fix styling --- src/Commands/SurveyheroWebhookCommand.php | 13 +++++++------ src/Http/SurveyheroClient.php | 17 ++++++++--------- src/Services/SurveyWebhookService.php | 13 +++---------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Commands/SurveyheroWebhookCommand.php b/src/Commands/SurveyheroWebhookCommand.php index 1cb328a..d8cbba2 100644 --- a/src/Commands/SurveyheroWebhookCommand.php +++ b/src/Commands/SurveyheroWebhookCommand.php @@ -4,7 +4,6 @@ use Illuminate\Console\Command; use Statikbe\Surveyhero\Contracts\SurveyContract; -use Statikbe\Surveyhero\Services\SurveyMappingService; use Statikbe\Surveyhero\Services\SurveyWebhookService; use Statikbe\Surveyhero\SurveyheroRegistrar; @@ -35,12 +34,14 @@ public function handle(): int $url = trim($this->option('url')); $eventType = trim($this->option('eventType')); - if(!$url) { - $this->error("Please specify the webhook URL"); + if (! $url) { + $this->error('Please specify the webhook URL'); + return self::FAILURE; } - if(!$eventType) { - $this->error("Please specify the event type"); + if (! $eventType) { + $this->error('Please specify the event type'); + return self::FAILURE; } @@ -62,7 +63,7 @@ public function handle(): int $this->comment("generating Webhooks for survey '$survey->name' completed!"); } - $this->comment("Generating webhooks complete!"); + $this->comment('Generating webhooks complete!'); return self::SUCCESS; } diff --git a/src/Http/SurveyheroClient.php b/src/Http/SurveyheroClient.php index 0142281..467dc6f 100644 --- a/src/Http/SurveyheroClient.php +++ b/src/Http/SurveyheroClient.php @@ -62,16 +62,15 @@ public function getSurveyLanguages(string|int $surveyId): array return $languages ? $languages->languages : []; } - public function createWebhook(string|int $surveyId, string $eventType, string $url, string $status="active") + public function createWebhook(string|int $surveyId, string $eventType, string $url, string $status = 'active') { $body = [ 'event_type' => $eventType, 'url' => $url, - 'status' => $status + 'status' => $status, ]; $this->postToSurveyHero(sprintf('surveys/%s/webhooks', $surveyId), $body); - } public function transformAPITimestamp(string $surveyheroTimestamp): Carbon @@ -95,11 +94,11 @@ private function postToSurveyHero(string $urlPath, array $body = []): \Illuminat //Prevent API rate limiting: max 2 requests per second //half a second in microseconds is 500000 usleep(500000); - $response = Http::withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password')) - ->post(config('surveyhero.api_url') . $urlPath, $body); - if($response->successful()) { - return $response; - } - Throw new \Exception($response->body()); + $response = Http::withBasicAuth(config('surveyhero.api_username'), config('surveyhero.api_password')) + ->post(config('surveyhero.api_url').$urlPath, $body); + if ($response->successful()) { + return $response; + } + throw new \Exception($response->body()); } } diff --git a/src/Services/SurveyWebhookService.php b/src/Services/SurveyWebhookService.php index 80f7bdc..62ed9fb 100644 --- a/src/Services/SurveyWebhookService.php +++ b/src/Services/SurveyWebhookService.php @@ -3,15 +3,7 @@ namespace Statikbe\Surveyhero\Services; use Statikbe\Surveyhero\Contracts\SurveyContract; -use Statikbe\Surveyhero\Exceptions\QuestionMapperNotImplementedException; -use Statikbe\Surveyhero\Exceptions\QuestionNotMappedException; -use Statikbe\Surveyhero\Exceptions\SurveyNotMappedException; use Statikbe\Surveyhero\Models\Survey; -use Statikbe\Surveyhero\Services\Factories\QuestionMapper\ChoiceListQuestionMapper; -use Statikbe\Surveyhero\Services\Factories\QuestionMapper\ChoiceTableQuestionMapper; -use Statikbe\Surveyhero\Services\Factories\QuestionMapper\InputQuestionMapper; -use Statikbe\Surveyhero\Services\Factories\QuestionMapper\QuestionMapper; -use Statikbe\Surveyhero\Services\Factories\QuestionMapper\RatingScaleQuestionMapper; class SurveyWebhookService extends AbstractSurveyheroAPIService { @@ -23,7 +15,8 @@ class SurveyWebhookService extends AbstractSurveyheroAPIService * * @see SurveyheroMapperCommand */ - public function generateWebhook(Survey $survey, string $eventType, string $url) { - $this->client->createWebhook($survey->surveyhero_id, $eventType, $url,'active'); + public function generateWebhook(Survey $survey, string $eventType, string $url) + { + $this->client->createWebhook($survey->surveyhero_id, $eventType, $url, 'active'); } }