Commit f37dd935 authored by Ghazi Triki's avatar Ghazi Triki
Browse files

Add support for webhooks.

parent 90d5d626
......@@ -24,6 +24,8 @@ use BigBlueButton\Parameters\DeleteRecordingsParameters;
use BigBlueButton\Parameters\EndMeetingParameters;
use BigBlueButton\Parameters\GetMeetingInfoParameters;
use BigBlueButton\Parameters\GetRecordingsParameters;
use BigBlueButton\Parameters\HooksCreateParameters;
use BigBlueButton\Parameters\HooksDestroyParameters;
use BigBlueButton\Parameters\IsMeetingRunningParameters;
use BigBlueButton\Parameters\JoinMeetingParameters;
use BigBlueButton\Parameters\PublishRecordingsParameters;
......@@ -36,6 +38,9 @@ use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
use BigBlueButton\Responses\GetMeetingInfoResponse;
use BigBlueButton\Responses\GetMeetingsResponse;
use BigBlueButton\Responses\GetRecordingsResponse;
use BigBlueButton\Responses\HooksCreateResponse;
use BigBlueButton\Responses\HooksDestroyResponse;
use BigBlueButton\Responses\HooksListResponse;
use BigBlueButton\Responses\IsMeetingRunningResponse;
use BigBlueButton\Responses\JoinMeetingResponse;
use BigBlueButton\Responses\PublishRecordingsResponse;
......@@ -351,6 +356,66 @@ class BigBlueButton
return new UpdateRecordingsResponse($xml);
}
/* ____________________ WEB HOOKS METHODS ___________________ */
/**
* @param $hookCreateParams HooksCreateParameters
* @return string
*/
public function getHooksCreateUrl($hookCreateParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
}
/**
* @param $hookCreateParams
* @return HooksCreateResponse
*/
public function hooksCreate($hookCreateParams)
{
$xml = $this->processXmlResponse($this->getHooksCreateUrl($hookCreateParams));
return new HooksCreateResponse($xml);
}
/**
* @return string
*/
public function getHooksListUrl()
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_LIST);
}
/**
* @return HooksListResponse
*/
public function hooksList()
{
$xml = $this->processXmlResponse($this->getHooksListUrl());
return new HooksListResponse($xml);
}
/**
* @param $hooksDestroyParams HooksDestroyParameters
* @return string
*/
public function getHooksDestroyUrl($hooksDestroyParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
}
/**
* @param $hooksDestroyParams
* @return HooksDestroyResponse
*/
public function hooksDestroy($hooksDestroyParams)
{
$xml = $this->processXmlResponse($this->getHooksDestroyUrl($hooksDestroyParams));
return new HooksDestroyResponse($xml);
}
/* ____________________ SPECIAL METHODS ___________________ */
/**
* @return string
......
......@@ -35,4 +35,7 @@ abstract class ApiMethod
const PUBLISH_RECORDINGS = 'publishRecordings';
const DELETE_RECORDINGS = 'deleteRecordings';
const UPDATE_RECORDINGS = 'updateRecordings';
const HOOKS_CREATE = 'hooks/create';
const HOOKS_LIST = 'hooks/list';
const HOOKS_DESTROY = 'hooks/destroy';
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Core;
/**
* Class Meeting
* @package BigBlueButton\Core
*/
class Hook
{
/**
* @var \SimpleXMLElement
*/
protected $rawXml;
/**
* @var string
*/
private $hookId;
/**
* @var string
*/
private $meetingId;
/**
* @var string
*/
private $callbackUrl;
/**
* @var bool
*/
private $permanentHook;
/**
* @var bool
*/
private $rawData;
/**
* Meeting constructor.
* @param $xml \SimpleXMLElement
*/
public function __construct($xml)
{
$this->rawXml = $xml;
$this->hookId = (int) $xml->hookID->__toString();
$this->callbackUrl = $xml->callbackURL->__toString();
$this->meetingId = $xml->meetingID->__toString();
$this->permanentHook = $xml->permanentHook->__toString() === 'true';
$this->rawData = $xml->rawData->__toString() === 'true';
}
/**
* @return string
*/
public function getHookId()
{
return $this->hookId;
}
/**
* @return string
*/
public function getMeetingId()
{
return $this->meetingId;
}
/**
* @return string
*/
public function getCallbackUrl()
{
return $this->callbackUrl;
}
/**
* @return bool
*/
public function isPermanentHook()
{
return $this->permanentHook;
}
/**
* @return bool
*/
public function hasRawData()
{
return $this->rawData;
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
class HooksCreateParameters extends BaseParameters
{
/**
* @var string
*/
private $callbackUrl;
/**
* @var string
*/
private $meetingId;
/**
* @var string
*/
private $getRaw;
/**
* HooksCreateParameters constructor.
*
* @param $callbackUrl
*/
public function __construct($callbackUrl)
{
$this->callbackUrl = $callbackUrl;
}
/**
* @return string
*/
public function getCallbackUrl()
{
return $this->callbackUrl;
}
/**
* @param string $callbackUrl
* @return HooksCreateParameters
*/
public function setCallbackUrl($callbackUrl)
{
$this->callbackUrl = $callbackUrl;
return $this;
}
/**
* @return string
*/
public function getMeetingId()
{
return $this->meetingId;
}
/**
* @param string $meetingId
* @return HooksCreateParameters
*/
public function setMeetingId($meetingId)
{
$this->meetingId = $meetingId;
return $this;
}
/**
* @return string
*/
public function getRaw()
{
return $this->getRaw;
}
/**
* @param string $getRaw
* @return HooksCreateParameters
*/
public function setGetRaw($getRaw)
{
$this->getRaw = $getRaw;
return $this;
}
/**
* @return string
*/
public function getHTTPQuery()
{
$queries = [
'callbackURL' => $this->callbackUrl,
'meetingID' => $this->meetingId,
'getRaw' => $this->getRaw
];
return $this->buildHTTPQuery($queries);
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
class HooksDestroyParameters extends BaseParameters
{
/**
* @var string
*/
private $hookId;
/**
* HooksDestroyParameters constructor.
*
* @param $hookId
*/
public function __construct($hookId)
{
$this->hookId = $hookId;
}
/**
* @return string
*/
public function getHookId()
{
return $this->hookId;
}
/**
* @param string $hookId
* @return HooksDestroyParameters
*/
public function setHookId($hookId)
{
$this->hookId = $hookId;
return $this;
}
/**
* @return string
*/
public function getHTTPQuery()
{
$queries = [
'hookID' => $this->hookId
];
return $this->buildHTTPQuery($queries);
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Responses;
/**
* Class GetRecordingsResponse
* @package BigBlueButton\Responses
*/
class HooksCreateResponse extends BaseResponse
{
/**
* @return int
*/
public function getHookId()
{
return (int) $this->rawXml->hookID->__toString();
}
/**
* @return bool
*/
public function isPermanentHook()
{
return $this->rawXml->permanentHook->__toString() === 'true';
}
/**
* @return bool
*/
public function hasRawData()
{
return $this->rawXml->rawData->__toString() === 'true';
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Responses;
/**
* Class GetRecordingsResponse
* @package BigBlueButton\Responses
*/
class HooksDestroyResponse extends BaseResponse
{
/**
* @return bool
*/
public function removed()
{
return $this->rawXml->removed->__toString() === 'true';
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Responses;
use BigBlueButton\Core\Hook;
/**
* Class GetRecordingsResponse
* @package BigBlueButton\Responses
*/
class HooksListResponse extends BaseResponse
{
/**
* @var Hook[]
*/
private $hooks;
/**
* @return Hook[]
*/
public function getHooks()
{
if ($this->hooks === null) {
$this->hooks = [];
foreach ($this->rawXml->hooks->children() as $hookXml) {
$this->hooks[] = new Hook($hookXml);
}
}
return $this->hooks;
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
use BigBlueButton\TestCase;
class HooksCreateParametersTest extends TestCase
{
public function testHooksCreateParameters()
{
$hooksCreateParameters = new HooksCreateParameters($callBackUrl = $this->faker->url);
$this->assertEquals($callBackUrl, $hooksCreateParameters->getCallbackUrl());
// Test setters that are ignored by the constructor
$hooksCreateParameters->setMeetingId($meetingId = $this->faker->uuid);
$hooksCreateParameters->setGetRaw($getRaw = $this->faker->boolean);
$this->assertEquals($meetingId, $hooksCreateParameters->getMeetingId());
$this->assertEquals($getRaw, $hooksCreateParameters->getRaw());
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
use BigBlueButton\TestCase;
class HooksDestroyParametersTest extends TestCase
{
public function testHooksDestroyParameters()
{
$hooksCreateParameters = new HooksDestroyParameters($hookId = $this->faker->numberBetween(1, 50));
$this->assertEquals($hookId, $hooksCreateParameters->getHookId());
}
}
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Parameters;
use BigBlueButton\Responses\HooksCreateResponse;