1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CL\Slack\Payload; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Cas Leentfaar <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
abstract class AbstractPayloadResponse implements PayloadResponseInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var bool |
12
|
|
|
*/ |
13
|
|
|
private $ok; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $error; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $needed; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $provided; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
57 |
|
public function isOk() |
34
|
|
|
{ |
35
|
57 |
|
return (bool) $this->ok; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
58 |
|
public function getError() |
42
|
|
|
{ |
43
|
58 |
|
return $this->error; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
57 |
|
public function getErrorExplanation() |
50
|
|
|
{ |
51
|
57 |
|
if (null === $error = $this->getError()) { |
52
|
1 |
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
56 |
|
$ownErrors = $this->getPossibleErrors(); |
56
|
56 |
|
if (array_key_exists($error, $ownErrors)) { |
57
|
56 |
|
return $ownErrors[$error]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return sprintf('Unknown error: "%s"', $error); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
56 |
|
protected function getPossibleErrors() |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
56 |
|
'account_inactive' => 'Authentication token is for a deleted user or team', |
70
|
56 |
|
'already_archived' => 'Channel has already been archived', |
71
|
56 |
|
'already_in_channel' => 'Invited user is already in the channel', |
72
|
56 |
|
'invalid_auth' => 'Invalid authentication token', |
73
|
56 |
|
'invalid_token' => 'Invalid token supplied', |
74
|
56 |
|
'cant_archive_general' => 'You cannot archive the general channel', |
75
|
56 |
|
'cant_invite' => 'User cannot be invited to this channel', |
76
|
56 |
|
'cant_invite_self' => 'Authenticated user cannot invite themselves to a channel', |
77
|
56 |
|
'cant_kick_from_general' => 'User cannot be removed from #general', |
78
|
56 |
|
'cant_kick_from_last_channel' => 'User cannot be removed from the last channel they\'re in', |
79
|
56 |
|
'cant_kick_self' => 'Authenticated user can\'t kick themselves from a channel', |
80
|
56 |
|
'channel_not_found' => 'Channel could not be found', |
81
|
56 |
|
'is_archived' => 'Channel has been archived', |
82
|
56 |
|
'last_ra_channel' => 'You cannot archive the last channel for a restricted account', |
83
|
56 |
|
'name_taken' => 'A channel cannot be created with the given name', |
84
|
56 |
|
'no_channel' => 'A value passed for name was empty', |
85
|
56 |
|
'not_authed' => 'No authentication token provided', |
86
|
56 |
|
'not_in_channel' => 'User was not in the channel', |
87
|
56 |
|
'rate_limited' => 'Application has posted too many messages, read the Rate Limit documentation (https://api.slack.com/docs/rate-limits) for more information', |
88
|
56 |
|
'restricted_action' => 'A team preference prevents authenticated user from archiving', |
89
|
56 |
|
'user_is_bot' => 'This method cannot be called by a bot user', |
90
|
56 |
|
'user_is_ultra_restricted' => 'This method cannot be called by a single channel guest', |
91
|
56 |
|
'user_not_found' => 'User could not be found', |
92
|
56 |
|
'missing_scope' => sprintf("The application's permissions is not enough to complete this request. Needed scope is '%s', provided - [%s].", |
93
|
56 |
|
$this->needed, $this->provided), |
94
|
56 |
|
'token_revoked'=>'Token was revoked. Try to reinstall the application to get a new one.', |
95
|
56 |
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|