From: Christian Weiske Date: Tue, 13 Sep 2016 15:05:18 +0000 (+0200) Subject: add support for reposts X-Git-Tag: v0.0.5~4 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/f2ef5ad9726ed325ffb846591ed6e701a0894dee add support for reposts --- diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 30c2d1f..57ccee7 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -163,6 +163,7 @@ class Cli Command_Note::opts($optParser); Command_Reply::opts($optParser); Command_Like::opts($optParser); + Command_Repost::opts($optParser); return $optParser; } diff --git a/src/shpub/Command/Repost.php b/src/shpub/Command/Repost.php new file mode 100644 index 0000000..2f4b46f --- /dev/null +++ b/src/shpub/Command/Repost.php @@ -0,0 +1,54 @@ +cfg = $cfg; + } + + public static function opts(\Console_CommandLine $optParser) + { + $cmd = $optParser->addCommand('repost'); + static::optsGeneric($cmd); + $cmd->addArgument( + 'url', + [ + 'optional' => false, + 'description' => 'URL that shall be reposted', + ] + ); + } + + public function run(\Console_CommandLine_Result $cmdRes) + { + $url = Validator::url($cmdRes->args['url'], 'url'); + if ($url === false) { + exit(10); + } + + $req = new Request($this->cfg->host, $this->cfg); + $req->req->addPostParameter('h', 'entry'); + $req->req->addPostParameter('repost-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 { + Log::info('Repost created at server'); + Log::msg($postUrl); + } + } +} +?>