Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeReygel authored and github-actions[bot] committed Oct 19, 2022
1 parent 8a3fdbd commit 835f857
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
13 changes: 7 additions & 6 deletions src/Commands/SurveyheroWebhookCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
17 changes: 8 additions & 9 deletions src/Http/SurveyheroClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
13 changes: 3 additions & 10 deletions src/Services/SurveyWebhookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
}
}

0 comments on commit 835f857

Please sign in to comment.