Support --html everywhere
[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 class Command_Rsvp extends Command_AbstractProps
8 {
9     public static function opts(\Console_CommandLine $optParser)
10     {
11         $cmd = $optParser->addCommand('rsvp');
12         static::addOptHtml($cmd);
13         static::optsGeneric($cmd);
14         $cmd->addArgument(
15             'url',
16             [
17                 'optional'    => false,
18                 'description' => 'URL that is replied to',
19             ]
20         );
21         $cmd->addArgument(
22             'rsvp',
23             [
24                 'optional'    => false,
25                 'multiple'    => false,
26                 'description' => 'Answer: yes, no, maybe',
27             ]
28         );
29         $cmd->addArgument(
30             'text',
31             [
32                 'optional'    => true,
33                 'multiple'    => false,
34                 'description' => 'Answer text',
35             ]
36         );
37     }
38
39     public function run(\Console_CommandLine_Result $cmdRes)
40     {
41         $url = Validator::url($cmdRes->args['url'], 'url');
42         if ($url === false) {
43             exit(10);
44         }
45         $rsvp = Validator::rsvp($cmdRes->args['rsvp']);
46         if ($rsvp === false) {
47             exit(10);
48         }
49
50         $req = new Request($this->cfg->host, $this->cfg);
51         $req->setType('h', 'entry');
52         $req->addProperty('in-reply-to', $url);
53         $req->addProperty('rsvp', $rsvp);
54         if ($cmdRes->args['text']) {
55             $req->addContent($cmdRes->args['text'], $cmdRes->options['html']);
56         }
57         $this->handleGenericOptions($cmdRes, $req);
58
59         $res = $req->send();
60         $postUrl = $res->getHeader('Location');
61         Log::info('RSVP created at server');
62         Log::msg($postUrl);
63     }
64 }
65 ?>