Skip to content

Commit

Permalink
Delete Event.
Browse files Browse the repository at this point in the history
  • Loading branch information
francis94c committed Jul 27, 2020
1 parent 99f6076 commit 4c08855
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
22 changes: 20 additions & 2 deletions src/LiveStream/LiveStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -201,7 +218,7 @@ public function getRtmpKey(
'notifyFollowers' => $notifyFollowers,
'publishVideo' => $publishVideo,
'saveVideo' => $saveVideo
]);
]);

if ($response === null) return null;

Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions tests/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
50 changes: 50 additions & 0 deletions tests/RTMPKeyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Tests;

use LiveStream\LiveStream;
use PHPUnit\Framework\TestCase;
use LiveStream\Resources\RTMPKey;

class RTMPKeyTest extends TestCase
{
/**
* Undocumented function
*
* @return void
*/
public function testCanFetchRtmpKey():void
{
$livestream = new LiveStream('abc');

$key = $livestream->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);
}
}
1 change: 1 addition & 0 deletions tests/invalid_logo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An Invalid Poster
67 changes: 65 additions & 2 deletions tests/server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c08855

Please sign in to comment.