Use adapters with Nextcloud News create feed and folder api calls

This commit is contained in:
Shinokuni 2020-01-13 11:25:14 +01:00
parent 6d79fdf64d
commit 4454c5c028
3 changed files with 14 additions and 21 deletions

View File

@ -20,9 +20,7 @@ import com.readrops.readropslibrary.services.nextcloudnews.NextNewsAPI;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncData;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncResult;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import com.readrops.readropslibrary.utils.UnknownFormatException;
@ -144,12 +142,12 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
FeedInsertionResult insertionResult = new FeedInsertionResult();
try {
NextNewsFeeds nextNewsFeeds = api.createFeed(result.getUrl(), 0);
List<Feed> nextNewsFeeds = api.createFeed(result.getUrl(), 0);
if (nextNewsFeeds != null) {
/*List<Feed> newFeeds = insertFeeds(nextNewsFeeds.getFeeds());
List<Feed> newFeeds = insertFeeds(nextNewsFeeds);
// there is always only one object in the list, see nextcloud news api doc
insertionResult.setFeed(newFeeds.get(0));*/
insertionResult.setFeed(newFeeds.get(0));
} else
insertionResult.setInsertionError(FeedInsertionResult.FeedInsertionError.UNKNOWN_ERROR);
@ -216,10 +214,10 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
return Single.<Folder>create(emitter -> {
try {
int folderRemoteId = folder.getRemoteId() == null ? 0 : Integer.parseInt(folder.getRemoteId());
NextNewsFolders folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName()));
List<Folder> folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName()));
if (folders != null) {
NextNewsFolder nextNewsFolder = folders.getFolders().get(0); // always only one item returned by the server, see doc
Folder nextNewsFolder = folders.get(0); // always only one item returned by the server, see doc
folder.setName(nextNewsFolder.getName());
folder.setRemoteId(String.valueOf(nextNewsFolder.getId()));

View File

@ -15,9 +15,7 @@ import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeed
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFoldersAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsItemsAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
@ -28,6 +26,7 @@ import com.squareup.moshi.Moshi;
import com.squareup.moshi.Types;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -61,10 +60,9 @@ public class NextNewsAPI extends API<NextNewsService> {
return response.body();
}
public @Nullable
NextNewsFeeds createFeed(String url, int folderId)
throws IOException, UnknownFormatException {
Response<NextNewsFeeds> response = api.createFeed(url, folderId).execute();
@Nullable
public List<Feed> createFeed(String url, int folderId) throws IOException, UnknownFormatException {
Response<List<Feed>> response = api.createFeed(url, folderId).execute();
if (!response.isSuccessful()) {
if (response.code() == LibUtils.HTTP_UNPROCESSABLE)
@ -158,9 +156,8 @@ public class NextNewsAPI extends API<NextNewsService> {
syncResult.setError(true);
}
public @Nullable
NextNewsFolders createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException {
Response<NextNewsFolders> foldersResponse = api.createFolder(folder).execute();
public List<Folder> createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException {
Response<List<Folder>> foldersResponse = api.createFolder(folder).execute();
if (foldersResponse.isSuccessful())
return foldersResponse.body();
@ -169,7 +166,7 @@ public class NextNewsAPI extends API<NextNewsService> {
else if (foldersResponse.code() == LibUtils.HTTP_CONFLICT)
throw new ConflictException();
else
return null;
return new ArrayList<>();
}
public boolean deleteFolder(NextNewsFolder folder) throws IOException {

View File

@ -3,9 +3,7 @@ package com.readrops.readropslibrary.services.nextcloudnews;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
@ -46,7 +44,7 @@ public interface NextNewsService {
Call<ResponseBody> setArticlesState(@Path("stateType") String stateType, @Body NextNewsItemIds items);
@POST("feeds")
Call<NextNewsFeeds> createFeed(@Query("url") String url, @Query("folderId") int folderId);
Call<List<Feed>> createFeed(@Query("url") String url, @Query("folderId") int folderId);
@DELETE("feeds/{feedId}")
Call<Void> deleteFeed(@Path("feedId") int feedId);
@ -58,7 +56,7 @@ public interface NextNewsService {
Call<ResponseBody> renameFeed(@Path("feedId") int feedId, @Body NextNewsRenameFeed feed);
@POST("folders")
Call<NextNewsFolders> createFolder(@Body NextNewsFolder folder);
Call<List<Folder>> createFolder(@Body NextNewsFolder folder);
@DELETE("folders/{folderId}")
Call<ResponseBody> deleteFolder(@Path("folderId") int folderId);