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