Skip to content

Commit a99b3d0

Browse files
committed
add insertDocument endpoint
requires at least BBB 2.5
1 parent 4849c5f commit a99b3d0

8 files changed

Lines changed: 247 additions & 0 deletions

File tree

src/BigBlueButton.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
3636
use BigBlueButton\Parameters\HooksCreateParameters;
3737
use BigBlueButton\Parameters\HooksDestroyParameters;
38+
use BigBlueButton\Parameters\InsertDocumentParameters;
3839
use BigBlueButton\Parameters\IsMeetingRunningParameters;
3940
use BigBlueButton\Parameters\JoinMeetingParameters;
4041
use BigBlueButton\Parameters\PublishRecordingsParameters;
@@ -51,6 +52,7 @@
5152
use BigBlueButton\Responses\HooksCreateResponse;
5253
use BigBlueButton\Responses\HooksDestroyResponse;
5354
use BigBlueButton\Responses\HooksListResponse;
55+
use BigBlueButton\Responses\InsertDocumentResponse;
5456
use BigBlueButton\Responses\IsMeetingRunningResponse;
5557
use BigBlueButton\Responses\JoinMeetingResponse;
5658
use BigBlueButton\Responses\PublishRecordingsResponse;
@@ -500,6 +502,27 @@ public function hooksDestroy(HooksDestroyParameters $hooksDestroyParams)
500502
return new HooksDestroyResponse($xml);
501503
}
502504

505+
/**
506+
* @return string
507+
*/
508+
public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParams)
509+
{
510+
return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParams->getHTTPQuery());
511+
}
512+
513+
/**
514+
* @return CreateMeetingResponse
515+
* @throws NetworkException
516+
* @throws ParsingException
517+
* @throws RuntimeException
518+
*/
519+
public function insertDocument(InsertDocumentParameters $insertDocumentParams)
520+
{
521+
$xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
522+
523+
return new InsertDocumentResponse($xml);
524+
}
525+
503526
/* ____________________ SPECIAL METHODS ___________________ */
504527
/**
505528
* @return string

src/Core/ApiMethod.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ class ApiMethod
4040
public const HOOKS_CREATE = 'hooks/create';
4141
public const HOOKS_LIST = 'hooks/list';
4242
public const HOOKS_DESTROY = 'hooks/destroy';
43+
public const INSERT_DOCUMENT = 'insertDocument';
4344
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Parameters;
22+
23+
/**
24+
* @method string getMeetingID()
25+
* @method $this setMeetingID(string $id)
26+
*/
27+
class InsertDocumentParameters extends MetaParameters
28+
{
29+
/**
30+
* @var string
31+
*/
32+
protected $meetingID;
33+
34+
/**
35+
* @var array
36+
*/
37+
protected $presentations = [];
38+
39+
public function __construct(string $meetingID)
40+
{
41+
$this->meetingID = $meetingID;
42+
}
43+
44+
/**
45+
* @return CreateMeetingParameters
46+
*/
47+
public function addPresentation(string $url, string $filename, ?bool $downloadable = null, ?bool $removable = null)
48+
{
49+
$this->presentations[$url] = [
50+
'filename' => $filename,
51+
'downloadable' => $downloadable,
52+
'removable' => $removable,
53+
];
54+
55+
return $this;
56+
}
57+
58+
/**
59+
* @return array
60+
*/
61+
public function getPresentations(): array
62+
{
63+
return $this->presentations;
64+
}
65+
66+
/**
67+
* @return mixed
68+
*/
69+
public function getPresentationsAsXML()
70+
{
71+
$result = '';
72+
73+
if (!empty($this->presentations)) {
74+
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
75+
$module = $xml->addChild('module');
76+
$module->addAttribute('name', 'presentation');
77+
78+
foreach ($this->presentations as $url => $content) {
79+
$presentation = $module->addChild('document');
80+
$presentation->addAttribute('url', $url);
81+
$presentation->addAttribute('filename', $content['filename']);
82+
83+
if (is_bool($content['downloadable'])) {
84+
$presentation->addAttribute('downloadable', $content['downloadable'] ? 'true' : 'false');
85+
}
86+
87+
if (is_bool($content['removable'])) {
88+
$presentation->addAttribute('removable', $content['removable'] ? 'true' : 'false');
89+
}
90+
}
91+
$result = $xml->asXML();
92+
}
93+
94+
return $result;
95+
}
96+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of littleredbutton/bigbluebutton-api-php.
5+
*
6+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
namespace BigBlueButton\Responses;
20+
21+
class InsertDocumentResponse extends BaseResponse
22+
{
23+
}

tests/fixtures/insert_document.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<response>
2+
<returncode>SUCCESS</returncode>
3+
</response>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<modules>
3+
<module name="presentation">
4+
<document url="http://localhost/foobar.png" filename="Foobar.png"/>
5+
<document url="http://localhost/foobar.pdf" filename="Foobar.pdf" downloadable="true"/>
6+
<document url="http://localhost/foobar.svg" filename="Foobar.svg" downloadable="true" removable="false"/>
7+
</module>
8+
</modules>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Parameters;
22+
23+
use BigBlueButton\TestCase;
24+
25+
class InsertDocumentParametersTest extends TestCase
26+
{
27+
public function testIsMeetingRunningParameters()
28+
{
29+
$meetingId = $this->faker->uuid;
30+
$params = new InsertDocumentParameters($meetingId);
31+
32+
$params->addPresentation('http://localhost/foobar.png', 'Foobar.png');
33+
$params->addPresentation('http://localhost/foobar.pdf', 'Foobar.pdf', true);
34+
$params->addPresentation('http://localhost/foobar.svg', 'Foobar.svg', true, false);
35+
36+
$this->assertEquals($meetingId, $params->getMeetingID());
37+
38+
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'insert_document_presentations.xml', $params->getPresentationsAsXML());
39+
}
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Parameters;
22+
23+
use BigBlueButton\Responses\InsertDocumentResponse;
24+
use BigBlueButton\TestCase;
25+
26+
class InsertDocumentResponse extends TestCase
27+
{
28+
/**
29+
* @var \BigBlueButton\Responses\IsMeetingRunningResponse
30+
*/
31+
private $running;
32+
33+
public function setUp(): void
34+
{
35+
parent::setUp();
36+
37+
$xml = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'insert_document.xml');
38+
39+
$this->running = new self($xml);
40+
}
41+
42+
public function testIsMeetingRunningResponseContent()
43+
{
44+
$this->assertEquals('SUCCESS', $this->running->getReturnCode());
45+
46+
$this->assertEquals('<?xmlversion="1.0"?><response><returncode>SUCCESS</returncode></response>', $this->minifyString($this->running->getRawXml()->asXML()));
47+
}
48+
49+
public function testIsMeetingRunningResponseTypes()
50+
{
51+
$this->assertEachGetterValueIsString($this->running, ['getReturnCode']);
52+
}
53+
}

0 commit comments

Comments
 (0)