From: Christian Weiske Date: Tue, 6 Sep 2016 21:16:26 +0000 (+0200) Subject: likes work! X-Git-Tag: v0.0.1~12 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/3c23b2cde4f8d6de57d5e1cc86828d6d200da65d likes work! --- diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index fb22d3f..32dcbe2 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -181,6 +181,8 @@ class Cli 'Server data incomplete. "shpub connect" first.' ); } + + $this->cfg->host->loadEndpoints(); } } ?> diff --git a/src/shpub/Command/Like.php b/src/shpub/Command/Like.php new file mode 100644 index 0000000..70e836f --- /dev/null +++ b/src/shpub/Command/Like.php @@ -0,0 +1,47 @@ +host = $host; + } + + public function run($url) + { + $url = Validator::url($url, 'url'); + if ($url === false) { + exit(10); + } + + $body = http_build_query( + [ + 'h' => 'entry', + 'like-of' => $url, + ] + ); + + $req = new \HTTP_Request2($this->host->endpoints->micropub, 'POST'); + $req->setHeader('Content-type', 'application/x-www-form-urlencoded'); + $req->setHeader('Authorization', 'Bearer ' . $this->host->token); + $req->setBody($body); + $res = $req->send(); + if (intval($res->getStatus() / 100) != 2) { + Log::err( + 'Server returned an error status code ' . $res->getStatus() + ); + Log::err($res->getBody()); + exit(11); + } + $postUrl = $res->getHeader('Location'); + echo "Like created at server\n"; + echo $postUrl . "\n"; + } +} +?> diff --git a/src/shpub/Validator.php b/src/shpub/Validator.php new file mode 100644 index 0000000..f7f3605 --- /dev/null +++ b/src/shpub/Validator.php @@ -0,0 +1,26 @@ +