File Coverage

blib/lib/Webqq/Client/Method/get_single_long_nick.pm
Criterion Covered Total %
statement 6 25 24.0
branch 0 10 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 39 23.0


line stmt bran cond sub pod time code
1 1     1   5 use JSON;
  1         1  
  1         6  
2 1     1   84 use Encode;
  1         3  
  1         426  
3             sub Webqq::Client::get_single_long_nick{
4 0     0 1   my $self = shift;
5 0           my $uin = shift;
6            
7 0           my $cache_data = $self->{cache_for_single_long_nick}->retrieve($uin);
8 0 0         return $cache_data if defined $cache_data;
9              
10 0           my $api_url = 'http://s.web2.qq.com/api/get_single_long_nick2';
11 0           my $ua = $self->{ua};
12 0 0         my @headers = $self->{type} eq 'webqq'?(Referer=>'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=3')
13             : (Referer=>'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
14             ;
15 0           my @query_string = (
16             tuin => $uin,
17             vfwebqq => $self->{qq_param}{vfwebqq},
18             t => time,
19             );
20 0           my @query_string_pairs;
21 0           push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string);
22 0           my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
23 0 0         if($response->is_success){
  0            
24 0 0         print $response->content(),"\n" if $self->{debug};
25 0           my $json = JSON->new->utf8->decode( $response->content() );
26 0 0         return undef if $json->{retcode} !=0;
27             #{"retcode":0,"result":[{"uin":308165330,"lnick":""}]}
28 0           my $single_long_nick = encode("utf8",$json->{result}[0]{lnick});
29 0           $self->{cache_for_single_long_nick}->store($uin,$single_long_nick);
30 0           return $single_long_nick;
31             }
32             else{return undef}
33             }
34             1;