SendBird/User.pm

filter: Statementstmt 74.4% 32 / 43 Branchbran 50.0% 1 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 72.7% 8 / 11 Podpod 100% 3 / 3 totaltotal 70.9% 44 / 62 CC 6 SCAR 11.0
CC
6
Cov
70%
update
6.0
issue_session_token
6.0
new
4.0
CRAP 3.0
« SendBird.pm ↑ Summary SendBird/GroupChat.pm »
1 package WebService::SendBird::User;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.002'; ## VERSION
10  
11 =head1 NAME
12  
13 WebService::SendBird::User - SendBird User
14  
15 =head1 SYNOPSIS
16  
17 use WebService::SendBird::User;
18  
19 my $user = WebService::SendBird::User->new(
20 api_client => $api,
21 user_id => 'my_chat_user_1',
22 );
23  
24 $user->update(nickname => 'cucumber');
25  
26 my $token_data = $user->issue_session_token;
27  
28 =head1 DESCRIPTION
29  
30 Class for SendBird User. Information about structure could be found at L<API Documentation|https://docs.sendbird.com/platform/user>
31  
32 =cut
33  
34 4 ▶use constant REQUIRED_FIELDS => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
35 api_client
36 user_id
37 4 );
38  
39 4 ▶use constant OPTIONAL_FIELDS => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
40 phone_number
41 has_ever_logged_in
42 session_tokens
43 access_token
44 discovery_keys
45 is_online
46 last_seen_at
47 nickname
48 profile_url
49 metadata
50 4 );
51  
52 {
53 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 4 for my $field (REQUIRED_FIELDS, OPTIONAL_FIELDS) {
55 0 ▶ *{__PACKAGE__ . '::' . $field} = sub { shift->{$field} };
Subroutine __ANON__: not called CC=1 SCAR=0.4
56 }
57 }
58  
59 =head2 new
60  
61 Creates an instance of SendBird User
62  
63 =over 4
64  
65 =item * C<api_client> - SendBird API client L<WebService::SendBird>.
66  
67 =item * C<user_id> - Unique User Identifier
68  
69 =back
70  
71 =cut
72  
73 2 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
74 2 my ($cls, %params) = @_;
75  
76 2 my $self = +{};
77 2 ▶ $self->{$_} = delete $params{$_} or Carp::croak "$_ is missed" for (REQUIRED_FIELDS);
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} = delete $params{$_} or Carp::croak("$_ is missed") 4 0 4
78  
79 2 $self->{$_} = delete $params{$_} for (OPTIONAL_FIELDS);
80  
81 2 return bless $self, $cls;
82 }
83  
84 =head2 Getters
85  
86 =over 4
87  
88 =item * C<api_client>
89  
90 =item * C<user_id>
91  
92 =item * C<phone_number>
93  
94 =item * C<has_ever_logged_in>
95  
96 =item * C<session_tokens>
97  
98 =item * C<access_token>
99  
100 =item * C<discovery_keys>
101  
102 =item * C<is_online>
103  
104 =item * C<last_seen_at>
105  
106 =item * C<nickname>
107  
108 =item * C<profile_url>
109  
110 =item * C<metadata>
111  
112 =back
113  
114 =cut
115  
116 =head2 update
117  
118 Updates the user at SendBird API
119  
120 Information about parameters could be found at L<API Documentation|https://docs.sendbird.com/platform/user#3_update_a_user>
121  
122 =cut
123  
124 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
125 0 my ($self, %params) = @_;
126  
127 0 my $res = $self->api_client->request(
128 PUT => 'users/' . $self->user_id,
129 \%params
130 );
131  
132 0 $self->{$_} = $res->{$_} for (OPTIONAL_FIELDS);
133  
134 0 return $self;
135 }
136  
137 =head2 issue_session_token
138  
139 Issues new session token and returns hash ref with token and expiration time of this token.
140  
141 =cut
142  
143 0 ▶sub issue_session_token {
Subroutine issue_session_token: not called CC=2 SCAR=17.9
Pod documented
144 0 my ($self) = @_;
145  
146 0 $self->update(issue_session_token => JSON::MaybeXS::true);
147  
148 0 ▶ my $tokens = $self->session_tokens // [];
Condition0%0/2
$self->session_tokens // []
l!l
00
MC/DC0%0/1
$self->session_tokens // []
$self->session_tokens
Truth table0%0/2
A
A= $self->session_tokens
Aresult
11
00
149  
150 0 my ($latest_token) = sort { $b->{expires_at} <=> $a->{expires_at} } @$tokens;
151  
152 0 return $latest_token;
153 }
154  
155 4 1;
« SendBird.pm ↑ Summary SendBird/GroupChat.pm »