Skip to content

Commit bb79002

Browse files
committed
Merge branch 'master' into 5.0
2 parents a901722 + c78315e commit bb79002

File tree

9 files changed

+254
-0
lines changed

9 files changed

+254
-0
lines changed

src/BigBlueButton.php

Lines changed: 22 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,26 @@ public function hooksDestroy(HooksDestroyParameters $hooksDestroyParams)
500502
return new HooksDestroyResponse($xml);
501503
}
502504

505+
/**
506+
* @return string
507+
*/
508+
public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParams): string
509+
{
510+
return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParams->getHTTPQuery());
511+
}
512+
513+
/**
514+
* @throws NetworkException
515+
* @throws ParsingException
516+
* @throws RuntimeException
517+
*/
518+
public function insertDocument(InsertDocumentParameters $insertDocumentParams): InsertDocumentResponse
519+
{
520+
$xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
521+
522+
return new InsertDocumentResponse($xml);
523+
}
524+
503525
/* ____________________ SPECIAL METHODS ___________________ */
504526
/**
505527
* @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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
final class InsertDocumentParameters extends MetaParameters
28+
{
29+
/**
30+
* @var string
31+
*/
32+
protected $meetingID;
33+
34+
/**
35+
* @var array
36+
*/
37+
private $presentations = [];
38+
39+
public function __construct(string $meetingID)
40+
{
41+
$this->meetingID = $meetingID;
42+
}
43+
44+
public function addPresentation(string $url, string $filename, ?bool $downloadable = null, ?bool $removable = null): self
45+
{
46+
$this->presentations[$url] = [
47+
'filename' => $filename,
48+
'downloadable' => $downloadable,
49+
'removable' => $removable,
50+
];
51+
52+
return $this;
53+
}
54+
55+
public function removePresentation(string $url): void
56+
{
57+
unset($this->presentations[$url]);
58+
}
59+
60+
/**
61+
* @return mixed
62+
*/
63+
public function getPresentationsAsXML()
64+
{
65+
$result = '';
66+
67+
if (!empty($this->presentations)) {
68+
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
69+
$module = $xml->addChild('module');
70+
$module->addAttribute('name', 'presentation');
71+
72+
foreach ($this->presentations as $url => $content) {
73+
$presentation = $module->addChild('document');
74+
$presentation->addAttribute('url', $url);
75+
$presentation->addAttribute('filename', $content['filename']);
76+
77+
if (is_bool($content['downloadable'])) {
78+
$presentation->addAttribute('downloadable', $content['downloadable'] ? 'true' : 'false');
79+
}
80+
81+
if (is_bool($content['removable'])) {
82+
$presentation->addAttribute('removable', $content['removable'] ? 'true' : 'false');
83+
}
84+
}
85+
$result = $xml->asXML();
86+
}
87+
88+
return $result;
89+
}
90+
}
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+
final 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>

tests/unit/BigBlueButtonTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use BigBlueButton\Http\Transport\TransportResponse;
2727
use BigBlueButton\Parameters\DeleteRecordingsParameters;
2828
use BigBlueButton\Parameters\GetRecordingsParameters;
29+
use BigBlueButton\Parameters\InsertDocumentParameters;
2930
use BigBlueButton\Parameters\PublishRecordingsParameters;
3031
use PHPUnit\Framework\MockObject\MockObject;
3132

@@ -346,4 +347,17 @@ public function testUpdateRecordingsUrl()
346347
$this->assertStringContainsString(\rawurlencode($key) . '=' . rawurlencode($value), $url);
347348
}
348349
}
350+
351+
public function testGetInsertDocument()
352+
{
353+
$params = new InsertDocumentParameters('foobar');
354+
355+
$this->assertStringContainsString('http://localhost/api/insertDocument?meetingID=foobar', $this->bbb->getInsertDocumentUrl($params));
356+
357+
$this->transport->method('request')->willReturn(new TransportResponse('<response><returncode>SUCCESS</returncode></response>', null));
358+
359+
$response = $this->bbb->insertDocument($params);
360+
361+
$this->assertTrue($response->success());
362+
}
349363
}
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+
final class InsertDocumentParametersTest extends TestCase
26+
{
27+
public function testIsMeetingRunningParameters(): void
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 InsertDocumentResponseTest 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 InsertDocumentResponse($xml);
40+
}
41+
42+
public function testIsMeetingRunningResponseContent(): void
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(): void
50+
{
51+
$this->assertEachGetterValueIsString($this->running, ['getReturnCode']);
52+
}
53+
}

0 commit comments

Comments
 (0)