void v0::Request::HandleContent(
        const std::string & url,
        const mf::http::Headers & headers,
        const std::string & content)
{
    assert( callback_ );
    if ( ! callback_ )
        return;

    ResponseType response;
    response.InitializeWithContent(url, "", headers, content);

#   ifdef OUTPUT_DEBUG // Debug code
    std::cout << "Got content:\n" << content << std::endl;

    std::wostringstream ss;
    boost::property_tree::write_json( ss, response.pt );
    std::cout << "Got JSON:\n" << mf::utils::wide_to_bytes(ss.str()) << std::endl;
#   endif

    if ( ! response.error_code )
    {
        GetIfExists( response.pt, "response.pkey", &response.pkey );

        if ( ! GetIfExists( response.pt, "response.login_token",
                    &response.login_token ) )
        {
            response.error_code = make_error_code(
                    mf::api::api_code::ContentInvalidData );
            response.error_string = "missing session token";
        }
    }

    callback_(response);
}
Exemple #2
0
void InformationArea::load(int aIdObjects)
{
    MainWidget::load();
    mIdObjects = aIdObjects;
    ResponseType vResponse = execQuery(
                QString("SELECT id, total, floor, kitchen FROM area WHERE object_fk = %1")
                .arg(mIdObjects));
    if (vResponse.count())
    {
        ResponseRecordType vQuery = vResponse[0];

        ui->mpFloor->blockSignals(true);
        ui->mpKitchen->blockSignals(true);
        ui->mpTotal->blockSignals(true);
        mId = vQuery["id"].toInt();
        ui->mpTotal->setText(vQuery["total"].toString());
        ui->mpKitchen->setText(vQuery["kitchen"].toString());
        ui->mpFloor->setText(vQuery["floor"].toString());
        ui->mpFloor->blockSignals(false);
        ui->mpKitchen->blockSignals(false);
        ui->mpTotal->blockSignals(false);
        MainWidget::save();
    }
    else
    {
        mId = -1;
        ui->mpTotal->setText("");
        ui->mpKitchen->setText("");
        ui->mpFloor->setText("");
    }

}
void v1_3::Request::HandleContent(const std::string & url,
                                  const mf::http::Headers & headers,
                                  const std::string & content)
{
    assert(callback_);
    if (!callback_)
        return;

    ResponseType response;
    response.InitializeWithContent(url, "", headers, content);

    // These could possibly be available when an error occurs or on success.
    GetIfExists(response.pt, "response.pkey", &response.pkey);
    GetIfExists(response.pt, "response.secret_key", &response.secret_key);
    GetIfExists(response.pt, "response.time", &response.time);

    if (!response.error_code)
    {
        if (!GetIfExists(response.pt, "response.session_token",
                         &response.session_token))
        {
            response.error_code
                    = make_error_code(mf::api::api_code::ContentInvalidData);
            response.error_string = "missing session token";
        }
        if (!GetIfExists(response.pt, "response.ekey", &response.ekey))
        {
            response.error_code
                    = make_error_code(mf::api::api_code::ContentInvalidData);
            response.error_string = "missing \"response.ekey\"";
        }
    }

    callback_(response);
}
void v1_3::Request::HandleError(const std::string & url,
                                std::error_code ec,
                                const std::string & error_string)
{
    if (!callback_)
        return;

    ResponseType response;
    response.InitializeWithError(url, "", ec, error_string);
    callback_(response);
}