23namespace PeopleService
34static const QUrl GoogleApisUrl(QStringLiteral(
"https://people.googleapis.com"));
35static const auto PeopleV1Path = QStringLiteral(
"/v1/");
36static const auto PeopleBasePath =
QString(PeopleV1Path % QStringLiteral(
"people"));
37static const auto ContactGroupsBasePath =
QString(PeopleV1Path % QStringLiteral(
"contactGroups"));
39static const auto AllPersonFields = QStringLiteral(
"addresses,"
69static const auto AllUpdatablePersonFields = QStringLiteral(
"addresses,"
94static const auto AllGroupFields = QStringLiteral(
"clientData,"
100static const auto AllRecentlyCreatedAvailableGroupFields = QStringLiteral(
"clientData,"
105void writeNextPageDataQuery(FetchType fetchType,
FeedData &feedData,
const QJsonObject &replyRootObject,
const QString &syncToken = {})
107 if(!replyRootObject.
contains(QStringLiteral(
"nextPageToken"))) {
112 if (fetchType == PersonFetch) {
113 url = fetchAllContactsUrl(syncToken);
114 }
else if (fetchType == ContactGroupFetch) {
115 url = fetchAllContactGroupsUrl();
117 qCDebug(KGAPIDebug) <<
"Unknown type of fetch, cannot write next page data query";
122 query.addQueryItem(QStringLiteral(
"pageToken"), replyRootObject.
value(QStringLiteral(
"nextPageToken")).toString());
132 return Private::AllPersonFields;
135QString allUpdatablePersonFields()
137 return Private::AllUpdatablePersonFields;
140QString allContactGroupRecentlyCreatedAvailableFields()
142 return Private::AllRecentlyCreatedAvailableGroupFields;
149 const auto objectifiedDocument = document.
object();
150 const auto resourceName = objectifiedDocument.
value(QStringLiteral(
"resourceName")).
toString();
160 QUrl url(Private::GoogleApisUrl);
161 const QString path = Private::PeopleBasePath % QStringLiteral(
"/me/connections");
165 query.addQueryItem(QStringLiteral(
"personFields"), Private::AllPersonFields);
166 query.addQueryItem(QStringLiteral(
"requestSyncToken"), QStringLiteral(
"true"));
169 query.addQueryItem(QStringLiteral(
"syncToken"), syncToken);
179 QUrl url(Private::GoogleApisUrl);
180 const QString path = Private::PeopleV1Path % resourceName;
184 query.addQueryItem(QStringLiteral(
"personFields"), Private::AllPersonFields);
190QUrl createContactUrl()
192 QUrl url(Private::GoogleApisUrl);
193 const QString path = Private::PeopleBasePath % QStringLiteral(
":createContact");
200 QUrl url(Private::GoogleApisUrl);
201 url.
setPath(Private::PeopleV1Path % resourceName % QStringLiteral(
":updateContact"));
204 query.addQueryItem(QStringLiteral(
"updatePersonFields"), personFields);
212 QUrl url(Private::GoogleApisUrl);
213 url.
setPath(Private::PeopleV1Path % resourceName % QStringLiteral(
":deleteContact"));
217QUrl fetchAllContactGroupsUrl()
219 QUrl url(Private::GoogleApisUrl);
220 url.
setPath(Private::ContactGroupsBasePath);
223 query.addQueryItem(QStringLiteral(
"groupFields"), Private::AllGroupFields);
231QUrl fetchContactGroupUrl(
const QString &resourceName)
233 QUrl url(Private::GoogleApisUrl);
234 const QString path = Private::PeopleV1Path % resourceName;
238 query.addQueryItem(QStringLiteral(
"groupFields"), Private::AllGroupFields);
244QUrl createContactGroupUrl()
246 QUrl url(Private::GoogleApisUrl);
247 url.
setPath(Private::ContactGroupsBasePath);
251QUrl updateContactGroupUrl(
const QString &resourceName)
253 QUrl url(Private::GoogleApisUrl);
254 const QString path = Private::PeopleV1Path % resourceName;
259QUrl deleteContactGroupUrl(
const QString &resourceName,
const bool deleteContacts)
261 QUrl url(Private::GoogleApisUrl);
262 url.
setPath(Private::PeopleV1Path % resourceName);
264 const auto deleteContactsString = deleteContacts ? QStringLiteral(
"true") : QStringLiteral(
"false");
266 query.addQueryItem(QStringLiteral(
"deleteContacts"), deleteContactsString);
272QUrl updateContactPhotoUrl(
const QString &resourceName)
274 QUrl url(Private::GoogleApisUrl);
275 url.
setPath(Private::PeopleV1Path % resourceName % QStringLiteral(
":updateContactPhoto"));
281 QUrl url(Private::GoogleApisUrl);
282 url.
setPath(Private::PeopleV1Path % resourceName % QStringLiteral(
":deleteContactPhoto"));
285 query.addQueryItem(QStringLiteral(
"personFields"), personFields);
295 if (!document.isObject()) {
301 const auto rootObject = document.object();
302 const auto connections = rootObject.
value(QStringLiteral(
"connections")).toArray();
303 for(
const auto &connection : connections) {
304 output.
append(People::Person::fromJSON(connection.toObject()));
307 feedData.
totalResults = rootObject.value(QStringLiteral(
"totalItems")).toInt();
309 Private::writeNextPageDataQuery(Private::PersonFetch, feedData, rootObject, syncToken);
310 feedData.
syncToken = rootObject.value(QStringLiteral(
"nextSyncToken")).toString();
320 if (!document.isObject()) {
326 const auto rootObject = document.object();
327 const auto contactGroups = rootObject.
value(QStringLiteral(
"contactGroups")).toArray();
328 for(
const auto &contactGroup : contactGroups) {
329 output.
append(People::ContactGroup::fromJSON(contactGroup.toObject()));
332 feedData.
totalResults = rootObject.value(QStringLiteral(
"totalItems")).toInt();
334 Private::writeNextPageDataQuery(Private::ContactGroupFetch, feedData, rootObject);