From f76b6928f87ebb03d6e288d657a6aea7f4b72b14 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 12 Aug 2022 17:47:34 +0200 Subject: [PATCH] specs,nextcloud: Use news v1.3 API --- .../lib/src/apps/news/blocs/articles.dart | 6 +- .../nextcloud/lib/src/nextcloud.openapi.dart | 62 ++++++++----------- .../nextcloud/lib/src/nextcloud.openapi.json | 60 +++++++----------- .../nextcloud/lib/src/version_supported.dart | 2 +- packages/nextcloud/test/news_test.dart | 9 +-- specs/news.json | 60 +++++++----------- 6 files changed, 77 insertions(+), 122 deletions(-) diff --git a/packages/neon/lib/src/apps/news/blocs/articles.dart b/packages/neon/lib/src/apps/news/blocs/articles.dart index 02953555..aff0a0ec 100644 --- a/packages/neon/lib/src/apps/news/blocs/articles.dart +++ b/packages/neon/lib/src/apps/news/blocs/articles.dart @@ -87,8 +87,7 @@ class NewsArticlesBloc extends $NewsArticlesBloc { _$starArticleEvent.listen((final article) { _wrapArticleAction((final client) async { await client.news.starArticle( - feedId: article.feedId!, - guidHash: article.guidHash!, + itemId: article.id!, ); // TODO //_articleUpdateController.add(article..starred = true); @@ -98,8 +97,7 @@ class NewsArticlesBloc extends $NewsArticlesBloc { _$unstarArticleEvent.listen((final article) { _wrapArticleAction((final client) async { await client.news.unstarArticle( - feedId: article.feedId!, - guidHash: article.guidHash!, + itemId: article.id!, ); // TODO //_articleUpdateController.add(article..starred = false); diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index a9312f59..61601a8c 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -1702,7 +1702,7 @@ class NewsClient { } Future listFolders() async { - var path = '/apps/news/api/v1-2/folders'; + var path = '/apps/news/api/v1-3/folders'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1719,7 +1719,7 @@ class NewsClient { } Future createFolder({required String name}) async { - var path = '/apps/news/api/v1-2/folders'; + var path = '/apps/news/api/v1-3/folders'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1740,7 +1740,7 @@ class NewsClient { required int folderId, required String name, }) async { - var path = '/apps/news/api/v1-2/folders/{folderId}'; + var path = '/apps/news/api/v1-3/folders/{folderId}'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1759,7 +1759,7 @@ class NewsClient { } Future deleteFolder({required int folderId}) async { - var path = '/apps/news/api/v1-2/folders/{folderId}'; + var path = '/apps/news/api/v1-3/folders/{folderId}'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1780,14 +1780,14 @@ class NewsClient { required int folderId, required int newestItemId, }) async { - var path = '/apps/news/api/v1-2/folders/{folderId}/read'; + var path = '/apps/news/api/v1-3/folders/{folderId}/read'; final queryParameters = {}; final headers = {}; Uint8List? body; path = path.replaceAll('{folderId}', Uri.encodeQueryComponent(folderId.toString())); queryParameters['newestItemId'] = newestItemId.toString(); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -1799,7 +1799,7 @@ class NewsClient { } Future listFeeds() async { - var path = '/apps/news/api/v1-2/feeds'; + var path = '/apps/news/api/v1-3/feeds'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1819,7 +1819,7 @@ class NewsClient { required String url, int? folderId, }) async { - var path = '/apps/news/api/v1-2/feeds'; + var path = '/apps/news/api/v1-3/feeds'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1840,7 +1840,7 @@ class NewsClient { } Future deleteFeed({required int feedId}) async { - var path = '/apps/news/api/v1-2/feeds/{feedId}'; + var path = '/apps/news/api/v1-3/feeds/{feedId}'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1861,7 +1861,7 @@ class NewsClient { required int feedId, int? folderId, }) async { - var path = '/apps/news/api/v1-2/feeds/{feedId}/move'; + var path = '/apps/news/api/v1-3/feeds/{feedId}/move'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1885,7 +1885,7 @@ class NewsClient { required int feedId, required String feedTitle, }) async { - var path = '/apps/news/api/v1-2/feeds/{feedId}/rename'; + var path = '/apps/news/api/v1-3/feeds/{feedId}/rename'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1907,14 +1907,14 @@ class NewsClient { required int feedId, required int newestItemId, }) async { - var path = '/apps/news/api/v1-2/feeds/{feedId}/read'; + var path = '/apps/news/api/v1-3/feeds/{feedId}/read'; final queryParameters = {}; final headers = {}; Uint8List? body; path = path.replaceAll('{feedId}', Uri.encodeQueryComponent(feedId.toString())); queryParameters['newestItemId'] = newestItemId.toString(); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -1933,7 +1933,7 @@ class NewsClient { int offset = 0, int oldestFirst = 0, }) async { - var path = '/apps/news/api/v1-2/items'; + var path = '/apps/news/api/v1-3/items'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1960,7 +1960,7 @@ class NewsClient { int id = 0, int lastModified = 0, }) async { - var path = '/apps/news/api/v1-2/items/updated'; + var path = '/apps/news/api/v1-3/items/updated'; final queryParameters = {}; final headers = {}; Uint8List? body; @@ -1980,13 +1980,13 @@ class NewsClient { } Future markArticleAsRead({required int itemId}) async { - var path = '/apps/news/api/v1-2/items/{itemId}/read'; + var path = '/apps/news/api/v1-3/items/{itemId}/read'; final queryParameters = {}; final headers = {}; Uint8List? body; path = path.replaceAll('{itemId}', Uri.encodeQueryComponent(itemId.toString())); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -1998,13 +1998,13 @@ class NewsClient { } Future markArticleAsUnread({required int itemId}) async { - var path = '/apps/news/api/v1-2/items/{itemId}/unread'; + var path = '/apps/news/api/v1-3/items/{itemId}/unread'; final queryParameters = {}; final headers = {}; Uint8List? body; path = path.replaceAll('{itemId}', Uri.encodeQueryComponent(itemId.toString())); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -2015,18 +2015,14 @@ class NewsClient { throw ApiException.fromResponse(response); } - Future starArticle({ - required int feedId, - required String guidHash, - }) async { - var path = '/apps/news/api/v1-2/items/{feedId}/{guidHash}/star'; + Future starArticle({required int itemId}) async { + var path = '/apps/news/api/v1-3/items/{itemId}/star'; final queryParameters = {}; final headers = {}; Uint8List? body; - path = path.replaceAll('{feedId}', Uri.encodeQueryComponent(feedId.toString())); - path = path.replaceAll('{guidHash}', Uri.encodeQueryComponent(guidHash.toString())); + path = path.replaceAll('{itemId}', Uri.encodeQueryComponent(itemId.toString())); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -2037,18 +2033,14 @@ class NewsClient { throw ApiException.fromResponse(response); } - Future unstarArticle({ - required int feedId, - required String guidHash, - }) async { - var path = '/apps/news/api/v1-2/items/{feedId}/{guidHash}/unstar'; + Future unstarArticle({required int itemId}) async { + var path = '/apps/news/api/v1-3/items/{itemId}/unstar'; final queryParameters = {}; final headers = {}; Uint8List? body; - path = path.replaceAll('{feedId}', Uri.encodeQueryComponent(feedId.toString())); - path = path.replaceAll('{guidHash}', Uri.encodeQueryComponent(guidHash.toString())); + path = path.replaceAll('{itemId}', Uri.encodeQueryComponent(itemId.toString())); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index 2cbdb43f..fd44c979 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -1847,7 +1847,7 @@ } } }, - "/apps/news/api/v1-2/folders": { + "/apps/news/api/v1-3/folders": { "get": { "operationId": "list-folders", "tags": [ @@ -1895,7 +1895,7 @@ } } }, - "/apps/news/api/v1-2/folders/{folderId}": { + "/apps/news/api/v1-3/folders/{folderId}": { "parameters": [ { "name": "folderId", @@ -1939,7 +1939,7 @@ } } }, - "/apps/news/api/v1-2/folders/{folderId}/read": { + "/apps/news/api/v1-3/folders/{folderId}/read": { "parameters": [ { "name": "folderId", @@ -1951,7 +1951,7 @@ } } ], - "put": { + "post": { "operationId": "mark-folder-as-read", "tags": [ "news" @@ -1974,7 +1974,7 @@ } } }, - "/apps/news/api/v1-2/feeds": { + "/apps/news/api/v1-3/feeds": { "get": { "operationId": "list-feeds", "tags": [ @@ -2030,7 +2030,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}": { + "/apps/news/api/v1-3/feeds/{feedId}": { "parameters": [ { "name": "feedId", @@ -2053,7 +2053,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/move": { + "/apps/news/api/v1-3/feeds/{feedId}/move": { "parameters": [ { "name": "feedId", @@ -2086,7 +2086,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/rename": { + "/apps/news/api/v1-3/feeds/{feedId}/rename": { "parameters": [ { "name": "feedId", @@ -2119,7 +2119,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/read": { + "/apps/news/api/v1-3/feeds/{feedId}/read": { "parameters": [ { "name": "feedId", @@ -2130,7 +2130,7 @@ } } ], - "put": { + "post": { "operationId": "mark-feed-as-read", "tags": [ "news" @@ -2152,7 +2152,7 @@ } } }, - "/apps/news/api/v1-2/items": { + "/apps/news/api/v1-3/items": { "get": { "operationId": "list-articles", "tags": [ @@ -2228,7 +2228,7 @@ } } }, - "/apps/news/api/v1-2/items/updated": { + "/apps/news/api/v1-3/items/updated": { "get": { "operationId": "list-updated-articles", "tags": [ @@ -2277,7 +2277,7 @@ } } }, - "/apps/news/api/v1-2/items/{itemId}/read": { + "/apps/news/api/v1-3/items/{itemId}/read": { "parameters": [ { "name": "itemId", @@ -2288,7 +2288,7 @@ } } ], - "put": { + "post": { "operationId": "mark-article-as-read", "tags": [ "news" @@ -2300,7 +2300,7 @@ } } }, - "/apps/news/api/v1-2/items/{itemId}/unread": { + "/apps/news/api/v1-3/items/{itemId}/unread": { "parameters": [ { "name": "itemId", @@ -2311,7 +2311,7 @@ } } ], - "put": { + "post": { "operationId": "mark-article-as-unread", "tags": [ "news" @@ -2323,26 +2323,18 @@ } } }, - "/apps/news/api/v1-2/items/{feedId}/{guidHash}/star": { + "/apps/news/api/v1-3/items/{itemId}/star": { "parameters": [ { - "name": "feedId", + "name": "itemId", "in": "path", "required": true, "schema": { "type": "integer" } - }, - { - "name": "guidHash", - "in": "path", - "required": true, - "schema": { - "type": "string" - } } ], - "put": { + "post": { "operationId": "star-article", "tags": [ "news" @@ -2354,26 +2346,18 @@ } } }, - "/apps/news/api/v1-2/items/{feedId}/{guidHash}/unstar": { + "/apps/news/api/v1-3/items/{itemId}/unstar": { "parameters": [ { - "name": "feedId", + "name": "itemId", "in": "path", "required": true, "schema": { "type": "integer" } - }, - { - "name": "guidHash", - "in": "path", - "required": true, - "schema": { - "type": "string" - } } ], - "put": { + "post": { "operationId": "unstar-article", "tags": [ "news" diff --git a/packages/nextcloud/lib/src/version_supported.dart b/packages/nextcloud/lib/src/version_supported.dart index cdc323c4..56aeae89 100644 --- a/packages/nextcloud/lib/src/version_supported.dart +++ b/packages/nextcloud/lib/src/version_supported.dart @@ -12,7 +12,7 @@ extension NewsVersionSupported on NewsClient { /// Checks if the app on the server is supported by the client Future isSupported() async { final versions = await getSupportedApiVersions(); - return versions.apiLevels!.contains('v1-2'); + return versions.apiLevels!.contains('v1-3'); } } diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index 1cc3d6e3..196f1a41 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -140,8 +140,7 @@ Future main() async { response = await client.news.listArticles(); await client.news.starArticle( - feedId: response.items![0].feedId!, - guidHash: response.items![0].guidHash!, + itemId: response.items![0].id!, ); response = await client.news.listArticles(type: 2); expect(response.items, hasLength(1)); @@ -154,15 +153,13 @@ Future main() async { final item = response.items![0]; await client.news.starArticle( - feedId: item.feedId!, - guidHash: item.guidHash!, + itemId: item.id!, ); response = await client.news.listArticles(type: 2); expect(response.items, hasLength(1)); await client.news.unstarArticle( - feedId: item.feedId!, - guidHash: item.guidHash!, + itemId: item.id!, ); response = await client.news.listArticles(type: 2); expect(response.items, hasLength(0)); diff --git a/specs/news.json b/specs/news.json index f27d15bd..b60ed99b 100644 --- a/specs/news.json +++ b/specs/news.json @@ -264,7 +264,7 @@ } } }, - "/apps/news/api/v1-2/folders": { + "/apps/news/api/v1-3/folders": { "get": { "operationId": "list-folders", "tags": [ @@ -312,7 +312,7 @@ } } }, - "/apps/news/api/v1-2/folders/{folderId}": { + "/apps/news/api/v1-3/folders/{folderId}": { "parameters": [ { "name": "folderId", @@ -356,7 +356,7 @@ } } }, - "/apps/news/api/v1-2/folders/{folderId}/read": { + "/apps/news/api/v1-3/folders/{folderId}/read": { "parameters": [ { "name": "folderId", @@ -368,7 +368,7 @@ } } ], - "put": { + "post": { "operationId": "mark-folder-as-read", "tags": [ "news" @@ -391,7 +391,7 @@ } } }, - "/apps/news/api/v1-2/feeds": { + "/apps/news/api/v1-3/feeds": { "get": { "operationId": "list-feeds", "tags": [ @@ -447,7 +447,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}": { + "/apps/news/api/v1-3/feeds/{feedId}": { "parameters": [ { "name": "feedId", @@ -470,7 +470,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/move": { + "/apps/news/api/v1-3/feeds/{feedId}/move": { "parameters": [ { "name": "feedId", @@ -503,7 +503,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/rename": { + "/apps/news/api/v1-3/feeds/{feedId}/rename": { "parameters": [ { "name": "feedId", @@ -536,7 +536,7 @@ } } }, - "/apps/news/api/v1-2/feeds/{feedId}/read": { + "/apps/news/api/v1-3/feeds/{feedId}/read": { "parameters": [ { "name": "feedId", @@ -547,7 +547,7 @@ } } ], - "put": { + "post": { "operationId": "mark-feed-as-read", "tags": [ "news" @@ -569,7 +569,7 @@ } } }, - "/apps/news/api/v1-2/items": { + "/apps/news/api/v1-3/items": { "get": { "operationId": "list-articles", "tags": [ @@ -645,7 +645,7 @@ } } }, - "/apps/news/api/v1-2/items/updated": { + "/apps/news/api/v1-3/items/updated": { "get": { "operationId": "list-updated-articles", "tags": [ @@ -694,7 +694,7 @@ } } }, - "/apps/news/api/v1-2/items/{itemId}/read": { + "/apps/news/api/v1-3/items/{itemId}/read": { "parameters": [ { "name": "itemId", @@ -705,7 +705,7 @@ } } ], - "put": { + "post": { "operationId": "mark-article-as-read", "tags": [ "news" @@ -717,7 +717,7 @@ } } }, - "/apps/news/api/v1-2/items/{itemId}/unread": { + "/apps/news/api/v1-3/items/{itemId}/unread": { "parameters": [ { "name": "itemId", @@ -728,7 +728,7 @@ } } ], - "put": { + "post": { "operationId": "mark-article-as-unread", "tags": [ "news" @@ -740,26 +740,18 @@ } } }, - "/apps/news/api/v1-2/items/{feedId}/{guidHash}/star": { + "/apps/news/api/v1-3/items/{itemId}/star": { "parameters": [ { - "name": "feedId", + "name": "itemId", "in": "path", "required": true, "schema": { "type": "integer" } - }, - { - "name": "guidHash", - "in": "path", - "required": true, - "schema": { - "type": "string" - } } ], - "put": { + "post": { "operationId": "star-article", "tags": [ "news" @@ -771,26 +763,18 @@ } } }, - "/apps/news/api/v1-2/items/{feedId}/{guidHash}/unstar": { + "/apps/news/api/v1-3/items/{itemId}/unstar": { "parameters": [ { - "name": "feedId", + "name": "itemId", "in": "path", "required": true, "schema": { "type": "integer" } - }, - { - "name": "guidHash", - "in": "path", - "required": true, - "schema": { - "type": "string" - } } ], - "put": { + "post": { "operationId": "unstar-article", "tags": [ "news"