| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::BuzzurlAPI::Response; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
WebService::BuzzurlAPI::Response - Buzzurl WebService API response package |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
0.02 |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Buzzurl WebService API response package |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHOD |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
9
|
|
|
9
|
|
50
|
use strict; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
395
|
|
|
22
|
9
|
|
|
9
|
|
46
|
use base qw(Class::Accessor); |
|
|
9
|
|
|
|
|
14
|
|
|
|
9
|
|
|
|
|
837
|
|
|
23
|
9
|
|
|
9
|
|
7935
|
use JSON::Syck; |
|
|
9
|
|
|
|
|
37318
|
|
|
|
9
|
|
|
|
|
13329
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(errstr)); |
|
26
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw(json res)); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = 0.02; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Create instance |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
|
39
|
|
|
|
|
|
|
|
|
40
|
3
|
|
|
3
|
1
|
3958771
|
my($class, $res) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
50
|
|
|
|
22
|
if(ref($res) ne "HTTP::Response"){ |
|
43
|
0
|
|
|
|
|
0
|
croak("\$res is not \"HTTP::Response\" object"); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
3
|
|
33
|
|
|
33
|
return bless { json => undef, res => $res }, $class || ref $class; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 analysis_response |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Analysis http response |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub analysis_response { |
|
57
|
|
|
|
|
|
|
|
|
58
|
3
|
|
|
3
|
1
|
8
|
my $self = shift; |
|
59
|
3
|
|
|
|
|
6
|
my $json; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# response check |
|
62
|
|
|
|
|
|
|
# for WebService::BuzzurlAPI::Request::Add and |
|
63
|
3
|
50
|
|
|
|
20
|
if(!$self->res->is_success){ |
|
64
|
0
|
|
|
|
|
0
|
return $self->_error($self->res->code, $self->res->message); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# for redirect error |
|
68
|
3
|
50
|
|
|
|
197
|
if($self->res->content_type !~ /^application\/json/){ |
|
69
|
0
|
|
|
|
|
0
|
return $self->_error(0, "invalid_param [" . $self->res->previous->request->uri . "]" ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
198
|
$json = JSON::Syck::Load($self->res->content); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# faild json check |
|
75
|
|
|
|
|
|
|
# for WebService::BuzzurlAPI::Request::Add |
|
76
|
3
|
0
|
33
|
|
|
6587
|
if(ref($json) eq "HASH" && exists $json->{status} && $json->{status} ne "success"){ |
|
|
|
|
33
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return $self->_error(999, $json->{status} . " " . $json->{reason}); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
11
|
$self->{json} = $json; |
|
81
|
3
|
|
|
|
|
11
|
return 1; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 is_success |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Check response |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub is_success { |
|
91
|
|
|
|
|
|
|
|
|
92
|
3
|
50
|
|
3
|
1
|
26
|
return shift->res->is_success ? 1 : 0; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 _error |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Set error code and message |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _error { |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
0
|
|
|
my($self, $code, $message) = @_; |
|
104
|
0
|
|
|
|
|
|
$self->res->code($code); |
|
105
|
0
|
|
|
|
|
|
$self->res->message($message); |
|
106
|
0
|
|
|
|
|
|
$self->errstr($message); |
|
107
|
0
|
|
|
|
|
|
return 0; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |