Example #1
0
/*!
   Shortens url
   \param url Url to shorten
   \return Shorten url
 */
QString ShortenedUrl::shortUrl(const QString &url)
{
	//TODO: Add other services for shortening
    QUrl urlService("http://api.bit.ly/v3/shorten");
    urlService.addQueryItem("login", "minimoog");
    urlService.addQueryItem("apiKey", "R_17b8dfb25efd629d31c8c8f93ea51b9e");
    urlService.addQueryItem("longUrl", url);
    urlService.addQueryItem("format", "txt");

    //QNetworkRequest req(urlService);
    //QNetworkReply *reply = m_netManager->get(req);

//    SignalWaiter signalWaiter(reply, SIGNAL(finished()));

//    if (signalWaiter.wait(2000)) {
//        if (reply->error() != QNetworkReply::NoError) {
//            qDebug() << "Error shortening url";
//            qDebug() << reply->readAll();

//            return QString();
//        }

//        return reply->readAll();
//    } else {
//        qDebug() << "Timeout";
//        return QString();
//    }

    return url;
}
Example #2
0
/**
 *  Shortens url
 *  @param url url to shorten
 */
void ShortenedUrl::shortUrl(const QString &url)
{
    //TODO: Add other services for shortening
    QUrl urlService("http://api.bit.ly/v3/shorten");
    urlService.addQueryItem("login", "minimoog");
    urlService.addQueryItem("apiKey", "R_17b8dfb25efd629d31c8c8f93ea51b9e");
    urlService.addQueryItem("longUrl", url);
    urlService.addQueryItem("format", "txt");

    QNetworkRequest req(urlService);

    QNetworkReply *reply = m_netManager->get(req);
    reply->setProperty("longurl", QVariant(url));
    connect(reply, SIGNAL(finished()), this, SLOT(finished()));
}