From 0103f507ef72ef369b2f7e9f90fe8922b691c33f Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 31 Mar 2017 21:42:40 +0200 Subject: [PATCH] Add command to list syndication targets Part of https://github.com/cweiske/shpub/issues/2 --- src/shpub/Cli.php | 1 + src/shpub/Command/Targets.php | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/shpub/Command/Targets.php diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 8ea550e..733f4df 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -119,6 +119,7 @@ class Cli Command_Connect::opts($optParser); Command_Server::opts($optParser); + Command_Targets::opts($optParser); Command_Article::opts($optParser); Command_Note::opts($optParser); diff --git a/src/shpub/Command/Targets.php b/src/shpub/Command/Targets.php new file mode 100644 index 0000000..eb66692 --- /dev/null +++ b/src/shpub/Command/Targets.php @@ -0,0 +1,55 @@ + + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/shpub.htm + */ +class Command_Targets +{ + public function __construct(Config $cfg) + { + $this->cfg = $cfg; + } + + public static function opts(\Console_CommandLine $optParser) + { + $cmd = $optParser->addCommand('targets'); + $cmd->description = 'List a server\'s syndication targets'; + } + + public function run(\Console_CommandLine_Result $cmdRes) + { + $req = new Request($this->cfg->host, $this->cfg); + $req->req->setMethod('GET'); + $req->req->setHeader('Content-type'); + $req->req->getUrl()->setQueryVariable('q', 'syndicate-to'); + $res = $req->send(); + + if ($res->getHeader('content-type') != 'application/json') { + Log::err('response data are not of type application/json'); + exit(2); + } + + $data = json_decode($res->getBody(), true); + if (!isset($data['syndicate-to'])) { + Log::err('"syndicate-to" property missing'); + exit(2); + } + + foreach ($data['syndicate-to'] as $target) { + Log::msg($target['name']); + Log::msg(' ' . $target['uid']); + if (isset($target['user'])) { + Log::msg(' User: ' . $target['user']['name']); + } + if (isset($target['service'])) { + Log::msg(' Service: ' . $target['service']['name']); + } + } + } +} +?> -- 2.30.2