File Coverage

blib/lib/Mojo/Weixin/Model/Remote/_webwxcreatechatroom.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 8 0.0
condition 0 7 0.0
subroutine 3 4 75.0
pod n/a
total 12 52 23.0


line stmt bran cond sub pod time code
1 1     1   6 use strict;
  1         2  
  1         30  
2 1     1   6 use Mojo::Weixin::Const;
  1         2  
  1         95  
3 1     1   459 use Mojo::Weixin::Group;
  1         3  
  1         8  
4             sub Mojo::Weixin::_webwxcreatechatroom {
5 0     0     my $self = shift;
6 0           my $friends = shift;
7 0           my $chatroom_displayname = shift;
8              
9 0 0 0       if(ref $friends ne "ARRAY" or 0+@$friends<1){
10 0           $self->error("_webwxcreatechatroom invaild friend list");
11 0           return;
12             }
13              
14 0           my $api = 'https://' .$self->domain . '/cgi-bin/mmwebwx-bin/webwxcreatechatroom';
15 0           my @query_string = (
16             r => $self->now(),
17             );
18 0 0         push @query_string,(pass_ticket => $self->url_escape($self->pass_ticket)) if $self->pass_ticket;
19             my $post = {
20             BaseRequest => {
21             Uin => $self->wxuin,
22             Sid => $self->wxsid,
23             Skey => $self->skey,
24             DeviceID => $self->deviceid,
25             },
26             MemberCount => 0+@$friends,
27 0   0       MemberList => [map { +{UserName=>$_->id} } @$friends],
  0            
28             Topic => $chatroom_displayname // "",
29             };
30            
31 0           my $json = $self->http_post($self->gen_url($api,@query_string),{json=>1,Referer=>'https://' . $self->domain . '/'},json=>$post);
32 0 0         return if not defined $json;
33 0 0         return if $json->{BaseResponse}{Ret}!=0;
34 0           my $group = {id=>$json->{ChatRoomName},name=>$json->{Topic},member=>[]};
35 0           for my $m (@{ $json->{MemberList} }){
  0            
36 0           my $member = {};
37 0           for(keys %Mojo::Weixin::Const::KEY_MAP_GROUP_MEMBER){
38 0   0       $member->{$_} = $m->{$KEY_MAP_GROUP_MEMBER{$_}} // "";
39             }
40 0           $member->{sex} = $self->code2sex($member->{sex});
41 0           push @{$group->{member}},$member;
  0            
42             }
43 0           return $group;
44             }
45             1;