X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/e53ff38824e76ee587c3c7b7fffebc551933e761..69fec2594f370eeb8a73c83c70dbeb50855fe65d:/src/shpub/Command/Like.php diff --git a/src/shpub/Command/Like.php b/src/shpub/Command/Like.php index 7daafc2..a619f7a 100644 --- a/src/shpub/Command/Like.php +++ b/src/shpub/Command/Like.php @@ -1,37 +1,45 @@ host = $host; + $cmd = $optParser->addCommand('like'); + $cmd->description = 'Create a like'; + static::optsGeneric($cmd); + $cmd->addArgument( + 'url', + [ + 'optional' => false, + 'description' => 'URL that is liked', + ] + ); } - public function run($url) + public function run(\Console_CommandLine_Result $cmdRes) { - $url = Validator::url($url, 'url'); + $url = Validator::url($cmdRes->args['url'], 'url'); if ($url === false) { exit(10); } - $body = http_build_query( - [ - 'h' => 'entry', - 'like-of' => $url, - ] - ); + $req = new Request($this->cfg->host, $this->cfg); + $req->setType('entry'); + $req->addProperty('like-of', $url); + + $this->handleGenericOptions($cmdRes, $req); + $res = $req->send(); - $req = new Request($this->host); - $res = $req->send($body); $postUrl = $res->getHeader('Location'); - echo "Like created at server\n"; - echo $postUrl . "\n"; + if ($postUrl === null) { + Log::err('Error: Server sent no "Location" header and said:'); + Log::err($res->getBody()); + exit(20); + } else { + Log::info('Like created at server'); + Log::msg($postUrl); + } } } ?>