diff --git a/README.md b/README.md index 83baa13..7a96f20 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Before you proceed, note that `$livestream` function calls that return null, ind __Every other HTTP Response Code except 200 & 201 will throw an Exception.__ ### Get Accounts ### -Get all LiveStream accounts linked to API key. +Get all LiveStream accounts linked to the current API key. ```php $accounts = $livestream->getAccounts(); // Returns an array of account resources. ``` diff --git a/src/LiveStream/LiveStream.php b/src/LiveStream/LiveStream.php index f171969..3b28383 100644 --- a/src/LiveStream/LiveStream.php +++ b/src/LiveStream/LiveStream.php @@ -121,7 +121,24 @@ public function updateEvent(int $accountId, Event $event): bool } /** - * Undocumented function + * Delete Event + * + * @param integer $accountId + * @param integer $eventId + * + * @return boolean + */ + public function deleteEvent(int $accountId, int $eventId): ?Event + { + $response = $this->request("accounts/$accountId/events/$eventId", 'delete'); + + if ($response === null) return null; + + return Event::fromObject(json_decode($response)); + } + + /** + * Update Event Logo. * * @param integer $accountId * @param integer $eventId @@ -201,7 +218,7 @@ public function getRtmpKey( 'notifyFollowers' => $notifyFollowers, 'publishVideo' => $publishVideo, 'saveVideo' => $saveVideo - ]); + ]); if ($response === null) return null; @@ -253,6 +270,7 @@ private function request( if ($verb != 'get') { if ($verb == 'post') curl_setopt($ch, CURLOPT_POST, true); if ($verb == 'put') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + if ($verb == 'delete') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); if ($body) { curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: ' . $body->getContentType() diff --git a/tests/EventsTest.php b/tests/EventsTest.php index 46e93cb..3249880 100644 --- a/tests/EventsTest.php +++ b/tests/EventsTest.php @@ -293,4 +293,20 @@ public function testCanGetDraftEvents():void $this->assertCount(5, $events); } + + /** + * Undocumented function + * + * @return void + */ + public function testCanDeleteEvent():void + { + $livestream = new LiveStream('abc'); + + $event = $livestream->deleteEvent(5637245, 5201483); + + $this->assertInstanceOf(Event::class, $event); + + $this->assertEquals(5201483, $event->getId()); + } } diff --git a/tests/RTMPKeyTest.php b/tests/RTMPKeyTest.php new file mode 100644 index 0000000..5c9f998 --- /dev/null +++ b/tests/RTMPKeyTest.php @@ -0,0 +1,50 @@ +getRtmpKey(5637245, 5201483); + + $this->assertInstanceOf(RTMPKey::class, $key); + + $this->assertEquals('m5m-25d-jr6-7yk?n=1&p=0', $key->id); + $this->assertEquals('m5m-25d-jr6-7yk?n=1&p=0', $key->getId()); + + $this->assertEquals('rtmp://rtmpin.livestreamingest.com/rtmpin', $key->getUrl()); + $this->assertEquals('rtmp://rtmpin.livestreamingest.com/rtmpin', $key->rtmpUrl); + } + + /** + * Undocumented function + * + * @return void + */ + public function testCanResetRtmpKey():void + { + $livestream = new LiveStream('abc'); + + $key = $livestream->resetRtmpKey(5637245, 5201483); + + $this->assertInstanceOf(RTMPKey::class, $key); + + $this->assertEquals('m5m-25d-jr6-7yk', $key->id); + $this->assertEquals('m5m-25d-jr6-7yk', $key->getId()); + + $this->assertEquals('rtmp://rtmpin.livestreamingest.com/rtmpin', $key->getUrl()); + $this->assertEquals('rtmp://rtmpin.livestreamingest.com/rtmpin', $key->rtmpUrl); + } +} \ No newline at end of file diff --git a/tests/invalid_logo.txt b/tests/invalid_logo.txt new file mode 100644 index 0000000..480d436 --- /dev/null +++ b/tests/invalid_logo.txt @@ -0,0 +1 @@ +An Invalid Poster \ No newline at end of file diff --git a/tests/server/index.php b/tests/server/index.php index db936f3..613e604 100644 --- a/tests/server/index.php +++ b/tests/server/index.php @@ -375,7 +375,7 @@ public function processGetDraftEvents(int $accountId): void * @param integer $eventId * @return void */ - public function processGetRtmpKeyRequest(int $accountId, int $eventId):void + public function processGetRtmpKeyRequest(int $accountId, int $eventId): void { if (!$this->authenticate()) { Flight::json([ @@ -406,7 +406,7 @@ public function processGetRtmpKeyRequest(int $accountId, int $eventId):void * @param integer $eventId * @return void */ - public function processResetRtmpKeyRequest(int $accountId, int $eventId):void + public function processResetRtmpKeyRequest(int $accountId, int $eventId): void { if (!$this->authenticate()) { Flight::json([ @@ -430,6 +430,68 @@ public function processResetRtmpKeyRequest(int $accountId, int $eventId):void ], 200); } + /** + * Undocumented function + * + * @param integer $accountId + * @param integer $eventId + * @return void + */ + public function processDeleteEventRequest(int $accountId, int $eventId): void + { + if (!$this->authenticate()) { + Flight::json([ + 'code' => 401, + 'message' => 'Unauthorized – Your API key is incorrect.' + ], 404); + return; + } + + if ($accountId != 5637245 || $eventId != 5201483) { + Flight::json([ + 'code' => 404, + 'message' => '' + ], 404); + return; + } + + Flight::json([ + "id" => 5201483, + "logo" => [ + "url" => "https=>//cdn.livestream.com/newlivestream/poster-default.jpeg", + "thumbnailUrl" => "https=>//cdn.livestream.com/newlivestream/poster-default.jpeg", + "smallUrl" => "https=>//cdn.livestream.com/newlivestream/poster-default.jpeg" + ], + "description" => Flight::request()->data->description, + "likes" => [ + "total" => 0 + ], + "fullName" => Flight::request()->data->fullName, + "shortName" => Flight::request()->data->shortName, + "ownerAccountId" => $accountId, + "viewerCount" => 0, + "createdAt" => date('c'), + "startTime" => Flight::request()->data->startTime ?? '', + "endTime" => Flight::request()->data->endTime ?? '', + "draft" => Flight::request()->data->draft ?? true, + "tags" => explode(',', Flight::request()->data->tags ?? ''), + "isPublic" => Flight::request()->data->isPublic ?? true, + "isSearchable" => Flight::request()->data->isSearchable ?? true, + "viewerCountVisible" => Flight::request()->data->viewerCountVisible ?? true, + "postCommentsEnabled" => Flight::request()->data->postCommentsEnabled ?? true, + "liveChatEnabled" => Flight::request()->data->liveChatEnabled ?? true, + "isEmbeddable" => Flight::request()->data->isEmbeddable ?? true, + "isPasswordProtected" => false, + "isWhiteLabeled" => true, + "embedRestriction" => "off", + "embedRestrictionWhitelist" => [ + "*.lsops.org/*" + ], + "embedRestrictionBlacklist" => null, + "isLive" => false + ], 200); + } + /** * Undocumented function * @@ -493,6 +555,7 @@ private function get_authorization_header(): ?string Flight::route('GET /accounts/@accountId/draft_events', [$stub, 'processGetDraftEvents']); Flight::route('GET /accounts/@accountId/events/@eventId/rtmp', [$stub, 'processGetRtmpKeyRequest']); Flight::route('PUT /accounts/@accountId/events/@eventId/rtmp', [$stub, 'processResetRtmpKeyRequest']); +Flight::route('DELETE /accounts/@accountId/events/@eventId', [$stub, 'processDeleteEventRequest']); /** * Configurations