| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::FogBugz; |
|
2
|
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
135963
|
use warnings; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
296
|
|
|
4
|
9
|
|
|
9
|
|
36
|
use strict; |
|
|
9
|
|
|
|
|
12
|
|
|
|
9
|
|
|
|
|
250
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
5598
|
use LWP::UserAgent; |
|
|
9
|
|
|
|
|
324766
|
|
|
|
9
|
|
|
|
|
382
|
|
|
7
|
9
|
|
|
9
|
|
7441
|
use XML::Liberal; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XML::LibXML; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.1.0'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
|
|
|
|
|
|
my $class = shift; |
|
14
|
|
|
|
|
|
|
my ($param) = @_; |
|
15
|
|
|
|
|
|
|
die 'you need to input email, password and base url.' |
|
16
|
|
|
|
|
|
|
unless $param->{email} and $param->{password} and $param->{base_url}; |
|
17
|
|
|
|
|
|
|
my $self = bless {%$param}, $class; |
|
18
|
|
|
|
|
|
|
$self->{ua} = $param->{ua} || LWP::UserAgent->new; |
|
19
|
|
|
|
|
|
|
$self->{ua}->agent(__PACKAGE__.'/'.$VERSION); |
|
20
|
|
|
|
|
|
|
$self->{parser} = XML::Liberal->new('LibXML'); |
|
21
|
|
|
|
|
|
|
return $self; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub logon { |
|
25
|
|
|
|
|
|
|
my $self = shift; |
|
26
|
|
|
|
|
|
|
my $res = $self->{ua}->get( |
|
27
|
|
|
|
|
|
|
$self->{base_url} |
|
28
|
|
|
|
|
|
|
. '?cmd=logon' |
|
29
|
|
|
|
|
|
|
. '&email=' . $self->{email} |
|
30
|
|
|
|
|
|
|
. '&password=' . $self->{password}); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return if ($self->_is_error($res->content)); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $doc = $self->{parser}->parse_string($res->content); |
|
35
|
|
|
|
|
|
|
$self->{token} = $doc->findvalue("//*[local-name()='response']/*[local-name()='token']/text()"); |
|
36
|
|
|
|
|
|
|
return $self->{token}; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub logoff { |
|
40
|
|
|
|
|
|
|
my $self = shift; |
|
41
|
|
|
|
|
|
|
my $res = $self->{ua}->get( |
|
42
|
|
|
|
|
|
|
$self->{base_url} |
|
43
|
|
|
|
|
|
|
. '?cmd=logoff' |
|
44
|
|
|
|
|
|
|
. '&token=' . $self->{token}); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return if ($self->_is_error($res->content)); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
delete $self->{token}; |
|
49
|
|
|
|
|
|
|
return; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub request_method { |
|
53
|
|
|
|
|
|
|
my $self = shift; |
|
54
|
|
|
|
|
|
|
my ($cmd, $param) = @_; |
|
55
|
|
|
|
|
|
|
my $query = join('', map {'&' . $_ . '=' . $param->{$_}} keys(%$param)); |
|
56
|
|
|
|
|
|
|
my $res = $self->{ua}->get( |
|
57
|
|
|
|
|
|
|
$self->{base_url} |
|
58
|
|
|
|
|
|
|
. '?cmd=' . $cmd |
|
59
|
|
|
|
|
|
|
. '&token=' . $self->{token} |
|
60
|
|
|
|
|
|
|
. $query); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return if ($self->_is_error($res->content)); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return $res->content; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _is_error { |
|
68
|
|
|
|
|
|
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
my ($content) = @_; |
|
70
|
|
|
|
|
|
|
$content =~ s/<\?xml\s+.*?\?>//g; |
|
71
|
|
|
|
|
|
|
my $doc = $self->{parser}->parse_string($content); |
|
72
|
|
|
|
|
|
|
$self->{error}{code} = $doc->findvalue("//*[local-name()='response']/*[local-name()='error']/\@code"); |
|
73
|
|
|
|
|
|
|
$self->{error}{msg} = $doc->findvalue("//*[local-name()='response']/*[local-name()='error']/text()"); |
|
74
|
|
|
|
|
|
|
return $self->{error}{code} ? '1' : '0'; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |