Skip to content

Commit 2c6b9e6

Browse files
committed
Added the Webinar Update and Delete API methods
Response carries now more information especially on error responses so that the developer can get a clear understanding if there was an error or not.
1 parent 659930b commit 2c6b9e6

File tree

4 files changed

+144
-91
lines changed

4 files changed

+144
-91
lines changed

readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ $webinar = [ 'subject' => 'API Test 2',
8181
'endTime' => "2016-03-23T20:00:00Z", ];
8282

8383
$webinar = GotoWebinar::createWebinar( $webinar );
84+
85+
86+
// Update a Webinar - date format standard: W3C - ISO 8601
87+
$webinar = [ 'subject' => 'API Test 2.2',
88+
'description' => 'This Webinar is updated via the API',
89+
'startTime' => "2016-03-24T19:00:00Z",
90+
'endTime' => "2016-03-24T20:00:00Z", ];
91+
92+
$webinar = GotoWebinar::updateWebinar( $webinarKey, $params, $sendNotification = true);
93+
94+
95+
// Delete a specific Webinar
96+
$result = GotoWebinar::deleteWebinar( $webinarKey, $sendNotification = true );
8497
```
8598

8699
### Attendee and Registrant Resource

src/CitrixAbstract.php

Lines changed: 94 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Slakbal\Citrix;
44

55
use GuzzleHttp\Client as HttpClient;
6-
use GuzzleHttp\Exception\ClientException;
7-
use GuzzleHttp\Exception\RequestException;
86
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Log;
98

109
/**
1110
* Provides common functionality for Citrix classes
@@ -35,6 +34,8 @@ abstract class CitrixAbstract
3534

3635
private $url;
3736

37+
private $httpResponse;
38+
3839
private $response;
3940

4041
private $status;
@@ -70,20 +71,22 @@ public function __construct($authType)
7071
}
7172

7273

73-
private function directAuthentication()
74+
public function hasAccessObject()
7475
{
75-
$directAuth = new DirectAuthenticate();
76+
if (Cache::has('citrix_access_object')) {
77+
return true;
78+
}
7679

77-
$this->authObject = $directAuth->authenticate();
78-
$this->rememberAccessObject($this->authObject);
80+
return false;
7981
}
8082

8183

82-
private function oauth2Authentication()
84+
private function directAuthentication()
8385
{
84-
//to be implemented
85-
$this->authObject = null;
86-
Cache::forget('citrix_access_object');
86+
$directAuth = new DirectAuthenticate();
87+
88+
$this->authObject = $directAuth->authenticate();
89+
$this->rememberAccessObject($this->authObject);
8790
}
8891

8992

@@ -93,13 +96,11 @@ public function rememberAccessObject($authObject)
9396
}
9497

9598

96-
public function hasAccessObject()
99+
private function oauth2Authentication()
97100
{
98-
if (Cache::has('citrix_access_object')) {
99-
return true;
100-
}
101-
102-
return false;
101+
//to be implemented
102+
$this->authObject = null;
103+
Cache::forget('citrix_access_object');
103104
}
104105

105106

@@ -109,12 +110,6 @@ public function getOrganizerKey()
109110
}
110111

111112

112-
public function getAccessToken()
113-
{
114-
return $this->authObject->access_token;
115-
}
116-
117-
118113
public function getAccountKey()
119114
{
120115
return $this->authObject->account_key;
@@ -133,26 +128,12 @@ public function getAuthObject()
133128
}
134129

135130

136-
public function getParams()
137-
{
138-
return $this->params;
139-
}
140-
141-
142131
public function getStatus()
143132
{
144133
return $this->status;
145134
}
146135

147136

148-
public function setParams($params)
149-
{
150-
$this->params = $params;
151-
152-
return $this;
153-
}
154-
155-
156137
public function addParam($key, $value)
157138
{
158139
$this->params[ $key ] = $value;
@@ -161,32 +142,12 @@ public function addParam($key, $value)
161142
}
162143

163144

164-
public function getUrl()
165-
{
166-
return $this->url;
167-
}
168-
169-
170-
public function setUrl($url)
171-
{
172-
$this->url = $url;
173-
174-
return $this;
175-
}
176-
177-
178145
public function getResponse()
179146
{
180147
return $this->response;
181148
}
182149

183150

184-
public function getResponseCollection()
185-
{
186-
return collect($this->response);
187-
}
188-
189-
190151
public function setResponse($response)
191152
{
192153
if (is_object($response)) {
@@ -203,17 +164,9 @@ public function setResponse($response)
203164
}
204165

205166

206-
public function getHttpMethod()
207-
{
208-
return $this->httpMethod;
209-
}
210-
211-
212-
public function setHttpMethod($httpMethod)
167+
public function getResponseCollection()
213168
{
214-
$this->httpMethod = strtoupper($httpMethod);
215-
216-
return $this;
169+
return collect($this->response);
217170
}
218171

219172

@@ -237,7 +190,7 @@ public function sendRequest()
237190

238191
case 'GET':
239192

240-
$response = $this->http_client->get($this->getUrl(), [
193+
$this->httpResponse = $this->http_client->get($this->getUrl(), [
241194
'headers' => [
242195
'Content-Type' => 'application/json; charset=utf-8',
243196
'Accept' => 'application/json',
@@ -249,7 +202,7 @@ public function sendRequest()
249202

250203
case 'POST':
251204

252-
$response = $this->http_client->post($this->getUrl(), [
205+
$this->httpResponse = $this->http_client->post($this->getUrl(), [
253206
'headers' => [
254207
'Content-Type' => 'application/json; charset=utf-8',
255208
'Accept' => 'application/json',
@@ -259,9 +212,9 @@ public function sendRequest()
259212
]);
260213
break;
261214

262-
case 'DELETE':
215+
case 'PUT':
263216

264-
$response = $this->http_client->delete($this->getUrl(), [
217+
$this->httpResponse = $this->http_client->put($this->getUrl(), [
265218
'headers' => [
266219
'Content-Type' => 'application/json; charset=utf-8',
267220
'Accept' => 'application/json',
@@ -271,38 +224,95 @@ public function sendRequest()
271224
]);
272225
break;
273226

227+
case 'DELETE':
228+
229+
$this->httpResponse = $this->http_client->delete($this->getUrl(), [
230+
'headers' => [
231+
'Content-Type' => 'application/json; charset=utf-8',
232+
'Accept' => 'application/json',
233+
'Authorization' => 'OAuth oauth_token=' . $this->getAccessToken(),
234+
],
235+
]);
236+
break;
237+
274238
default:
275239

276240
break;
277241
}
242+
} catch (\Exception $e) {
278243

279-
} catch (ClientException $e) {
280-
281-
$this->response = [];
244+
Log::error('CITRIX - ' . $e->getMessage());
245+
$this->response = [
246+
'error' => true,
247+
'message' => $e->getMessage()
248+
];
282249

283250
return $this;
284251

285-
} catch (RequestException $e) {
252+
}
286253

287-
$this->response = [];
254+
//if no error carry on to build the response
255+
$this->response = [
256+
'error' => false,
257+
'status' => $this->httpResponse->getStatusCode(),
258+
'body' => $this->parseBody($this->httpResponse->getBody())
259+
];
288260

289-
return $this;
261+
return $this;
262+
}
290263

291-
} catch (\Exception $e) {
292264

293-
$this->response = [];
265+
public function getHttpMethod()
266+
{
267+
return $this->httpMethod;
268+
}
294269

295-
return $this;
296-
}
297270

298-
//if no error carry on to process the response
271+
public function setHttpMethod($httpMethod)
272+
{
273+
$this->httpMethod = strtoupper($httpMethod);
274+
275+
return $this;
276+
}
277+
278+
279+
public function getUrl()
280+
{
281+
return $this->url;
282+
}
283+
284+
285+
public function setUrl($url)
286+
{
287+
$this->url = $url;
288+
289+
return $this;
290+
}
291+
292+
293+
public function getAccessToken()
294+
{
295+
return $this->authObject->access_token;
296+
}
297+
298+
299+
public function getParams()
300+
{
301+
return $this->params;
302+
}
299303

300-
$this->response = $response->getBody();
301-
//dd( (string)$this->response );
302304

303-
$this->response = json_decode($this->response, false, 512, JSON_BIGINT_AS_STRING);
305+
public function setParams($params)
306+
{
307+
$this->params = $params;
304308

305309
return $this;
306310
}
307311

312+
313+
public function parseBody($body)
314+
{
315+
return json_decode($body, false, 512, JSON_BIGINT_AS_STRING);
316+
}
317+
308318
}

src/Entity/Webinar.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Webinar extends EntityAbstract
1010
public $description;
1111
public $times = [];
1212
public $timezone = 'Europe/Berlin';
13+
public $local;
1314
private $webinarKey;
1415
private $registrationUrl;
1516
private $participants;
@@ -19,10 +20,11 @@ public function __construct($parameterArray = null)
1920
{
2021
if (isset($parameterArray) && is_array($parameterArray)) {
2122

22-
$this->setSubject($parameterArray[ 'subject' ]);
23-
(isset($parameterArray[ 'description' ]) ? $this->setDescription($parameterArray[ 'description' ]) : null);
23+
$this->setSubject((isset($parameterArray[ 'subject' ]) ? $parameterArray[ 'subject' ] : null));
24+
$this->setDescription((isset($parameterArray[ 'description' ]) ? $parameterArray[ 'description' ] : ''));
2425
$this->setTimes(new Time($parameterArray[ 'startTime' ], $parameterArray[ 'endTime' ]));
25-
(isset($parameterArray[ 'timezone' ]) ? $this->setTimezone($parameterArray[ 'timezone' ]) : null);
26+
$this->setTimezone((isset($parameterArray[ 'timezone' ]) ? $parameterArray[ 'timezone' ] : $this->timezone));
27+
$this->setLocal((isset($parameterArray[ 'local' ]) ? $parameterArray[ 'local' ] : 'de_DE'));
2628

2729
}
2830
}
@@ -64,6 +66,18 @@ public function setTimezone($timezone)
6466
}
6567

6668

69+
public function getLocal()
70+
{
71+
return $this->local;
72+
}
73+
74+
75+
public function setLocal($local)
76+
{
77+
$this->local = $local;
78+
}
79+
80+
6781
public function getTimes()
6882
{
6983
return $this->times;

0 commit comments

Comments
 (0)