Kgapi

pagecreatejob.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 "pagecreatejob.h"
8#include "bloggerservice.h"
9#include "page.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 PageCreateJob::Private
19{
20public:
21 Private(const PagePtr &page);
22
23 const PagePtr page;
24};
25
26PageCreateJob::Private::Private(const PagePtr &page_)
27 : page(page_)
28{
29}
30
31PageCreateJob::PageCreateJob(const PagePtr &page, const AccountPtr &account, QObject *parent)
32 : CreateJob(account, parent)
33 , d(new Private(page))
34{
35}
36
37PageCreateJob::~PageCreateJob()
38{
39 delete d;
40}
41
42void PageCreateJob::start()
43{
44 const QUrl url = BloggerService::createPageUrl(d->page->blogId());
45 QNetworkRequest request(url);
46
47 const QByteArray rawData = Page::toJSON(d->page);
48
49 enqueueRequest(request, rawData, QStringLiteral("application/json"));
50}
51
52ObjectsList PageCreateJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
53{
54 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
55 ContentType ct = Utils::stringToContentType(contentType);
57 if (ct != KGAPI2::JSON) {
59 setErrorString(tr("Invalid response content type"));
61 return items;
62 }
63
64 items << Page::fromJSON(rawData);
66 return items;
67}
68
69#include "moc_pagecreatejob.cpp"
Abstract superclass for all jobs that create new objects on the server.
Definition createjob.h:26
virtual ObjectsList items() const
Definition createjob.cpp:40
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
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 Mon Nov 4 2024 16:36:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.