line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tropo::RestAPI::Session; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Tropo session handling |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
666
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3087
|
use Moo; |
|
1
|
|
|
|
|
22382
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
1934
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Tropo::RestAPI::Base'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.05; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub create { |
16
|
|
|
|
|
|
|
my ($self, %param) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
if ( !defined $param{token} ) { |
19
|
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$param{action} = 'create'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $delim = substr( $self->url, -1 ) eq '/' ? '' : '/'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $session_url = $self->url . $delim . 'sessions'; |
27
|
|
|
|
|
|
|
my $response = $self->get( |
28
|
|
|
|
|
|
|
$session_url, |
29
|
|
|
|
|
|
|
\%param, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ( !$response ) { |
33
|
|
|
|
|
|
|
$self->err( 'Cannot connect to ' . $session_url ); |
34
|
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ( !$response->{success} ) { |
38
|
|
|
|
|
|
|
$self->err( $response->{reason} . ': ' . $response->{content} ); |
39
|
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ( !$response->{content} ) { |
43
|
|
|
|
|
|
|
$self->err( 'Tropo session launch failed!' ); |
44
|
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if ( !$self->redirect && $response->{url} !~ m{ \A \Q$session_url\E }xms ) { |
48
|
|
|
|
|
|
|
$self->err( 'Reponse from differen URL as the request was sent to!' ); |
49
|
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $data = XMLin( $response->{content} ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $data; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |