File indexing completed on 2024-05-12 05:22:10
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "bloggerservice.h" 0008 0009 #include <QUrlQuery> 0010 0011 inline QUrl operator%(const QUrl &url, const QString &path) 0012 { 0013 return QUrl(url.toString() % QLatin1Char('/') % path); 0014 } 0015 0016 namespace KGAPI2 0017 { 0018 namespace BloggerService 0019 { 0020 namespace Private 0021 { 0022 static const QUrl GoogleApisUrl(QStringLiteral("https://www.googleapis.com")); 0023 0024 auto commentBasePath(const QString &blogId, const QString &postId = QString(), const QString &commentId = QString()) -> QString 0025 { 0026 const auto post = !postId.isEmpty() ? (QLatin1StringView("/posts/") % postId) : QString(); 0027 const auto comment = !commentId.isEmpty() ? (QLatin1Char('/') % commentId) : QString(); 0028 const QString path = QLatin1StringView("blogger/v3/blogs/") % blogId % post % QLatin1StringView("/comments") % comment; 0029 return path; 0030 } 0031 0032 auto pageBasePath(const QString &blogId, const QString &pageId = QString()) -> QString 0033 { 0034 const auto page = !pageId.isEmpty() ? (QLatin1Char('/') % pageId) : QString(); 0035 const QString path = QLatin1StringView("blogger/v3/blogs/") % blogId % QLatin1StringView("/pages") % page; 0036 return path; 0037 } 0038 0039 auto postBasePath(const QString &blogId, const QString &postId = QString()) -> QString 0040 { 0041 const auto post = !postId.isEmpty() ? (QLatin1Char('/') % postId) : QString(); 0042 const QString path = QLatin1StringView("blogger/v3/blogs/") % blogId % QLatin1StringView("/posts") % post; 0043 return path; 0044 } 0045 0046 } // namespace Private 0047 } // namespace BloggerService 0048 } // namespace KGAPI2 0049 0050 using namespace KGAPI2; 0051 using namespace KGAPI2::BloggerService::Private; 0052 0053 QUrl BloggerService::fetchBlogByBlogIdUrl(const QString &blogId) 0054 { 0055 return GoogleApisUrl % QStringLiteral("/blogger/v3/blogs/") % blogId; 0056 } 0057 0058 QUrl BloggerService::fetchBlogByBlogUrlUrl(const QString &blogUrl) 0059 { 0060 QUrl url = GoogleApisUrl % QStringLiteral("/blogger/v3/blogs/byurl"); 0061 QUrlQuery query(url); 0062 query.addQueryItem(QStringLiteral("url"), blogUrl); 0063 url.setQuery(query); 0064 return url; 0065 } 0066 0067 QUrl BloggerService::fetchBlogsByUserIdUrl(const QString &userId) 0068 { 0069 return GoogleApisUrl % QStringLiteral("/blogger/v3/users/") % userId % QStringLiteral("/blogs"); 0070 } 0071 0072 QUrl BloggerService::fetchCommentsUrl(const QString &blogId, const QString &postId, const QString &commentId) 0073 { 0074 return GoogleApisUrl % commentBasePath(blogId, postId, commentId); 0075 } 0076 0077 QUrl BloggerService::approveCommentUrl(const QString &blogId, const QString &postId, const QString &commentId) 0078 { 0079 return GoogleApisUrl % commentBasePath(blogId, postId, commentId) % QStringLiteral("/approve"); 0080 } 0081 0082 QUrl BloggerService::markCommentAsSpamUrl(const QString &blogId, const QString &postId, const QString &commentId) 0083 { 0084 return GoogleApisUrl % commentBasePath(blogId, postId, commentId) % QStringLiteral("/spam"); 0085 } 0086 0087 QUrl BloggerService::deleteCommentUrl(const QString &blogId, const QString &postId, const QString &commentId) 0088 { 0089 return GoogleApisUrl % commentBasePath(blogId, postId, commentId); 0090 } 0091 0092 QUrl BloggerService::deleteCommentContentUrl(const QString &blogId, const QString &postId, const QString &commentId) 0093 { 0094 return GoogleApisUrl % commentBasePath(blogId, postId, commentId) % QStringLiteral("/removecontent"); 0095 } 0096 0097 QUrl BloggerService::fetchPageUrl(const QString &blogId, const QString &pageId) 0098 { 0099 return GoogleApisUrl % pageBasePath(blogId, pageId); 0100 } 0101 0102 QUrl BloggerService::deletePageUrl(const QString &blogId, const QString &pageId) 0103 { 0104 return GoogleApisUrl % pageBasePath(blogId, pageId); 0105 } 0106 0107 QUrl BloggerService::modifyPageUrl(const QString &blogId, const QString &pageId) 0108 { 0109 return GoogleApisUrl % pageBasePath(blogId, pageId); 0110 } 0111 0112 QUrl BloggerService::createPageUrl(const QString &blogId) 0113 { 0114 return GoogleApisUrl % pageBasePath(blogId); 0115 } 0116 0117 QUrl BloggerService::fetchPostUrl(const QString &blogId, const QString &postId) 0118 { 0119 return GoogleApisUrl % postBasePath(blogId, postId); 0120 } 0121 0122 QUrl BloggerService::searchPostUrl(const QString &blogId) 0123 { 0124 return GoogleApisUrl % postBasePath(blogId) % QStringLiteral("/search"); 0125 } 0126 0127 QUrl BloggerService::createPostUrl(const QString &blogId) 0128 { 0129 return GoogleApisUrl % postBasePath(blogId); 0130 } 0131 0132 QUrl BloggerService::deletePostUrl(const QString &blogId, const QString &postId) 0133 { 0134 return GoogleApisUrl % postBasePath(blogId, postId); 0135 } 0136 0137 QUrl BloggerService::modifyPostUrl(const QString &blogId, const QString &postId) 0138 { 0139 return GoogleApisUrl % postBasePath(blogId, postId); 0140 } 0141 0142 QUrl BloggerService::publishPostUrl(const QString &blogId, const QString &postId) 0143 { 0144 return GoogleApisUrl % postBasePath(blogId, postId) % QStringLiteral("/publish"); 0145 } 0146 0147 QUrl BloggerService::revertPostUrl(const QString &blogId, const QString &postId) 0148 { 0149 return GoogleApisUrl % postBasePath(blogId, postId) % QStringLiteral("/revert"); 0150 }