7daafc22d7ee4afb51ebe1729c72ec2d941fe9e5
[shpub.git] / src / shpub / Command / Like.php
1 <?php
2 namespace shpub;
3
4 class Command_Like
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)
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                 'like-of' => $url,
27             ]
28         );
29
30         $req = new Request($this->host);
31         $res = $req->send($body);
32         $postUrl = $res->getHeader('Location');
33         echo "Like created at server\n";
34         echo $postUrl . "\n";
35     }
36 }
37 ?>