Quote values in .ini file
[shpub.git] / src / shpub / Request.php
1 <?php
2 namespace shpub;
3
4 class Request
5 {
6     public $req;
7
8     public function __construct($host)
9     {
10         $this->req = new \HTTP_Request2($host->endpoints->micropub, 'POST');
11         if (version_compare(PHP_VERSION, '5.6.0', '<')) {
12             //correct ssl validation on php 5.5 is a pain, so disable
13             $this->req->setConfig('ssl_verify_host', false);
14             $this->req->setConfig('ssl_verify_peer', false);
15         }
16         $this->req->setHeader('Content-type', 'application/x-www-form-urlencoded');
17         $this->req->setHeader('Authorization', 'Bearer ' . $host->token);
18     }
19
20     public function send($body)
21     {
22         $this->req->setBody($body);
23         $res = $this->req->send();
24         if (intval($res->getStatus() / 100) != 2) {
25             Log::err(
26                 'Server returned an error status code ' . $res->getStatus()
27             );
28             Log::err($res->getBody());
29             exit(11);
30         }
31         return $res;
32     }
33 }