File Coverage

blib/lib/Mojo/Webqq/Model/Remote/_get_group_info.pm
Criterion Covered Total %
statement 3 63 4.7
branch 0 22 0.0
condition 0 6 0.0
subroutine 1 4 25.0
pod n/a
total 4 95 4.2


line stmt bran cond sub pod time code
1 1     1   7 use strict;
  1         1  
  1         699  
2             sub Mojo::Webqq::Model::_get_group_info {
3 0     0     my $self = shift;
4 0           my $gcode = shift;
5 0           my $callback = shift;
6 0           my $api_url = 'http://s.web2.qq.com/api/get_group_info_ext2';
7 0           my @query_string = (
8             gcode => $gcode,
9             vfwebqq => $self->vfwebqq,
10             t => time(),
11             );
12              
13 0           my $headers = {
14             Referer => 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
15             json=>1,
16             ua_request_timeout => $self->model_update_timeout,
17             ua_retry_times => 3,
18             };
19 0 0         my $is_blocking = ref $callback eq "CODE"?0:1;
20             my $handle = sub {
21 0     0     my $json = shift;
22 0 0         return unless defined $json;
23 0 0         my $ginfo_status = exists $json->{result}{ginfo}?"[ginfo-ok]":"[ginfo-not-ok]";
24 0 0         my $minfo_status = ref $json->{result}{minfo} eq "ARRAY"?"[minfo-ok]":"[minfo-not-ok]";
25            
26 0 0         return undef unless exists $json->{result}{ginfo};
27 0           $json->{result}{ginfo}{id} = delete $json->{result}{ginfo}{gid};
28 0           $json->{result}{ginfo}{code} = delete $json->{result}{ginfo}{code};
29 0           $json->{result}{ginfo}{name} = $self->xmlescape_parse($json->{result}{ginfo}{name});
30 0           $json->{result}{ginfo}{memo} = delete $json->{result}{ginfo}{memo};
31 0           $json->{result}{ginfo}{createtime} = delete $json->{result}{ginfo}{createtime};
32 0           $json->{result}{ginfo}{level} = delete $json->{result}{ginfo}{level};
33 0           $json->{result}{ginfo}{owner_id} = delete $json->{result}{ginfo}{owner};
34 0           $json->{result}{ginfo}{markname} = $self->xmlescape_parse($json->{result}{ginfo}{markname});
35            
36 0           delete $json->{result}{ginfo}{fingermemo};
37 0           delete $json->{result}{ginfo}{face};
38 0           delete $json->{result}{ginfo}{option};
39 0           delete $json->{result}{ginfo}{class};
40 0           delete $json->{result}{ginfo}{flag};
41 0           delete $json->{result}{ginfo}{members};
42              
43             #retcode等于0说明包含完整的ginfo和minfo
44 0 0 0       if(exists $json->{result}{minfo} and ref $json->{result}{minfo} eq "ARRAY"){
45 0           my %cards;
46 0 0 0       if(ref $json->{result}{cards} eq "ARRAY" and @{ $json->{result}{cards} }!=0){
  0            
47 0           for (@{ $json->{result}{cards} }){
  0            
48 0           $cards{$_->{muin}} = $_->{card};
49             }
50             }
51 0           my %state;
52 0           for(@{ $json->{result}{stats} }){
  0            
53 0           $state{$_->{uin}}{client_type} = $self->code2client($_->{client_type});
54 0           $state{$_->{uin}}{state} = $self->code2state($_->{'stat'});
55             }
56 0           for my $m(@{ $json->{result}{minfo} }){
  0            
57 0 0         if( not $self->group_member_card_ext_only){
58 0 0         $m->{card} = $self->xmlescape_parse($cards{$m->{uin}}) if exists $cards{$m->{uin}};
59 0           $m->{card} = $self->safe_truncate($m->{card},$self->group_member_card_cut_length);
60             }
61 0           $m->{name} = $self->xmlescape_parse(delete $m->{nick});
62 0 0         if(exists $state{$m->{uin}}){
63 0           $m->{state} = $state{$m->{uin}}{state};
64 0           $m->{client_type} = $state{$m->{uin}}{client_type};
65             }
66             else{
67 0           $m->{state} = 'offline';
68 0           $m->{client_type} = 'unknown';
69             }
70 0           $m->{_group_id} = $json->{result}{ginfo}{id};
71 0           $m->{id} = delete $m->{uin};
72 0           $m->{sex} = delete $m->{gender};
73             }
74 0           $json->{result}{ginfo}{member} = delete $json->{result}{minfo};
75             }
76 0           return $json->{result}{ginfo};
77 0           };
78 0 0         if($is_blocking){
79 0           return $handle->( $self->http_get($self->gen_url($api_url,@query_string),$headers,) );
80             }
81             else{
82             $self->http_get($self->gen_url($api_url,@query_string),$headers,sub{
83 0     0     my $json = shift;
84 0           $callback->( $handle->($json) );
85 0           });
86             }
87             }
88             1;