1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Threema GmbH |
4
|
|
|
* @copyright Copyright (c) 2015-2016 Threema GmbH |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
namespace Threema\MsgApi\Commands\Results; |
9
|
|
|
|
10
|
|
|
class CapabilityResult extends Result { |
11
|
|
|
/** |
12
|
|
|
* @var string[] |
13
|
|
|
*/ |
14
|
|
|
private $capabilities; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param string $response |
18
|
|
|
*/ |
19
|
|
|
protected function processResponse($response) { |
20
|
|
|
$this->capabilities = |
21
|
|
|
array_unique(array_filter(explode(',', $response !== null && strlen($response) > 0 ? $response : ''))); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return string[] |
26
|
|
|
*/ |
27
|
|
|
public function getCapabilities() { |
28
|
|
|
return $this->capabilities; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* the threema id can receive text |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
|
|
public function canText() { |
36
|
|
|
return $this->can('text'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* the threema id can receive images |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function canImage() { |
44
|
|
|
return $this->can('image'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* the threema id can receive videos |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public function canVideo() { |
52
|
|
|
return $this->can('video'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* the threema id can receive files |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function canAudio() { |
60
|
|
|
return $this->can('audio'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* the threema id can receive files |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
public function canFile() { |
68
|
|
|
return $this->can('file'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function can($key) { |
72
|
|
|
return null !== $this->capabilities |
73
|
|
|
&& true === in_array($key, $this->capabilities); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param int $httpCode |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
protected function getErrorMessageByErrorCode($httpCode) { |
81
|
|
|
switch($httpCode) { |
82
|
|
|
case 401: |
83
|
|
|
return 'API identity or secret incorrect'; |
84
|
|
|
case 404: |
85
|
|
|
return 'No matching ID found'; |
86
|
|
|
case 500: |
87
|
|
|
return 'A temporary internal server error has occurred'; |
88
|
|
|
default: |
89
|
|
|
return 'Unknown error'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|