src/Service/ShortenUrl.php
public function shortenUrl($url)
    {
        if ($this->getOptions()->getBitlyApiKey() && $this->getOptions()->getBitlyUsername()) {
            $client = new \Zend\Http\Client($this->getOptions()->getBitlyUrl());
            $client->setParameterGet(array(
                'format'  => 'json',
                'longUrl' => $url,
                'login'   => $this->getOptions()->getBitlyUsername(),
                'apiKey'  => $this->getOptions()->getBitlyApiKey(),
            ));
    
            $result = $client->send();
            if ($result) {
                $jsonResult = \Zend\Json\Json::decode($result->getBody());
                if ($jsonResult->status_code == 200) {
                    return $jsonResult->data->url;
                }
            }
        }

        return $url;
    }
public function shortenUrl($url)
    {
        if ($this->getOptions()->getBitlyApiKey() && $this->getOptions()->getBitlyUsername()) {
            $client = new \Zend\Http\Client($this->getOptions()->getBitlyUrl());
            $client->setParameterGet(array(
                'format'  => 'json',
                'longUrl' => $url,
                'login'   => $this->getOptions()->getBitlyUsername(),
                'apiKey'  => $this->getOptions()->getBitlyApiKey(),
            ));
    
            $result = $client->send();
            if ($result) {
                $jsonResult = \Zend\Json\Json::decode($result->getBody());
                if ($jsonResult->status_code == 200) {
                    return $jsonResult->data->url;
                }
            }
        }

        return $url;
    }
public function shortenUrl ( $ url ) { if ( $ this -> getOptions ( ) -> getBitlyApiKey ( ) && $ this -> getOptions ( ) -> getBitlyUsername ( ) ) { $ client = new \ Zend \ Http \ Client ( $ this -> getOptions ( ) -> getBitlyUrl ( ) ) ; $ client -> setParameterGet ( array ( 'format' => 'json' , 'longUrl' => $ url , 'login' => $ this -> getOptions ( ) -> getBitlyUsername ( ) , 'apiKey' => $ this -> getOptions ( ) -> getBitlyApiKey ( ) , ) ) ; $ result = $ client -> send ( ) ; if ( $ result ) { $ jsonResult = \ Zend \ Json \ Json :: decode ( $ result -> getBody ( ) ) ; if ( $ jsonResult -> status_code == 200 ) { return $ jsonResult -> data -> url ; } } } return $ url ; }
This method call Bit.ly to shorten a given URL.
@param  unknown_type $url
@return unknown
This method call Bit . ly to shorten a given URL .