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\MsgApi\Connection; |
12
|
|
|
use Threema\MsgApi\ConnectionSettings; |
13
|
|
|
use Threema\MsgApi\PublicKeyStore; |
14
|
|
|
|
15
|
|
|
class Credits extends Base { |
16
|
|
|
/** |
17
|
|
|
* @var PublicKeyStore |
18
|
|
|
*/ |
19
|
|
|
private $publicKeyStore; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param PublicKeyStore $publicKeyStore |
23
|
|
|
*/ |
24
|
|
|
public function __construct(PublicKeyStore $publicKeyStore) { |
25
|
|
|
parent::__construct('Get remaining credits', |
26
|
|
|
array(self::argFrom, self::argSecret), |
27
|
|
|
'Get the remaining credits'); |
28
|
|
|
$this->publicKeyStore = $publicKeyStore; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function doRun() { |
32
|
|
|
$from = $this->getArgumentThreemaId(self::argFrom); |
33
|
|
|
$secret = $this->getArgument(self::argSecret); |
34
|
|
|
|
35
|
|
|
Common::required($from, $secret); |
36
|
|
|
|
37
|
|
|
//define connection settings |
38
|
|
|
$settings = new ConnectionSettings($from, $secret); |
39
|
|
|
|
40
|
|
|
//create a connection |
41
|
|
|
$connector = new Connection($settings, $this->publicKeyStore); |
42
|
|
|
|
43
|
|
|
$result = $connector->credits(); |
44
|
|
|
Common::required($result); |
45
|
|
|
if($result->isSuccess()) { |
46
|
|
|
Common::l("remaining credits: ".$result->getCredits()); |
47
|
|
|
} |
48
|
|
|
else { |
49
|
|
|
Common::e($result->getErrorMessage()); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|