File Coverage

lib/API/BigBlueButton.pm
Criterion Covered Total %
statement 24 48 50.0
branch 0 10 0.0
condition 0 3 0.0
subroutine 8 11 72.7
pod 1 3 33.3
total 33 75 44.0


line stmt bran cond sub pod time code
1             package API::BigBlueButton;
2              
3             =encoding utf-8
4              
5             =head1 NAME
6              
7             API::BigBlueButton
8              
9             =head1 SYNOPSIS
10              
11             use API::BigBlueButton;
12              
13             my $bbb = API::BigBlueButton->new( server => 'bbb.myhost', secret => '1234567890' );
14             my $res = $bbb->get_version;
15              
16             if ( $res->success ) {
17             my $version = $res->response->version
18             }
19             else {
20             warn "Error occured: " . $res->error . ", Status: " . $res->status;
21             }
22              
23             =head1 DESCRIPTION
24              
25             client for BigBlueButton API
26              
27             =cut
28              
29 1     1   790 use 5.008008;
  1         3  
  1         40  
30 1     1   6 use strict;
  1         4  
  1         39  
31 1     1   15 use warnings;
  1         2  
  1         48  
32              
33 1     1   5 use Carp qw/ confess /;
  1         2  
  1         74  
34 1     1   298089 use LWP::UserAgent '6.05';
  1         355751  
  1         41  
35              
36 1     1   1116 use API::BigBlueButton::Response;
  1         4  
  1         31  
37              
38 1     1   9 use base qw/ API::BigBlueButton::Requests /;
  1         1  
  1         556  
39              
40 1     1   6 use constant REQUIRE_PARAMS => qw/ secret server /;
  1         2  
  1         600  
41              
42             our $VERSION = "0.013";
43              
44             =head1 VERSION
45            
46             version 0.013
47              
48             =cut
49              
50             =head1 METHODS
51              
52             =over
53              
54             =item B
55              
56             Constructor
57              
58             %param:
59              
60             server
61              
62             Ip-address or hostname in which the server is located. Required parameter.
63              
64             secret
65              
66             Shared secret. Required parameter.
67              
68             timeout
69              
70             Connection timeout. Optional parameter.
71              
72             use_https
73              
74             Use/not use https. Optional parameter.
75             =cut
76              
77             sub new {
78 0     0 1   my $class = shift;
79              
80 0   0       $class = ref $class || $class;
81              
82 0           my $self = {
83             timeout => 30,
84             secret => '',
85             server => '',
86             use_https => 0,
87             (@_),
88             };
89              
90 0           for my $need_param ( REQUIRE_PARAMS ) {
91 0 0         confess "Parameter $need_param required!" unless $self->{ $need_param };
92             }
93              
94 0           return bless $self, $class;
95             }
96              
97             sub abstract_request {
98 0     0 0   my ( $self, $data ) = @_;
99              
100 0           my $request = delete $data->{request};
101 0           my $checksum = delete $data->{checksum};
102 0 0         confess "Parameter request required!" unless $request;
103              
104 0 0         my $url = $self->{use_https} ? 'https://' : 'http://';
105 0           $url .= $self->{server} . '/bigbluebutton/api/' . $request . '?';
106              
107 0 0         if ( scalar keys %{ $data } > 0 ) {
  0            
108 0           $url .= $self->generate_url_query( $data );
109 0           $url .= '&';
110             }
111 0           $url .= 'checksum=' . $checksum;
112              
113 0           return $self->request( $url );
114             }
115              
116             sub request {
117 0     0 0   my ( $self, $url ) = @_;
118              
119 0           my $ua = LWP::UserAgent->new;
120              
121 0 0         $ua->ssl_opts(verify_hostname => 0) if $self->{use_https};
122 0           $ua->timeout( $self->{ timeout } );
123              
124 0           my $res = $ua->get( $url );
125              
126 0           return API::BigBlueButton::Response->new( $res );
127             }
128              
129             1;
130              
131             __END__