File Coverage

blib/lib/Webqq/Client/Method/_get_discuss_list_info.pm
Criterion Covered Total %
statement 6 29 20.6
branch 0 12 0.0
condition 0 3 0.0
subroutine 2 3 66.6
pod n/a
total 8 47 17.0


line stmt bran cond sub pod time code
1 1     1   7 use JSON;
  1         1  
  1         43  
2 1     1   171 use Encode;
  1         2  
  1         519  
3             sub Webqq::Client::_get_discuss_list_info {
4 0     0     my $self = shift;
5 0           my $ua = $self->{ua};
6 0 0         return undef if $self->{type} ne 'smartqq';
7 0           my $ua = $self->{ua};
8 0           my $api_url = 'http://s.web2.qq.com/api/get_discus_list';
9 0           my @query_string = (
10             clientid => $self->{qq_param}{clientid},
11             psessionid => $self->{qq_param}{psessionid},
12             vfwebqq => $self->{qq_param}{vfwebqq},
13             t => time(),
14             );
15            
16 0           my @headers = (
17             Referer => 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
18             );
19 0           my @query_string_pairs;
20 0           push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string);
21 0           my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
22 0 0         if($response->is_success){
  0            
23             #{"retcode":0,"result":{"dnamelist":[{"name":"测试2","did":2742986730},{"name":"测试","did":3420777698}]}}
24 0 0         print $response->content(),"\n" if $self->{debug};
25 0           my $json;
26 0           eval{
27 0           $json = JSON->new->utf8->decode($response->content()) ;
28             };
29 0 0 0       print $@ if $@ and $self->{debug};
30 0 0         $json = {} unless defined $json;
31 0 0         return undef if $json->{retcode}!=0;
32 0           for(@{ $json->{result}{dnamelist} }){
  0            
33 0           $_->{name} = encode("utf8",$_->{name});
34             }
35 0           return $json->{result}{dnamelist};
36            
37             }
38             else{return undef;}
39              
40             }
41              
42             1;