add support for delete queries
authorChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 16:07:43 +0000 (18:07 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 16:07:43 +0000 (18:07 +0200)
src/shpub/Cli.php
src/shpub/Command/Delete.php [new file with mode: 0644]

index eedbb10..e452f00 100644 (file)
@@ -166,6 +166,8 @@ class Cli
         Command_Like::opts($optParser);
         Command_Repost::opts($optParser);
 
+        Command_Delete::opts($optParser);
+
         return $optParser;
     }
 
diff --git a/src/shpub/Command/Delete.php b/src/shpub/Command/Delete.php
new file mode 100644 (file)
index 0000000..fec839f
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+namespace shpub;
+
+class Command_Delete extends Command_AbstractProps
+{
+    /**
+     * @var Config
+     */
+    protected $cfg;
+
+    public function __construct($cfg)
+    {
+        $this->cfg = $cfg;
+    }
+
+    public static function opts(\Console_CommandLine $optParser)
+    {
+        $cmd = $optParser->addCommand('delete');
+        $cmd->addArgument(
+            'url',
+            [
+                'optional'    => false,
+                'description' => 'URL to remove',
+            ]
+        );
+    }
+
+    public function run(\Console_CommandLine_Result $cmdRes)
+    {
+        $url = Validator::url($cmdRes->args['url'], 'url');
+        if ($url === false) {
+            exit(10);
+        }
+
+        $req = new Request($this->cfg->host, $this->cfg);
+        $req->req->addPostParameter('action', 'delete');
+        $req->req->addPostParameter('url', $url);
+
+        $res = $req->send();
+        Log::info('Post deleted from server');
+    }
+}
+?>