Ignore:
Timestamp:
Sep 17, 2015, 9:11:21 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
a2330fc
Parents:
e498070
Message:
  • Working c++ library webserviceclient class, which allows to register a station
    • Added tests for the webserviceclient class
    • Improved build system
    • Fixed some errors in Webservice Location.php and WebserviceApi.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lib/siwebserviceclient.cpp

    re498070 r915dc18  
    4545}
    4646
    47 SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister(SiWeatherStation station, QString &error)
     47SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister(const SiWeatherStation &station, QString &error)
    4848{
    4949        if(!_networkManager)
    5050                return Error;
    5151
    52         if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty()){
     52        if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty() || station.type().isEmpty()){
    5353                error = tr("Station has empty name, city or eMail address. All of these are needed!");
    5454                return Error;
    … …  
    6161        jsonStation["latitude"] = Library::geoCoordinateToString(station.latitude());
    6262        jsonStation["email"] = station.eMail();
     63        jsonStation["type"] = station.type();
     64        jsonStation["typeUrl"] = station.typeUrl().toString();
    6365        QJsonDocument jsonDocument(jsonStation);
    6466
    6567        QNetworkRequest request;
    66         request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg("/stations/register"));
     68        request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg("index.php/stations/register"));
    6769        request.setRawHeader("User-Agent", QString("SiWeather Library %1").arg(Library::version()).toUtf8());
    6870        request.setHeader(QNetworkRequest::ContentTypeHeader,
    … …  
    8183       
    8284        QByteArray data = reply->readAll();
    83         QJsonDocument jsonDocument = QJsonDocument::fromBinaryData(data);
     85        reply->deleteLater();
     86
     87        QJsonDocument jsonDocument = QJsonDocument::fromJson(data);
    8488        QJsonObject json = jsonDocument.object();
    8589        if(!json.contains("result")){
    8690                emit finishedStationsRegister(false, "", tr("No result in response found"));
     91                emit finished(StationsRegister, false, data);
    8792                return;
    8893        }
    8994        if(json["result"].toString() != "success"){
    9095                emit finishedStationsRegister(false, "", tr("Operation failed for reason: %1").arg(json["message"].toString()));
     96                emit finished(StationsRegister, false, data);
    9197                return;
    9298        }
    9399        if(!json.contains("uuid")){
    94100                emit finishedStationsRegister(false, "", tr("No uuid in response found"));
     101                emit finished(StationsRegister, false, data);
    95102                return;
    96103        }
    97         emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), "");
    98         emit finished(StationsRegister, data);
    99         reply->deleteLater();
     104        emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), json["message"].toString());
     105        emit finished(StationsRegister, false, data);
    100106}
    101107
    … …  
    120126        return reply;
    121127}
    122 
Note: See TracChangeset for help on using the changeset viewer.