Kgapi

commentapprovejob.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 "commentapprovejob.h"
8#include "account.h"
9#include "bloggerservice.h"
10#include "comment.h"
11#include "utils.h"
12
13#include <QNetworkReply>
14#include <QNetworkRequest>
15
16using namespace KGAPI2;
17using namespace KGAPI2::Blogger;
18
19class Q_DECL_HIDDEN CommentApproveJob::Private
20{
21public:
22 Private(const QString &blogId, const QString &postId, const QString &commentId, ApprovalAction action);
23
24 const QString blogId;
25 const QString postId;
26 const QString commentId;
27 const ApprovalAction action;
28};
29
30CommentApproveJob::Private::Private(const QString &blogId_, const QString &postId_, const QString &commentId_, CommentApproveJob::ApprovalAction action_)
31 : blogId(blogId_)
32 , postId(postId_)
33 , commentId(commentId_)
34 , action(action_)
35{
36}
37
38CommentApproveJob::CommentApproveJob(const QString &blogId,
39 const QString &postId,
40 const QString &commentId,
41 CommentApproveJob::ApprovalAction action,
42 const AccountPtr &account,
43 QObject *parent)
44 : ModifyJob(account, parent)
45 , d(new Private(blogId, postId, commentId, action))
46{
47}
48
49CommentApproveJob::CommentApproveJob(const CommentPtr &comment, CommentApproveJob::ApprovalAction action, const AccountPtr &account, QObject *parent)
50 : ModifyJob(account, parent)
51 , d(new Private(comment->blogId(), comment->postId(), comment->id(), action))
52{
53}
54
55CommentApproveJob::~CommentApproveJob()
56{
57 delete d;
58}
59
60void CommentApproveJob::start()
61{
62 QNetworkRequest request;
63 if (d->action == Blogger::CommentApproveJob::Approve) {
64 request.setUrl(BloggerService::approveCommentUrl(d->blogId, d->postId, d->commentId));
65 } else {
66 request.setUrl(BloggerService::markCommentAsSpamUrl(d->blogId, d->postId, d->commentId));
67 }
68
69 enqueueRequest(request);
70}
71
72ObjectsList CommentApproveJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
73{
74 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
75 ContentType ct = Utils::stringToContentType(contentType);
77 if (ct != KGAPI2::JSON) {
79 setErrorString(tr("Invalid response content type"));
81 return items;
82 }
83
84 items << Comment::fromJSON(rawData);
86 return items;
87}
88
89#include "moc_commentapprovejob.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
void setUrl(const QUrl &url)
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 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.