Support auth servers with ? in their URL
[shpub.git] / src / shpub / Command / Rsvp.php
1 <?php
2 namespace shpub;
3
4 /**
5  * Repondez s'il vous plait - an answer to an invitation
6  *
7  * @author  Christian Weiske <cweiske@cweiske.de>
8  * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
9  * @link    http://cweiske.de/shpub.htm
10  */
11 class Command_Rsvp extends Command_AbstractProps
12 {
13     public static function opts(\Console_CommandLine $optParser)
14     {
15         $cmd = $optParser->addCommand('rsvp');
16         $cmd->description = 'Create a reservation';
17         static::addOptHtml($cmd);
18         static::optsGeneric($cmd);
19         $cmd->addArgument(
20             'url',
21             [
22                 'optional'    => false,
23                 'description' => 'URL that is replied to',
24             ]
25         );
26         $cmd->addArgument(
27             'rsvp',
28             [
29                 'optional'    => false,
30                 'multiple'    => false,
31                 'description' => 'Answer: yes, no, maybe',
32             ]
33         );
34         $cmd->addArgument(
35             'text',
36             [
37                 'optional'    => true,
38                 'multiple'    => false,
39                 'description' => 'Answer text',
40             ]
41         );
42     }
43
44     public function run(\Console_CommandLine_Result $cmdRes)
45     {
46         $url = Validator::url($cmdRes->args['url'], 'url');
47         if ($url === false) {
48             exit(10);
49         }
50         $rsvp = Validator::rsvp($cmdRes->args['rsvp']);
51         if ($rsvp === false) {
52             exit(10);
53         }
54
55         $req = new Request($this->cfg->host, $this->cfg);
56         $req->setType('entry');
57         $req->addProperty('in-reply-to', $url);
58         $req->addProperty('rsvp', $rsvp);
59         if ($cmdRes->args['text']) {
60             $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
61         }
62         $this->handleGenericOptions($cmdRes, $req);
63
64         $res = $req->send();
65         $postUrl = $res->getHeader('Location');
66         Log::info('RSVP created at server');
67         Log::msg($postUrl);
68     }
69 }
70 ?>