Last active
October 30, 2015 10:58
-
-
Save YOzaz/d6a78a623633ba8e628b to your computer and use it in GitHub Desktop.
Yourls3.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use League\Uri\Schemes\Http as HttpUri; | |
/* ... */ | |
const STATUS_OK = 200; | |
const STATUS_ERROR = 400; | |
const STATUS_NOT_FOUND = 500; | |
/** | |
* Updates short URL | |
* | |
* @param string $short_url | |
* @param string $url | |
* @oaran string $format | |
* | |
* @return boolean | |
*/ | |
public function updateShortUrl( $short_url = '', $url = '' ) | |
{ | |
$short_url_uri = HttpUri::createFromString( $short_url ); | |
$keyword = $short_url_uri->path->getBasename(); | |
$data = [ | |
'signature' => $this->token, | |
'format' => self::RETURN_FORMAT_JSON, // mandatory parameter in YOURLS | |
'action' => 'update', | |
'shorturl' => $keyword, | |
'url' => $url | |
]; | |
$result = $this->library->post( '/', $data ); | |
if ( isset($result) && $result->statusCode == self::STATUS_OK ) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
/* ... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment