Changeset 915dc18 for src


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
Location:
src
Files:
12 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/CMakeLists.txt

    re498070 r915dc18  
    2424        FIND_PACKAGE(Qt5Network REQUIRED)
    2525        ADD_SUBDIRECTORY(lib)
     26        IF(BUILD_TESTING)
     27                FIND_PACKAGE(Qt5Test REQUIRED)
     28                ADD_SUBDIRECTORY(testing)
     29                ADD_SUBDIRECTORY(tests)
     30        ENDIF()
    2631ENDIF(WITH_STATIONCLIENT)
    2732IF(WITH_WEBSERVICE)
  • src/lib/silibconfig.h.in

    re498070 r915dc18  
    11/*
    2     Copyright (C) 2010 - 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     2    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    33
    44    This library is free software; you can redistribute it and/or
  • 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 
  • src/lib/siwebserviceclient.h

    re498070 r915dc18  
    4848                                 * @brief Registers a station at the server and emits error() or finishedStationsRegister() if finished.
    4949                                 */
    50                                 ReplyType stationsRegister(SiWeatherStation station, QString &error);
     50                                ReplyType stationsRegister(const SiWeather::Library::SiWeatherStation& station, QString& error);
    5151
    5252                        signals:
    53                                 void error(ReplyType replyType, const QString &errorMessage) const;
     53                                void error(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString &errorMessage) const;
    5454                                /**
    5555                                 * @brief Generic finish signal for all requests. Use specialized finished signals instead!
    … …  
    5757                                 * @see finishedStationsRegister
    5858                                 */
    59                                 void finished(ReplyType replyType, const QByteArray &data) const;
     59                                void finished(SiWeather::Library::SiWebserviceClient::ReplyType replyType, bool result, const QByteArray &data) const;
    6060                                void finishedStationsRegister(bool result, const QUuid &uuid, const QString &message) const;
    6161                               
  • src/webservice/config/config.php.in

    re498070 r915dc18  
    2121$config = [
    2222        "mode" => "@WEBSERVICE_MODE@",
    23         "webserviceBaseUrl" => "http://@WEBSERVICE_SERVER_HOST@:@WEBSERVICE_SERVER_PORT@@WEBSERVICE_BASE_URL@",
     23        "webserviceBaseUrl" => "@WEBSERVICE_BASE_URL_COMPLETE@",
    2424        "spatialiteExtension" => "mod_spatialite.so",
    2525        "geonamesUsername" => "@WEBSERVICE_GEONAMES_USERNAME@",
  • src/webservice/htdocs/SiWeather/Webservice/Location.php

    re498070 r915dc18  
    5050                $this->setRegion($regionName, $regionCode);
    5151                $this->setCountry($countryName, $countryCode);
    52                 $this->setLocation($longitude, $latitude);
     52                $this->setLocation($latitude, $longitude);
    5353                $this->setTimezone($timeZone);
    5454        }
  • src/webservice/htdocs/SiWeather/Webservice/WebserviceApi.php

    re498070 r915dc18  
    203203                                }
    204204                                if(!$validatedLocation){
    205                                         $message  = "The city (". $json[city] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send, does not suite with locations we found at your given location (city, latitude, longitude):\n";
     205                                        $message  = "The city (". $json["city"] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send, does not suite with locations we found at your given location (city, latitude, longitude):\n";
    206206                                        foreach($locations as $location){
    207207                                                $message .= "    ". $location->city() .": ". $location->latitude() .", ". $location->longitude() ."\n";
Note: See TracChangeset for help on using the changeset viewer.