9#include "contactgroupfetchjob.h"
10#include "peopleservice.h"
11#include "contactgroup.h"
14#include <QNetworkRequest>
15#include <QNetworkReply>
17#include <QJsonDocument>
21namespace KGAPI2::People
24class Q_DECL_HIDDEN ContactGroupFetchJob::Private
27 explicit Private(ContactGroupFetchJob *parent);
34 ContactGroupFetchJob *
const q;
37ContactGroupFetchJob::Private::Private(ContactGroupFetchJob *parent)
42ContactGroupFetchJob::ContactGroupFetchJob(
const AccountPtr& account,
QObject* parent)
43 : FetchJob(account, parent)
44 , d(std::make_unique<Private>(this))
51 request.setRawHeader(
"Host",
"people.googleapis.com");
55ContactGroupFetchJob::ContactGroupFetchJob(
const QString &resourceName,
56 const AccountPtr &account,
58 : FetchJob(account, parent)
59 , d(std::make_unique<Private>(this))
61 d->resourceName = resourceName;
64ContactGroupFetchJob::~ContactGroupFetchJob() =
default;
66void ContactGroupFetchJob::start()
69 if (d->resourceName.isEmpty()) {
70 url = PeopleService::fetchAllContactGroupsUrl();
72 url = PeopleService::fetchContactGroupUrl(d->resourceName);
76 enqueueRequest(request);
86 ContentType ct = Utils::stringToContentType(contentType);
88 if (ct != KGAPI2::JSON) {
92 if (d->resourceName.isEmpty()) {
93 items = PeopleService::parseContactGroupsJSONFeed(feedData, rawData);
96 if(jsonDocumentFromData.isObject()) {
97 items << People::ContactGroup::fromJSON(jsonDocumentFromData.object());
99 qDebug() <<
"JSON document does not have object";
103 if (feedData.nextPageUrl.isValid()) {
104 emitProgress(feedData.startIndex, feedData.totalResults);
106 const auto request = d->createRequest(feedData.nextPageUrl);
107 enqueueRequest(request);
117#include "moc_contactgroupfetchjob.cpp"
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QString toString() const const