X-Git-Url: https://git.cweiske.de/shpub.git/blobdiff_plain/4e67ee4a6c7cc62f9c12f091660aae6b1e87d53b..f46e4d3108d944bcf86f5905780f1fcfd441c036:/src/shpub/Command/Like.php diff --git a/src/shpub/Command/Like.php b/src/shpub/Command/Like.php index e7c6052..65020dc 100644 --- a/src/shpub/Command/Like.php +++ b/src/shpub/Command/Like.php @@ -1,21 +1,12 @@ cfg = $cfg; - } - public static function opts(\Console_CommandLine $optParser) { $cmd = $optParser->addCommand('like'); + static::optsGeneric($cmd); $cmd->addArgument( 'url', [ @@ -25,30 +16,28 @@ class Command_Like ); } - public function run($command) + public function run(\Console_CommandLine_Result $cmdRes) { - $url = Validator::url($command->args['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); - $res = $req->send($body); + $req->req->addPostParameter('h', 'entry'); + $req->req->addPostParameter('like-of', $url); + + $this->handleGenericOptions($cmdRes, $req); + $res = $req->send(); + $postUrl = $res->getHeader('Location'); if ($postUrl === null) { Log::err('Error: Server sent no "Location" header and said:'); Log::err($res->getBody()); exit(20); } else { - echo "Like created at server\n"; - echo $postUrl . "\n"; + Log::info('Like created at server'); + Log::msg($postUrl); } } }