API-BigBlueButton

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

    received the program in object code or executable form alone.)

Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

  5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions.  You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.

  7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of the license which applies to it and "any

LICENSE  view on Meta::CPAN

may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.

6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.

7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.

8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.

9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

The End

cpanfile  view on Meta::CPAN

requires 'perl', '5.008008';
requires 'Carp', '0';
requires 'LWP::UserAgent', '>= 6.05';
requires 'base', '0';
requires 'constant', '0';
requires 'Digest::SHA1', '0';
requires 'XML::Fast', '0';

on 'test' => sub {
    requires 'Test::More', '0.98';
    requires 'Test::Spec', '0';
    requires 'FindBin', '0';
};

lib/API/BigBlueButton.pm  view on Meta::CPAN


timeout

    Connection timeout. Optional parameter.

use_https

    Use/not use https. Optional parameter.
=cut

sub new {
    my $class = shift;

    $class = ref $class || $class;

    my $self = {
        timeout => 30,
        secret  => '',
        server  => '',
        use_https => 0,
        (@_),
    };

    for my $need_param ( REQUIRE_PARAMS ) {
        confess "Parameter $need_param required!" unless $self->{ $need_param };
    }

    return bless $self, $class;
}

sub abstract_request {
    my ( $self, $data ) = @_;

    my $request = delete $data->{request};
    my $checksum = delete $data->{checksum};
    confess "Parameter request required!" unless $request;

    my $url = $self->{use_https} ? 'https://' : 'http://';
    $url .= $self->{server} . '/bigbluebutton/api/' . $request . '?';

    if ( scalar keys %{ $data } > 0 ) {
        $url .= $self->generate_url_query( $data );
        $url .= '&';
    }
    $url .= 'checksum=' . $checksum;

    return $self->request( $url );
}

sub request {
    my ( $self, $url ) = @_;

    my $ua = LWP::UserAgent->new;

    $ua->ssl_opts(verify_hostname => 0) if $self->{use_https};
    $ua->timeout( $self->{ timeout } );

    my $res = $ua->get( $url );

    return API::BigBlueButton::Response->new( $res );

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

=head1 METHODS

=over

=item B<get_version($self)>

Getting the current version of the BigBlueButton

=cut

sub get_version {
    my ( $self ) = @_;

    my $url = $self->{use_https} ? 'https://' : 'http://';
    $url .= $self->{server} . '/bigbluebutton/api';

    return $self->request( $url );
}

=item B<create($self,%params)>

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    This parameter is optional.

clientURL

    This parameter is optional.

SEE MORE L<https://code.google.com/p/bigbluebutton/wiki/API#create>

=cut

sub create {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'create', \%params );
    return $self->abstract_request( $data );
}

=item B<join($self,%params)>

Joins a user to the meeting specified in the meetingID parameter.

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    This parameter is optional.

clientURL

    This parameter is optional.

SEE MORE L<https://code.google.com/p/bigbluebutton/wiki/API#join>

=cut

sub join {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'join', \%params );
    return $self->abstract_request( $data );
}

=item B<ismeetingrunning($self,%params)>

This call enables you to simply check on whether or not a meeting is running by
looking it up with your meeting ID.

%params:

meetingID

    This parameter is mandatory.
    The meeting ID that identifies the meeting you are attempting to check on.

=cut

sub ismeetingrunning {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'isMeetingRunning', \%params );
    return $self->abstract_request( $data );
}

=item B<end($self,%params)>

Use this to forcibly end a meeting and kick all participants out of the meeting.

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    This parameter is mandatory.
    The meeting ID that identifies the meeting you are attempting to end.

password

    This parameter is mandatory.
    The moderator password for this meeting. You can not end a meeting using the attendee password.

=cut

sub end {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'end', \%params );
    return $self->abstract_request( $data );
}

=item B<getmeetinginfo($self,%params)>

This call will return all of a meeting's information,
including the list of attendees as well as start and end times.

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    The meeting ID that identifies the meeting you are attempting to check on.

password

    This parameter is mandatory.
    The moderator password for this meeting.
    You can not get the meeting information using the attendee password.

=cut

sub getmeetinginfo {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'getMeetingInfo', \%params );
    return $self->abstract_request( $data );
}

=item B<getmeetings($self)>

This call will return a list of all the meetings found on this server.

=cut

sub getmeetings {
    my ( $self ) = @_;

    my $data = $self->_generate_data( 'getMeetings' );
    return $self->abstract_request( $data );
}

=item B<getrecordings($self,%params)>

Retrieves the recordings that are available for playback for a given meetingID (or set of meeting IDs).

%params:

meetingID

    This parameter is optional.

=cut

sub getrecordings {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'getRecordings', \%params );
    return $self->abstract_request( $data );
}

=item B<publishrecordings($self,%params)>

Publish and unpublish recordings for a given recordID (or set of record IDs).

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    A record ID for specify the recordings to apply the publish action.
    It can be a set of record IDs separated by commas.

publish

    This parameter is mandatory.
    The value for publish or unpublish the recording(s). Available values: true or false.

=cut

sub publishrecordings {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'publishRecordings', \%params );
    return $self->abstract_request( $data );
}

=item B<deleterecordings($self,%params)>

Delete one or more recordings for a given recordID (or set of record IDs).

%params:

recordID

    This parameter is mandatory.
    A record ID for specify the recordings to delete.
    It can be a set of record IDs separated by commas.

=cut

sub deleterecordings {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'deleteRecordings', \%params );
    return $self->abstract_request( $data );
}

=item B<getdefaultconfigxml($self)>

Retrieve the default config.xml.

SEE MORE L<https://code.google.com/p/bigbluebutton/wiki/API#getDefaultConfigXML>

=cut

sub getdefaultconfigxml {
    my ( $self ) = @_;

    my $data = $self->_generate_data( 'getDefaultConfigXML' );
    return $self->abstract_request( $data );
}

=item B<setconfigxml($self,%params)>

Associate an custom config.xml file with the current session.

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN


configXML

    This parameter is mandatory.
    A valid config.xml file

SEE MORE L<https://code.google.com/p/bigbluebutton/wiki/API#setConfigXML>

=cut

sub setconfigxml {
    my ( $self, %params ) = @_;

    my $data = $self->_generate_data( 'setConfigXML', \%params );
    return $self->abstract_request( $data );
}

=item B<generate_checksum($self,$request,$params)>

Create a checksum for the query

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

    Name of query, e.g. 'create' or 'join'

$params:

    Query parameters

    my $chksum = $self->generate_checksum( 'create', \%params );

=cut

sub generate_checksum {
    my ( $self, $request, $params ) = @_;

    my $string = $request;
    $string .= $self->generate_url_query( $params ) if ( $params && ref $params );
    $string .= $self->{secret};

    return sha1_hex( $string );
}

=item B<generate_url_query($self,$params)>

lib/API/BigBlueButton/Requests.pm  view on Meta::CPAN

$params:

    Query parameters

    $params{checksum} = $self->generate_checksum( 'create', \%params );
    $params{request}  = 'create';
    my $url = $self->generate_url_query( \%params );

=cut

sub generate_url_query {
    my ( $self, $params ) = @_;

    my $string = CORE::join( '&', map { "$_=$params->{$_}" } sort keys %{ $params } );

    return $string;
}

sub _generate_data {
    my ( $self, $request, $params ) = @_;

    $self->_check_params( $request, $params ) if $params;
    $params->{checksum} = $self->generate_checksum( $request, $params );
    $params->{request}  = $request;

    return $params;
}

sub _check_params {
    my ( $self, $request, $params ) = @_;

    my $const = 'REQUIRE_' . uc $request . '_PARAMS';
    return unless $self->can( $const );

    for my $req_param ( @{ $self->$const } ) {
        confess "Parameter $req_param required!" unless $params->{ $req_param };
    }

    return 1;

lib/API/BigBlueButton/Response.pm  view on Meta::CPAN

=item B<new($class,$res)>

Constructor.

$res

    HTTP::Response object.

=cut

sub new {
    my ( $class, $res ) = @_;

    my $success   = $res->is_success;
    my $xml       = $success ? $res->decoded_content : '';
    my $error     = $success ? '' : $res->decoded_content;
    my $status    = $res->status_line;

    my $parsed_response = $xml ? xml2hash( $xml, attr => '' ) : {};

    return bless(

lib/API/BigBlueButton/Response.pm  view on Meta::CPAN

        }, $class
    );
}

=item B<xml($self)>

Returns original XML answer.

=cut

sub xml {
    my ( $self ) = @_;

    return $self->{xml};
}

=item B<success($self)>

Returns 1 if request succeeded, 0 otherwise.

=cut

sub success {
    my ( $self ) = @_;

    return $self->{success};
}

=item B<response($self)>

Returns munged response from service. According to method, it can be scalar, hashref of arrayref.

=cut

sub response {
    my ( $self ) = @_;

    return $self->{response};
}

=item B<error($self)>

Returns munged error text.

=cut

sub error {
    my ( $self ) = @_;

    return $self->{error};
}

=item B<status($self)>

Returns response status line.

=cut

sub status {
    my ( $self ) = @_;

    return $self->{status};
}

1;

__END__

=back

t/002_bigbluebutton.t  view on Meta::CPAN

use strict;
use warnings;
use Test::Spec;

use FindBin qw/ $Bin /;
use lib "$Bin/../lib";

use_ok( 'API::BigBlueButton' );

describe "Constructor" => sub {

    it "Normal creation" => sub {
        my $bbb = API::BigBlueButton->new(
            secret => 'mysecret',
            server => 'myserver',
        );
        ok( $bbb );
        is( $bbb->{server}, 'myserver' );
        is( $bbb->{secret}, 'mysecret' );
    };

    it "Empty required params" => sub {
        my $bbb;
        eval { $bbb = API::BigBlueButton->new };
        ok( $@ );

        eval { $bbb = API::BigBlueButton->new( secret => 'mysecret' ) };
        ok( $@ );
        like( $@, qr/Parameter server required/ );

        eval { $bbb = API::BigBlueButton->new( server => 'myserver' ) };
        ok( $@ );
        like( $@, qr/Parameter secret required/ );
    };
};

describe "abstract_request" => sub {

    my $checksum = '1233dfgdfg';
    my $bbb;

    before each => sub {
        $bbb = API::BigBlueButton->new(
            secret => 'mysecret',
            server => 'myserver',
        );
    };

    it "Without data" => sub {
        my $url;
        API::BigBlueButton->expects( 'request' )
            ->returns( sub { $url = $_[1]; return 1 } )->at_least(1);

        my $res = $bbb->abstract_request( {
            request  => 'create',
            checksum => $checksum,
        } );

        ok( $res );
        like( $url, qr/myserver.+create\?checksum=$checksum/ );
    };

    it "With data" => sub {
        my $url;
        my $key = 'myparam';
        my $val = 'myvalue';

        API::BigBlueButton->expects( 'request' )
            ->returns( sub { $url = $_[1]; return 1 } )->at_least(1);

        API::BigBlueButton->expects( 'generate_url_query' )
            ->returns( sub { return $key . '=' . $_[1]->{ $key } } )->at_least(1);

        my $res = $bbb->abstract_request( {
            request  => 'create',
            checksum => $checksum,
            $key     => $val,
        } );

        ok( $res );
        like( $url, qr/myserver.+create\?$key=$val&checksum=$checksum/ );
    };

    it "Empty param request" => sub {
        eval { $bbb->abstract_request( { checksum => $checksum } ) };

        ok ( $@ );
        like( $@, qr/Parameter request required/ );
    };
};

runtests unless caller;

t/003_bigbluebutton_requests.t  view on Meta::CPAN

use strict;
use warnings;
use Test::Spec;

use FindBin qw/ $Bin /;
use lib "$Bin/../lib";

use_ok( 'API::BigBlueButton' );

describe "Get version" => sub {
    it "Normal run" => sub {
        my $url;

        API::BigBlueButton->expects( 'request' )
            ->returns( sub { $url = $_[1]; return 1; } )->at_least(1);

        my $bbb = API::BigBlueButton->new(
            secret => 'mysecret',
            server => 'myserver',
        );

        ok( $bbb->get_version );
        is( $url, 'http://myserver/bigbluebutton/api' );
    };
};

describe "Other requests" => sub {
    my ( $bbb, $url );

    before all => sub {
        $bbb = API::BigBlueButton->new(
            secret => 'mysecret',
            server => 'myserver',
        );
    };

    before each => sub {
        undef $url;
        API::BigBlueButton->expects( 'request' )
            ->returns( sub { $url = $_[1]; return 1; } )->any_number;
    };

    describe "create" => sub {
        it "Normal run" => sub {
            ok( $bbb->create( meetingID => 'mymeeting' ) );
            like( $url, qr/create\?meetingID=mymeeting/ );
        };

        it "Empty meetingID" => sub {
            eval { $bbb->create };
            ok( $@ );
            like( $@, qr/Parameter meetingID required!/ );
        };
    };

    describe "join" => sub {
        it "Normal run" => sub {
            ok( $bbb->join(
                fullName  => 'myname',
                meetingID => 'mymeeting',
                password  => 'mypass',
                )
            );
            like( $url, qr/join\?fullName=myname&meetingID=mymeeting&password=mypass/ );
        };
    };

    describe "ismeetingrunning" => sub {
        it "Normal run" => sub {
            ok( $bbb->ismeetingrunning( meetingID => 'mymeeting' ) );
            like( $url, qr/isMeetingRunning\?meetingID=mymeeting/ );
        };
    };

    describe "end" => sub {
        it "Normal run" => sub {
            ok( $bbb->end( meetingID => 'mymeeting', password  => 'mypass' ) );
            like( $url, qr/end\?meetingID=mymeeting&password=mypass/ );
        }
    };

    describe "getmeetinginfo" => sub {
        it "Normal run" => sub {
            ok( $bbb->getmeetinginfo( meetingID => 'mymeeting', password  => 'mypass' ) );
            like( $url, qr/getMeetingInfo\?meetingID=mymeeting&password=mypass/ );
        }
    };

    describe "getmeetings" => sub {
        it "Normal run" => sub {
            ok( $bbb->getmeetings );
            like( $url, qr/getMeetings/ );
        }
    };

    describe "getrecordings" => sub {
        it "Normal run" => sub {
            ok( $bbb->getrecordings( meetingID => 'mymeeting', password  => 'mypass' ) );
            like( $url, qr/getRecordings\?meetingID=mymeeting&password=mypass/ );
        }
    };
};

runtests unless caller;



( run in 2.510 seconds using v1.01-cache-2.11-cpan-88abd93f124 )