| Server IP : 104.21.37.246 / Your IP : 172.71.28.145 [ Web Server : Apache System : Linux cpanel01wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.59.el6.x86_64 #1 SMP Thu Dec 6 05:11:00 EST 2018 x86_64 User : cp648411 ( 1354) PHP Version : 7.2.34 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/cp648411/www/simded.com/vendor/narendravaghela/bitly-client/src/ |
Upload File : |
<?php
namespace Bitly;
use BadFunctionCallException;
use Bitly\Exception\MissingAccessTokenException;
/**
* Bitly client
*
*/
class BitlyClient
{
/**
* Access token
*
* @var string
*/
protected $token = "";
/**
* API Modules
*
* @var array
*/
protected $apiModules = [
'Links'
];
/**
* constructor
*
*/
public function __construct($token = null)
{
if ($token !== null) {
$this->accessToken($token);
}
}
/**
* Gets/Sets access token
*
* @param string $token Authentication token
* @return mixes String if $token is empty, true otherwise
*/
public function accessToken($token = null)
{
if ($token === null) {
return $this->token;
}
$this->token = $token;
return true;
}
/**
* Magic method to call Bitly API methods.
*
* For example:
*
* $bitlyClient = new BitlyClient('Your access token');
* OR
* $bitlyClient = new BitlyClient();
* $bitlyClient->accessToken('Your access token');
*
* $options = ['longUrl' => 'http://www.example.com?foo=bar&john=doe'];
* $response = $bitlyClient->shorten($options);
*
* @param string $methodName Method name to use.
* @param array $arguments Parameters to pass when calling methods.
* @return mixed API Response.
* @throws BadFunctionCallException If method does not exist.
* @throws MissingAccessTokenException If access token is not set.
*/
public function __call($methodName, $arguments = [])
{
if (empty($this->token)) {
throw new MissingAccessTokenException();
}
foreach ($this->apiModules as $module) {
$className = '\Bitly\Module\\' . $module;
if (method_exists($className, $methodName)) {
$apiModule = new $className($this->accessToken());
break;
}
}
if (!isset($apiModule)) {
throw new BadFunctionCallException("Invalid API method!");
}
return $apiModule->$methodName(!empty($arguments[0]) ? $arguments[0] : null);
}
}