public function genereteShortLink($longLink)
    {
        $this->client->setMethod('POST');
        $this->client->setUri('https://www.googleapis.com/urlshortener/v1/url');
        $data = array('longUrl' => $longLink);
        $this->client->setRawBody(json_encode($data));
        $contentJson = $this->client->send()->getContent();
        $responseArray = json_decode($contentJson, true);
        if (!empty($responseArray['error'])) {
            $response = new Response();
            return $response->setError($responseArray['error']['errors']);
        } else {
            $response = new Response();
            $response->setId($responseArray['id'])
                ->setKind($responseArray['kind'])
                ->setLongUrl($responseArray['longUrl']);
            return $response;
        }
    }
public function genereteShortLink($longLink)
    {
        $this->client->setMethod('POST');
        $this->client->setUri('https://www.googleapis.com/urlshortener/v1/url');
        $data = array('longUrl' => $longLink);
        $this->client->setRawBody(json_encode($data));
        $contentJson = $this->client->send()->getContent();
        $responseArray = json_decode($contentJson, true);
        if (!empty($responseArray['error'])) {
            $response = new Response();
            return $response->setError($responseArray['error']['errors']);
        } else {
            $response = new Response();
            $response->setId($responseArray['id'])
                ->setKind($responseArray['kind'])
                ->setLongUrl($responseArray['longUrl']);
            return $response;
        }
    }
public function genereteShortLink ( $ longLink ) { $ this -> client -> setMethod ( 'POST' ) ; $ this -> client -> setUri ( 'https://www.googleapis.com/urlshortener/v1/url' ) ; $ data = array ( 'longUrl' => $ longLink ) ; $ this -> client -> setRawBody ( json_encode ( $ data ) ) ; $ contentJson = $ this -> client -> send ( ) -> getContent ( ) ; $ responseArray = json_decode ( $ contentJson , true ) ; if ( ! empty ( $ responseArray [ 'error' ] ) ) { $ response = new Response ( ) ; return $ response -> setError ( $ responseArray [ 'error' ] [ 'errors' ] ) ; } else { $ response = new Response ( ) ; $ response -> setId ( $ responseArray [ 'id' ] ) -> setKind ( $ responseArray [ 'kind' ] ) -> setLongUrl ( $ responseArray [ 'longUrl' ] ) ; return $ response ; } }
Generate a Short Link by Long link
@param $longLink
@return Response
Generate a Short Link by Long link