Kgapi

postmodifyjob.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#include "postmodifyjob.h"
8#include "bloggerservice.h"
9#include "post.h"
10#include "utils.h"
11
12#include <QNetworkReply>
13#include <QNetworkRequest>
14
15using namespace KGAPI2;
16using namespace KGAPI2::Blogger;
17
18class Q_DECL_HIDDEN PostModifyJob::Private
19{
20public:
21 Private(const PostPtr &post);
22
23 const PostPtr post;
24};
25
26PostModifyJob::Private::Private(const PostPtr &post_)
27 : post(post_)
28{
29}
30
31PostModifyJob::PostModifyJob(const PostPtr &post, const AccountPtr &account, QObject *parent)
32 : ModifyJob(account, parent)
33 , d(new Private(post))
34{
35}
36
37PostModifyJob::~PostModifyJob()
38{
39 delete d;
40}
41
42void PostModifyJob::start()
43{
44 const QUrl url = BloggerService::modifyPostUrl(d->post->blogId(), d->post->id());
45 QNetworkRequest request(url);
46
47 const QByteArray rawData = Post::toJSON(d->post);
48 enqueueRequest(request, rawData, QStringLiteral("application/json"));
49}
50
51ObjectsList PostModifyJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
52{
53 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
54 ContentType ct = Utils::stringToContentType(contentType);
56 if (ct != KGAPI2::JSON) {
58 setErrorString(tr("Invalid response content type"));
60 return items;
61 }
62
63 items << Post::fromJSON(rawData);
65 return items;
66}
67
68#include "moc_postmodifyjob.cpp"
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition job.cpp:401
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
void setError(KGAPI2::Error error)
Set job error to error.
Definition job.cpp:386
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
Abstract superclass for all jobs that somehow modify resources on Google.
Definition modifyjob.h:25
ObjectsList items() const
Definition modifyjob.cpp:43
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:54:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.