debug option to print curl requests
[shpub.git] / src / shpub / Command / Like.php
index 7daafc22d7ee4afb51ebe1729c72ec2d941fe9e5..26f615a163e8d5e2f7643a71e866b58d70d1c441 100644 (file)
@@ -4,13 +4,13 @@ namespace shpub;
 class Command_Like
 {
     /**
-     * @var Config_Host
+     * @var Config
      */
-    protected $host;
+    protected $cfg;
 
-    public function __construct($host)
+    public function __construct($cfg)
     {
-        $this->host = $host;
+        $this->cfg = $cfg;
     }
 
     public function run($url)
@@ -27,11 +27,17 @@ class Command_Like
             ]
         );
 
-        $req = new Request($this->host);
+        $req = new Request($this->cfg->host, $this->cfg);
         $res = $req->send($body);
         $postUrl = $res->getHeader('Location');
-        echo "Like created at server\n";
-        echo $postUrl . "\n";
+        if ($postUrl === null) {
+            Log::err('Error: Server sent no "Location" header and said:');
+            Log::err($res->getBody());
+            exit(20);
+        } else {
+            echo "Like created at server\n";
+            echo $postUrl . "\n";
+        }
     }
 }
 ?>