| 1 | package WebService::SendBird::GroupChat; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use JSON::MaybeXS (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use WebService::SendBird::User; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 3 | our $VERSION = '0.002'; ## VERSION | |||||||||||
| 11 | |||||||||||||
| 12 | =head1 NAME | ||||||||||||
| 13 | |||||||||||||
| 14 | WebService::SendBird::GroupChat - SendBird Group Chat | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||
| 17 | |||||||||||||
| 18 | use WebService::SendBird::Group; | ||||||||||||
| 19 | |||||||||||||
| 20 | my $chat = WebService::SendBird::User->new( | ||||||||||||
| 21 | api_client => $api, | ||||||||||||
| 22 | channel_url => 'chat_room_1', | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | |||||||||||||
| 25 | $chat->update(name => 'Gossips'); | ||||||||||||
| 26 | |||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||
| 28 | |||||||||||||
| 29 | Class for SendBird Group Channel. Information about structure could be found at L<API Documentation|https://docs.sendbird.com/platform/group_channel> | ||||||||||||
| 30 | |||||||||||||
| 31 | =cut | ||||||||||||
| 32 | |||||||||||||
| 33 | 3 | ▶ | use constant REQUIRED_FIELDS => qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | api_client | ||||||||||||
| 35 | channel_url | ||||||||||||
| 36 | 3 | ); | |||||||||||
| 37 | |||||||||||||
| 38 | 3 | ▶ | use constant OPTIONAL_FIELDS => qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | is_broadcast | ||||||||||||
| 40 | name | ||||||||||||
| 41 | is_access_code_required | ||||||||||||
| 42 | is_super | ||||||||||||
| 43 | joined_member_count | ||||||||||||
| 44 | is_public | ||||||||||||
| 45 | cover_url | ||||||||||||
| 46 | unread_mention_count | ||||||||||||
| 47 | is_created | ||||||||||||
| 48 | is_distinct | ||||||||||||
| 49 | is_ephemeral | ||||||||||||
| 50 | freeze | ||||||||||||
| 51 | data | ||||||||||||
| 52 | is_discoverable | ||||||||||||
| 53 | last_message | ||||||||||||
| 54 | sms_fallback_interval_sec | ||||||||||||
| 55 | custom_type | ||||||||||||
| 56 | unread_message_count | ||||||||||||
| 57 | created_at | ||||||||||||
| 58 | member_count | ||||||||||||
| 59 | sms_fallback_enabled | ||||||||||||
| 60 | max_length_message | ||||||||||||
| 61 | members | ||||||||||||
| 62 | 3 | ); | |||||||||||
| 63 | |||||||||||||
| 64 | { | ||||||||||||
| 65 | 3 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 66 | 3 | for my $field (REQUIRED_FIELDS, OPTIONAL_FIELDS) { | |||||||||||
| 67 | 6 | ▶ | *{__PACKAGE__ . '::' . $field} = sub { shift->{$field} }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | =head2 new | ||||||||||||
| 72 | |||||||||||||
| 73 | Creates an instance of SendBird Group Chat | ||||||||||||
| 74 | |||||||||||||
| 75 | =over 4 | ||||||||||||
| 76 | |||||||||||||
| 77 | =item * C<api_client> - SendBird API client L<WebService::SendBird>. | ||||||||||||
| 78 | |||||||||||||
| 79 | =item * C<channel_url> - Unique Channel Identifier | ||||||||||||
| 80 | |||||||||||||
| 81 | =back | ||||||||||||
| 82 | |||||||||||||
| 83 | =cut | ||||||||||||
| 84 | |||||||||||||
| 85 | 3 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||
| 86 | 3 | my ($cls, %params) = @_; | |||||||||||
| 87 | |||||||||||||
| 88 | 3 | my $self = +{}; | |||||||||||
| 89 | 3 | ▶ | $self->{$_} = delete $params{$_} or Carp::croak "$_ is missed" for (REQUIRED_FIELDS); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | |||||||||||||
| 91 | 3 | $self->{$_} = delete $params{$_} for (OPTIONAL_FIELDS); | |||||||||||
| 92 | |||||||||||||
| 93 | 3 | ▶ | $self->{members} //= []; | ||||||||||
|
Condition50%1/2
$self->{"members"} //= []
MC/DC0%0/1
$self->{"members"} //= []
$self->{"members"}
Truth table50%1/2
A
A= $self->{"members"}
| |||||||||||||
| 94 | 0 | my @obj_members = map { WebService::SendBird::User->new(%$_, api_client => $self->{api_client}) } @{$self->{members}}; | |||||||||||
| 95 | 3 | $self->{members} = \@obj_members; | |||||||||||
| 96 | |||||||||||||
| 97 | 3 | return bless $self, $cls; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | =head2 Getters | ||||||||||||
| 101 | |||||||||||||
| 102 | =over 4 | ||||||||||||
| 103 | |||||||||||||
| 104 | =item * C<api_client> | ||||||||||||
| 105 | |||||||||||||
| 106 | =item * C<channel_url> | ||||||||||||
| 107 | |||||||||||||
| 108 | =item * C<is_broadcast> | ||||||||||||
| 109 | |||||||||||||
| 110 | =item * C<name> | ||||||||||||
| 111 | |||||||||||||
| 112 | =item * C<is_access_code_required> | ||||||||||||
| 113 | |||||||||||||
| 114 | =item * C<is_super> | ||||||||||||
| 115 | |||||||||||||
| 116 | =item * C<joined_member_count> | ||||||||||||
| 117 | |||||||||||||
| 118 | =item * C<is_public> | ||||||||||||
| 119 | |||||||||||||
| 120 | =item * C<cover_url> | ||||||||||||
| 121 | |||||||||||||
| 122 | =item * C<unread_mention_count> | ||||||||||||
| 123 | |||||||||||||
| 124 | =item * C<is_created> | ||||||||||||
| 125 | |||||||||||||
| 126 | =item * C<is_distinct> | ||||||||||||
| 127 | |||||||||||||
| 128 | =item * C<is_ephemeral> | ||||||||||||
| 129 | |||||||||||||
| 130 | =item * C<freeze> | ||||||||||||
| 131 | |||||||||||||
| 132 | =item * C<data> | ||||||||||||
| 133 | |||||||||||||
| 134 | =item * C<is_discoverable> | ||||||||||||
| 135 | |||||||||||||
| 136 | =item * C<last_message> | ||||||||||||
| 137 | |||||||||||||
| 138 | =item * C<sms_fallback_interval_sec> | ||||||||||||
| 139 | |||||||||||||
| 140 | =item * C<custom_type> | ||||||||||||
| 141 | |||||||||||||
| 142 | =item * C<unread_message_count> | ||||||||||||
| 143 | |||||||||||||
| 144 | =item * C<created_at> | ||||||||||||
| 145 | |||||||||||||
| 146 | =item * C<member_count> | ||||||||||||
| 147 | |||||||||||||
| 148 | =item * C<sms_fallback_enabled> | ||||||||||||
| 149 | |||||||||||||
| 150 | =item * C<max_length_message> | ||||||||||||
| 151 | |||||||||||||
| 152 | =item * C<members> | ||||||||||||
| 153 | |||||||||||||
| 154 | =back | ||||||||||||
| 155 | |||||||||||||
| 156 | =cut | ||||||||||||
| 157 | |||||||||||||
| 158 | =head2 update | ||||||||||||
| 159 | |||||||||||||
| 160 | Updates the group channel at SendBird API | ||||||||||||
| 161 | |||||||||||||
| 162 | Information about parameters could be found at L<API Documentation|https://docs.sendbird.com/platform/group_channel#3_update_a_channel> | ||||||||||||
| 163 | |||||||||||||
| 164 | =cut | ||||||||||||
| 165 | |||||||||||||
| 166 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 167 | 0 | my ($self, %params) = @_; | |||||||||||
| 168 | |||||||||||||
| 169 | 0 | my $res = $self->api_client->request( | |||||||||||
| 170 | PUT => 'group_channels/' . $self->channel_url, | ||||||||||||
| 171 | \%params | ||||||||||||
| 172 | ); | ||||||||||||
| 173 | |||||||||||||
| 174 | 0 | $self->{$_} = $res->{$_} for qw(OPTIONAL_FIELDS); | |||||||||||
| 175 | |||||||||||||
| 176 | 0 | return $self; | |||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | =head2 set_freeze | ||||||||||||
| 180 | |||||||||||||
| 181 | Freeze or unfreeze the channel. | ||||||||||||
| 182 | |||||||||||||
| 183 | See L<https://sendbird.com/docs/chat/v3/platform-api/guides/group-channel#2-freeze-a-channel>. | ||||||||||||
| 184 | |||||||||||||
| 185 | =cut | ||||||||||||
| 186 | |||||||||||||
| 187 | 2 | ▶ | sub set_freeze { | ||||||||||
|
Subroutine
set_freeze: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 188 | 2 | my ($self, $freeze) = @_; | |||||||||||
| 189 | |||||||||||||
| 190 | 2 | ▶ | $freeze = $freeze ? JSON::MaybeXS::true : JSON::MaybeXS::false; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 191 | |||||||||||||
| 192 | 2 | my $res = $self->api_client->request( | |||||||||||
| 193 | PUT => 'group_channels/' . $self->channel_url . '/freeze', | ||||||||||||
| 194 | {freeze => $freeze}); | ||||||||||||
| 195 | |||||||||||||
| 196 | 2 | $self->{freeze} = $res->{freeze}; | |||||||||||
| 197 | 2 | return $self; | |||||||||||
| 198 | } | ||||||||||||
| 199 | |||||||||||||
| 200 | 3 | 1; | |||||||||||