From: Christian Weiske Date: Thu, 15 Sep 2016 05:45:51 +0000 (+0200) Subject: Add rsvp command X-Git-Tag: v0.0.6~3 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/f5d91b8eb1a2d1e5876f7eb3871ae42f6092961d Add rsvp command --- diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 9daa59b..75f51bd 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -165,6 +165,7 @@ class Cli Command_Reply::opts($optParser); Command_Like::opts($optParser); Command_Repost::opts($optParser); + Command_Rsvp::opts($optParser); Command_Delete::opts($optParser); Command_Undelete::opts($optParser); diff --git a/src/shpub/Command/Rsvp.php b/src/shpub/Command/Rsvp.php new file mode 100644 index 0000000..5ed8ecd --- /dev/null +++ b/src/shpub/Command/Rsvp.php @@ -0,0 +1,64 @@ +addCommand('rsvp'); + static::optsGeneric($cmd); + $cmd->addArgument( + 'url', + [ + 'optional' => false, + 'description' => 'URL that is replied to', + ] + ); + $cmd->addArgument( + 'rsvp', + [ + 'optional' => false, + 'multiple' => false, + 'description' => 'Answer: yes, no, maybe', + ] + ); + $cmd->addArgument( + 'text', + [ + 'optional' => true, + 'multiple' => false, + 'description' => 'Answer text', + ] + ); + } + + public function run(\Console_CommandLine_Result $cmdRes) + { + $url = Validator::url($cmdRes->args['url'], 'url'); + if ($url === false) { + exit(10); + } + $rsvp = Validator::rsvp($cmdRes->args['rsvp']); + if ($rsvp === false) { + exit(10); + } + + $req = new Request($this->cfg->host, $this->cfg); + $req->req->addPostParameter('h', 'entry'); + $req->req->addPostParameter('in-reply-to', $url); + $req->req->addPostParameter('rsvp', $rsvp); + if ($cmdRes->args['text'] != '') { + $req->req->addPostParameter('content', $cmdRes->args['text']); + } + $this->handleGenericOptions($cmdRes, $req); + + $res = $req->send(); + $postUrl = $res->getHeader('Location'); + Log::info('RSVP created at server'); + Log::msg($postUrl); + } +} +?> diff --git a/src/shpub/Validator.php b/src/shpub/Validator.php index 1da91cb..283604d 100644 --- a/src/shpub/Validator.php +++ b/src/shpub/Validator.php @@ -28,5 +28,18 @@ class Validator return $url; } + + public static function rsvp($answer) + { + $allowed = ['yes', 'no', 'maybe']; + if (false === array_search($answer, $allowed)) { + Log::err( + 'Invalid RSVP answer given; allowed are: ' + . implode (', ', $allowed) + ); + return false; + } + return $answer; + } } ?>