cb09ba77943e33231171523df6b73ca923b0f70b
[shpub.git] / src / shpub / Command / Reply.php
1 <?php
2 namespace shpub;
3
4 class Command_Reply
5 {
6     /**
7      * @var Config_Host
8      */
9     protected $host;
10
11     public function __construct($host)
12     {
13         $this->host = $host;
14     }
15
16     public function run($url, $text)
17     {
18         $url = Validator::url($url, 'url');
19         if ($url === false) {
20             exit(10);
21         }
22
23         $body = http_build_query(
24             [
25                 'h'           => 'entry',
26                 'content'     => $text,
27                 'in-reply-to' => $url,
28             ]
29         );
30
31         $req = new Request($this->host);
32         $res = $req->send($body);
33         $postUrl = $res->getHeader('Location');
34         echo "Reply created at server\n";
35         echo $postUrl . "\n";
36     }
37 }
38 ?>