public function expand($shortUrlHash, $returnFullReponse = false) { if (!is_string($shortUrlHash)) { throw new \Exception('shortUrl parameter must be a string'); } if (!is_bool($returnFullReponse)) { throw new \Exception('returnFullReponse parameter must be an boolean'); } $curl = new Curl($this->getApiUrl() . 'expand'); $curl->addArgument('version', $this->getApiVersion(), 'GET'); $curl->addArgument('hash', $shortUrlHash, 'GET'); $curl->addArgument('login', $this->getApiLogin(), 'GET'); $curl->addArgument('apiKey', $this->getApiKey(), 'GET'); $curl->execute(true); $reponse = json_decode($curl->getResponse()); if ($returnFullReponse) { return $reponse; } else { if ($reponse->errorCode != 0) { Logger::getInstance()->debug('Bit.Ly expand url error, code : "' . $reponse->errorCode . '" and message : "' . $reponse->errorMessage . '"'); return false; } if ($reponse->statusCode == 'OK') { Logger::getInstance()->debug('Bit.Ly expand url : "http://bit.ly/' . $shortUrlHash . '" result is : "' . $reponse->results->{$shortUrlHash}->longUrl . '"'); return $reponse->results->{$shortUrlHash}->longUrl; } return false; } }
public function expand($shortUrlHash, $returnFullReponse = false) { if (!is_string($shortUrlHash)) { throw new \Exception('shortUrl parameter must be a string'); } if (!is_bool($returnFullReponse)) { throw new \Exception('returnFullReponse parameter must be an boolean'); } $curl = new Curl($this->getApiUrl()); if ($this->getApiKey()) { $curl->addArgument('apiKey', $this->getApiKey(), 'GET'); } $curl->addArgument('shortUrl', 'http://goo.gl/' . $shortUrlHash, 'GET'); $curl->execute(true); $reponse = json_decode($curl->getResponse()); if ($returnFullReponse) { return $reponse; } else { if (isset($reponse->error)) { Logger::getInstance()->debug('Goo.gl expand url error, code : "' . $reponse->error->code . '" and message : "' . $reponse->error->message . '"'); return false; } if ($reponse->status == 'OK') { Logger::getInstance()->debug('Goo.gl expand url : "http://goo.gl/' . $shortUrlHash . '" result is : "' . $reponse->longUrl . '"'); return $reponse->longUrl; } return false; } }