ad19b8f529838a4014f50bc70420bff4eb1932b1
[shpub.git] / src / shpub / Command / Like.php
1 <?php
2 namespace shpub;
3
4 class Command_Like extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('like');
9         static::optsGeneric($cmd);
10         $cmd->addArgument(
11             'url',
12             [
13                 'optional'    => false,
14                 'description' => 'URL that is liked',
15             ]
16         );
17     }
18
19     public function run(\Console_CommandLine_Result $cmdRes)
20     {
21         $url = Validator::url($cmdRes->args['url'], 'url');
22         if ($url === false) {
23             exit(10);
24         }
25
26         $req = new Request($this->cfg->host, $this->cfg);
27         $req->setType('entry');
28         $req->addProperty('like-of', $url);
29
30         $this->handleGenericOptions($cmdRes, $req);
31         $res = $req->send();
32
33         $postUrl = $res->getHeader('Location');
34         if ($postUrl === null) {
35             Log::err('Error: Server sent no "Location" header and said:');
36             Log::err($res->getBody());
37             exit(20);
38         } else {
39             Log::info('Like created at server');
40             Log::msg($postUrl);
41         }
42     }
43 }
44 ?>