git.cweiske.de
/
shpub.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add "published" option to notes
[shpub.git]
/
src
/
shpub
/
Command
/
Like.php
diff --git
a/src/shpub/Command/Like.php
b/src/shpub/Command/Like.php
index 7daafc22d7ee4afb51ebe1729c72ec2d941fe9e5..e7c6052fc6866b458b01a820f7dd7a03bdc845ad 100644
(file)
--- a/
src/shpub/Command/Like.php
+++ b/
src/shpub/Command/Like.php
@@
-4,18
+4,30
@@
namespace shpub;
class Command_Like
{
/**
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
)
+ public
static function opts(\Console_CommandLine $optParser
)
{
{
- $url = Validator::url($url, 'url');
+ $cmd = $optParser->addCommand('like');
+ $cmd->addArgument(
+ 'url',
+ [
+ 'optional' => false,
+ 'description' => 'URL that is liked',
+ ]
+ );
+ }
+
+ public function run($command)
+ {
+ $url = Validator::url($command->args['url'], 'url');
if ($url === false) {
exit(10);
}
if ($url === false) {
exit(10);
}
@@
-27,11
+39,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');
$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";
+ }
}
}
?>
}
}
?>