4
4
5
5
use Carbon \Carbon ;
6
6
use Illuminate \Support \Facades \Http ;
7
+ use stdClass ;
7
8
8
9
class SurveyheroClient
9
10
{
@@ -77,6 +78,13 @@ public function getSurveyLanguages(string|int $surveyId): array
77
78
return $ languages ? $ languages ->languages : [];
78
79
}
79
80
81
+ public function listWebhooks (string |int $ surveyId ): ?array
82
+ {
83
+ $ webhookData = $ this ->fetchFromSurveyHero (sprintf ('surveys/%s/webhooks ' , $ surveyId ));
84
+
85
+ return $ webhookData ->successful () ? json_decode ($ webhookData ->body ())->webhooks : null ;
86
+ }
87
+
80
88
public function createWebhook (string |int $ surveyId , string $ eventType , string $ url , string $ status = 'active ' )
81
89
{
82
90
$ body = [
@@ -88,6 +96,13 @@ public function createWebhook(string|int $surveyId, string $eventType, string $u
88
96
$ this ->postToSurveyHero (sprintf ('surveys/%s/webhooks ' , $ surveyId ), $ body );
89
97
}
90
98
99
+ public function deleteWebhook (string |int $ surveyId , string |int $ webhookId ): ?stdClass
100
+ {
101
+ $ webhookData = $ this ->deleteFromSurveyHero (sprintf ('surveys/%s/webhooks/%s ' , $ surveyId , $ webhookId ));
102
+
103
+ return $ webhookData ->successful () ? json_decode ($ webhookData ->body ()) : null ;
104
+ }
105
+
91
106
public function deleteResponse (string |int $ surveyId , string |int $ responseId )
92
107
{
93
108
$ this ->deleteFromSurveyHero (sprintf ('surveys/%s/responses/%s ' , $ surveyId , $ responseId ));
@@ -98,6 +113,9 @@ public function transformAPITimestamp(string $surveyheroTimestamp): Carbon
98
113
return Carbon::createFromFormat ('Y-m-d\TH:i:s ' , substr ($ surveyheroTimestamp , 0 , strpos ($ surveyheroTimestamp , '+ ' )));
99
114
}
100
115
116
+ /**
117
+ * @throws \Exception
118
+ */
101
119
private function fetchFromSurveyHero (string $ urlPath , array $ queryStringArgs = []): \Illuminate \Http \Client \Response
102
120
{
103
121
$ this ->preventThrottle ();
@@ -115,6 +133,9 @@ private function fetchFromSurveyHero(string $urlPath, array $queryStringArgs = [
115
133
throw new \Exception ($ response ->body ());
116
134
}
117
135
136
+ /**
137
+ * @throws \Exception
138
+ */
118
139
private function postToSurveyHero (string $ urlPath , array $ queryStringArgs = []): \Illuminate \Http \Client \Response
119
140
{
120
141
$ this ->preventThrottle ();
0 commit comments