1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Threema GmbH |
4
|
|
|
* @copyright Copyright (c) 2015-2016 Threema GmbH |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
namespace Threema\Console\Command; |
9
|
|
|
|
10
|
|
|
use Threema\Console\Common; |
11
|
|
|
use Threema\Core\Exception; |
12
|
|
|
use Threema\MsgApi\Connection; |
13
|
|
|
use Threema\MsgApi\ConnectionSettings; |
14
|
|
|
use Threema\MsgApi\PublicKeyStore; |
15
|
|
|
|
16
|
|
|
class Capability extends Base { |
17
|
|
|
/** |
18
|
|
|
* @var \Threema\MsgApi\PublicKeyStore |
19
|
|
|
*/ |
20
|
|
|
private $publicKeyStore; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param PublicKeyStore $publicKeyStore |
24
|
|
|
*/ |
25
|
|
|
public function __construct(PublicKeyStore $publicKeyStore) { |
26
|
|
|
parent::__construct('Fetch Capability', |
27
|
|
|
array(self::argThreemaId, self::argFrom, self::argSecret), |
28
|
|
|
'Fetch the capabilities of a Threema ID'); |
29
|
|
|
$this->publicKeyStore = $publicKeyStore; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function doRun() { |
33
|
|
|
$threemaId = $this->getArgumentThreemaId(self::argThreemaId); |
34
|
|
|
$from = $this->getArgumentThreemaId(self::argFrom); |
35
|
|
|
$secret = $this->getArgument(self::argSecret); |
36
|
|
|
|
37
|
|
|
Common::required($threemaId, $from, $secret); |
38
|
|
|
|
39
|
|
|
if(strlen($threemaId) != 8) { |
40
|
|
|
throw new Exception('invalid threema id'); |
41
|
|
|
} |
42
|
|
|
//define connection settings |
43
|
|
|
$settings = new ConnectionSettings($from, $secret); |
44
|
|
|
|
45
|
|
|
//create a connection |
46
|
|
|
$connector = new Connection($settings, $this->publicKeyStore); |
47
|
|
|
|
48
|
|
|
$result = $connector->keyCapability($threemaId); |
49
|
|
|
Common::required($result); |
50
|
|
|
if($result->isSuccess()) { |
51
|
|
|
Common::l(implode("\n", $result->getCapabilities())); |
52
|
|
|
} |
53
|
|
|
else { |
54
|
|
|
Common::e($result->getErrorMessage()); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|