diff --git a/api/src/main/java/com/readrops/api/services/Credentials.java b/api/src/main/java/com/readrops/api/services/Credentials.java deleted file mode 100644 index 755ff918..00000000 --- a/api/src/main/java/com/readrops/api/services/Credentials.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.readrops.api.services; - -import com.readrops.api.services.freshrss.FreshRSSCredentials; -import com.readrops.api.services.freshrss.FreshRSSService; -import com.readrops.api.services.nextcloudnews.NextNewsCredentials; -import com.readrops.api.services.nextcloudnews.NextNewsService; -import com.readrops.db.entities.account.Account; -import com.readrops.db.entities.account.AccountType; - -public abstract class Credentials { - - private final String authorization; - - private String url; - - public Credentials(String authorization, String url) { - this.authorization = authorization; - this.url = url; - } - - public String getAuthorization() { - return authorization; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public static Credentials toCredentials(Account account) { - String endPoint = getEndPoint(account.getAccountType()); - - switch (account.getAccountType()) { - case NEXTCLOUD_NEWS: - return new NextNewsCredentials(account.getLogin(), account.getPassword(), account.getUrl() + endPoint); - case FRESHRSS: - return new FreshRSSCredentials(account.getToken(), account.getUrl() + endPoint); - default: - throw new IllegalArgumentException("Unknown account type"); - } - } - - private static String getEndPoint(AccountType accountType) { - switch (accountType) { - case FRESHRSS: - return FreshRSSService.END_POINT; - case NEXTCLOUD_NEWS: - return NextNewsService.END_POINT; - default: - throw new IllegalArgumentException("Unknown account type"); - } - } -} diff --git a/api/src/main/java/com/readrops/api/services/Credentials.kt b/api/src/main/java/com/readrops/api/services/Credentials.kt new file mode 100644 index 00000000..38a223f4 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/Credentials.kt @@ -0,0 +1,32 @@ +package com.readrops.api.services + +import com.readrops.api.services.freshrss.FreshRSSCredentials +import com.readrops.api.services.freshrss.FreshRSSService +import com.readrops.api.services.nextcloudnews.NextNewsCredentials +import com.readrops.api.services.nextcloudnews.NextNewsService +import com.readrops.db.entities.account.Account +import com.readrops.db.entities.account.AccountType + +abstract class Credentials(val authorization: String?, val url: String) { + + companion object { + @JvmStatic + fun toCredentials(account: Account): Credentials { + val endPoint = getEndPoint(account.accountType) + + return when (account.accountType) { + AccountType.NEXTCLOUD_NEWS -> NextNewsCredentials(account.login, account.password, account.url + endPoint) + AccountType.FRESHRSS -> FreshRSSCredentials(account.token, account.url + endPoint) + else -> throw IllegalArgumentException("Unknown account type") + } + } + + private fun getEndPoint(accountType: AccountType): String { + return when (accountType) { + AccountType.FRESHRSS -> FreshRSSService.END_POINT + AccountType.NEXTCLOUD_NEWS -> NextNewsService.END_POINT + else -> throw IllegalArgumentException("Unknown account type") + } + } + } +} \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/SyncType.java b/api/src/main/java/com/readrops/api/services/SyncType.java deleted file mode 100644 index efbb274e..00000000 --- a/api/src/main/java/com/readrops/api/services/SyncType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.readrops.api.services; - -public enum SyncType { - INITIAL_SYNC, - CLASSIC_SYNC -} diff --git a/api/src/main/java/com/readrops/api/services/SyncType.kt b/api/src/main/java/com/readrops/api/services/SyncType.kt new file mode 100644 index 00000000..51d87e93 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/SyncType.kt @@ -0,0 +1,5 @@ +package com.readrops.api.services + +enum class SyncType { + INITIAL_SYNC, CLASSIC_SYNC +} \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.java b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.java deleted file mode 100644 index 0ad89f45..00000000 --- a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.readrops.api.services.freshrss; - -import com.readrops.api.services.Credentials; - -public class FreshRSSCredentials extends Credentials { - - private static final String AUTH_PREFIX = "GoogleLogin auth="; - - public FreshRSSCredentials(String token, String url) { - super(token != null ? AUTH_PREFIX + token : null, url); - - } -} diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.kt b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.kt new file mode 100644 index 00000000..b8446a18 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSCredentials.kt @@ -0,0 +1,11 @@ +package com.readrops.api.services.freshrss + +import com.readrops.api.services.Credentials + +class FreshRSSCredentials(token: String?, url: String) : + Credentials(token?.let { AUTH_PREFIX + it }, url) { + + companion object { + private const val AUTH_PREFIX = "GoogleLogin auth=" + } +} \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.java b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.java deleted file mode 100644 index d3e17269..00000000 --- a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.readrops.api.services.freshrss; - -import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo; -import com.readrops.db.entities.Feed; -import com.readrops.db.entities.Folder; -import com.readrops.db.entities.Item; - -import java.util.List; - -import io.reactivex.Completable; -import io.reactivex.Single; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import retrofit2.http.Body; -import retrofit2.http.Field; -import retrofit2.http.FormUrlEncoded; -import retrofit2.http.GET; -import retrofit2.http.POST; -import retrofit2.http.Query; - -public interface FreshRSSService { - - String END_POINT = "/api/greader.php/"; - - @POST("accounts/ClientLogin") - Single login(@Body RequestBody body); - - @GET("reader/api/0/token") - Single getWriteToken(); - - @GET("reader/api/0/user-info") - Single getUserInfo(); - - @GET("reader/api/0/subscription/list?output=json") - Single> getFeeds(); - - @GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list") - Single> getItems(@Query("xt") List excludeTarget, @Query("n") int max, @Query("ot") Long lastModified); - - @GET("reader/api/0/stream/contents/user/-/state/com.google/starred") - Single> getStarredItems(@Query("n") int max); - - @GET("reader/api/0/stream/items/ids") - Single> getItemsIds(@Query("xt") String excludeTarget, @Query("s") String includeTarget, @Query("n") int max); - - @GET("reader/api/0/tag/list?output=json") - Single> getFolders(); - - @FormUrlEncoded - @POST("reader/api/0/edit-tag") - Completable setItemsState(@Field("T") String token, @Field("a") String addAction, @Field("r") String removeAction, @Field("i") List itemIds); - - @FormUrlEncoded - @POST("reader/api/0/subscription/edit") - Completable createOrDeleteFeed(@Field("T") String token, @Field("s") String feedUrl, @Field("ac") String action); - - @FormUrlEncoded - @POST("reader/api/0/subscription/edit") - Completable updateFeed(@Field("T") String token, @Field("s") String feedUrl, @Field("t") String title, @Field("a") String folderId, @Field("ac") String action); - - @FormUrlEncoded - @POST("reader/api/0/edit-tag") - Completable createFolder(@Field("T") String token, @Field("a") String tagName); - - @FormUrlEncoded - @POST("reader/api/0/rename-tag") - Completable updateFolder(@Field("T") String token, @Field("s") String folderId, @Field("dest") String newFolderId); - - @FormUrlEncoded - @POST("reader/api/0/disable-tag") - Completable deleteFolder(@Field("T") String token, @Field("s") String folderId); -} diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt new file mode 100644 index 00000000..4069b1bb --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt @@ -0,0 +1,70 @@ +package com.readrops.api.services.freshrss + +import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo +import com.readrops.db.entities.Feed +import com.readrops.db.entities.Folder +import com.readrops.db.entities.Item +import io.reactivex.Completable +import io.reactivex.Single +import okhttp3.RequestBody +import okhttp3.ResponseBody +import retrofit2.http.* + +interface FreshRSSService { + + @POST("accounts/ClientLogin") + fun login(@Body body: RequestBody?): Single? + + @get:GET("reader/api/0/token") + val writeToken: Single + + @get:GET("reader/api/0/user-info") + val userInfo: Single + + @get:GET("reader/api/0/subscription/list?output=json") + val feeds: Single> + + @get:GET("reader/api/0/tag/list?output=json") + val folders: Single> + + @GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list") + fun getItems(@Query("xt") excludeTarget: List?, @Query("n") max: Int, + @Query("ot") lastModified: Long?): Single> + + @GET("reader/api/0/stream/contents/user/-/state/com.google/starred") + fun getStarredItems(@Query("n") max: Int): Single> + + @GET("reader/api/0/stream/items/ids") + fun getItemsIds(@Query("xt") excludeTarget: String?, @Query("s") includeTarget: String?, + @Query("n") max: Int): Single> + + @FormUrlEncoded + @POST("reader/api/0/edit-tag") + fun setItemsState(@Field("T") token: String, @Field("a") addAction: String?, + @Field("r") removeAction: String?, @Field("i") itemIds: List): Completable + + @FormUrlEncoded + @POST("reader/api/0/subscription/edit") + fun createOrDeleteFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("ac") action: String): Completable + + @FormUrlEncoded + @POST("reader/api/0/subscription/edit") + fun updateFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("t") title: String, + @Field("a") folderId: String, @Field("ac") action: String): Completable + + @FormUrlEncoded + @POST("reader/api/0/edit-tag") + fun createFolder(@Field("T") token: String, @Field("a") tagName: String): Completable + + @FormUrlEncoded + @POST("reader/api/0/rename-tag") + fun updateFolder(@Field("T") token: String, @Field("s") folderId: String, @Field("dest") newFolderId: String): Completable + + @FormUrlEncoded + @POST("reader/api/0/disable-tag") + fun deleteFolder(@Field("T") token: String, @Field("s") folderId: String): Completable + + companion object { + const val END_POINT = "/api/greader.php/" + } +} \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.java b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.java deleted file mode 100644 index dde0c8b2..00000000 --- a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.readrops.api.services.freshrss; - -import java.util.ArrayList; -import java.util.List; - -public class FreshRSSSyncData { - - private long lastModified; - - private List readItemsIds; - - private List unreadItemsIds; - - private List starredItemsIds; - - private List unstarredItemsIds; - - public FreshRSSSyncData() { - readItemsIds = new ArrayList<>(); - unreadItemsIds = new ArrayList<>(); - } - - public long getLastModified() { - return lastModified; - } - - public void setLastModified(long lastModified) { - this.lastModified = lastModified; - } - - public List getReadItemsIds() { - return readItemsIds; - } - - public void setReadItemsIds(List readItemsIds) { - this.readItemsIds = readItemsIds; - } - - public List getUnreadItemsIds() { - return unreadItemsIds; - } - - public void setUnreadItemsIds(List unreadItemsIds) { - this.unreadItemsIds = unreadItemsIds; - } - - public List getStarredItemsIds() { - return starredItemsIds; - } - - public void setStarredItemsIds(List starredItemsIds) { - this.starredItemsIds = starredItemsIds; - } - - public List getUnstarredItemsIds() { - return unstarredItemsIds; - } - - public void setUnstarredItemsIds(List unstarredItemsIds) { - this.unstarredItemsIds = unstarredItemsIds; - } -} diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.kt b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.kt new file mode 100644 index 00000000..e783b4ac --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSSyncData.kt @@ -0,0 +1,9 @@ +package com.readrops.api.services.freshrss + +data class FreshRSSSyncData( + var lastModified: Long = 0, + var readItemsIds: List = listOf(), + var unreadItemsIds: List = listOf(), + var starredItemsIds: List = listOf(), + var unstarredItemsIds: List = listOf(), +) \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.java b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.java deleted file mode 100644 index 24c44ab7..00000000 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.readrops.api.services.nextcloudnews; - -import com.readrops.api.services.Credentials; - -public class NextNewsCredentials extends Credentials { - - public NextNewsCredentials(String login, String password, String url) { - super(login != null && password != null ? okhttp3.Credentials.basic(login, password) : null, url); - } -} diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.kt new file mode 100644 index 00000000..21c86283 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsCredentials.kt @@ -0,0 +1,8 @@ +package com.readrops.api.services.nextcloudnews + +import com.readrops.api.services.Credentials + +class NextNewsCredentials(login: String?, password: String?, url: String): + Credentials((login != null && password != null).let { + okhttp3.Credentials.basic(login!!, password!!) + }, url) \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.java b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.java deleted file mode 100644 index cf1ce098..00000000 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.readrops.api.services.nextcloudnews; - -import com.readrops.db.entities.Feed; -import com.readrops.db.entities.Folder; -import com.readrops.db.entities.Item; - -import java.util.List; -import java.util.Map; - -import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.DELETE; -import retrofit2.http.GET; -import retrofit2.http.Headers; -import retrofit2.http.POST; -import retrofit2.http.PUT; -import retrofit2.http.Path; -import retrofit2.http.Query; - -public interface NextNewsService { - - String END_POINT = "/index.php/apps/news/api/v1-2/"; - - @GET("/ocs/v1.php/cloud/users/{userId}") - @Headers("OCS-APIRequest: true") - Call getUser(@Path("userId") String userId); - - @GET("folders") - Call> getFolders(); - - @GET("feeds") - Call> getFeeds(); - - @GET("items") - Call> getItems(@Query("type") int type, @Query("getRead") boolean read, @Query("batchSize") int batchSize); - - @GET("items/updated") - Call> getNewItems(@Query("lastModified") long lastModified, @Query("type") int type); - - @PUT("items/{stateType}/multiple") - Call setReadState(@Path("stateType") String stateType, @Body Map> itemIdsMap); - - @PUT("items/{starType}/multiple") - Call setStarState(@Path("starType") String starType, @Body Map>> body); - - @POST("feeds") - Call> createFeed(@Query("url") String url, @Query("folderId") int folderId); - - @DELETE("feeds/{feedId}") - Call deleteFeed(@Path("feedId") int feedId); - - @PUT("feeds/{feedId}/move") - Call changeFeedFolder(@Path("feedId") int feedId, @Body Map folderIdMap); - - @PUT("feeds/{feedId}/rename") - Call renameFeed(@Path("feedId") int feedId, @Body Map feedTitleMap); - - @POST("folders") - Call> createFolder(@Body Map folderName); - - @DELETE("folders/{folderId}") - Call deleteFolder(@Path("folderId") int folderId); - - @PUT("folders/{folderId}") - Call renameFolder(@Path("folderId") int folderId, @Body Map folderName); -} diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.kt new file mode 100644 index 00000000..d5c29075 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsService.kt @@ -0,0 +1,58 @@ +package com.readrops.api.services.nextcloudnews + +import com.readrops.db.entities.Feed +import com.readrops.db.entities.Folder +import com.readrops.db.entities.Item +import okhttp3.ResponseBody +import retrofit2.Call +import retrofit2.http.* + +interface NextNewsService { + + @GET("/ocs/v1.php/cloud/users/{userId}") + @Headers("OCS-APIRequest: true") + fun getUser(@Path("userId") userId: String): Call + + @get:GET("folders") + val folders: Call> + + @get:GET("feeds") + val feeds: Call> + + @GET("items") + fun getItems(@Query("type") type: Int, @Query("getRead") read: Boolean, @Query("batchSize") batchSize: Int): Call> + + @GET("items/updated") + fun getNewItems(@Query("lastModified") lastModified: Long, @Query("type") type: Int): Call> + + @PUT("items/{stateType}/multiple") + fun setReadState(@Path("stateType") stateType: String, @Body itemIdsMap: Map>): Call + + @PUT("items/{starType}/multiple") + fun setStarState(@Path("starType") starType: String?, @Body body: Map>>): Call + + @POST("feeds") + fun createFeed(@Query("url") url: String, @Query("folderId") folderId: Int): Call> + + @DELETE("feeds/{feedId}") + fun deleteFeed(@Path("feedId") feedId: Int): Call? + + @PUT("feeds/{feedId}/move") + fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map): Call + + @PUT("feeds/{feedId}/rename") + fun renameFeed(@Path("feedId") feedId: Int, @Body feedTitleMap: Map): Call + + @POST("folders") + fun createFolder(@Body folderName: Map): Call> + + @DELETE("folders/{folderId}") + fun deleteFolder(@Path("folderId") folderId: Int): Call + + @PUT("folders/{folderId}") + fun renameFolder(@Path("folderId") folderId: Int, @Body folderName: Map): Call + + companion object { + const val END_POINT = "/index.php/apps/news/api/v1-2/" + } +} \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.java b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.java deleted file mode 100644 index 0e59a982..00000000 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.readrops.api.services.nextcloudnews; - -import com.readrops.db.pojo.StarItem; - -import java.util.ArrayList; -import java.util.List; - -public class NextNewsSyncData { - - private List unreadItems; - - private List readItems; - - private List starredItems; - - private List unstarredItems; - - private long lastModified; - - public NextNewsSyncData() { - unreadItems = new ArrayList<>(); - readItems = new ArrayList<>(); - starredItems = new ArrayList<>(); - unstarredItems = new ArrayList<>(); - } - - public List getUnreadItems() { - return unreadItems; - } - - public void setUnreadItems(List unreadItems) { - this.unreadItems = unreadItems; - } - - public List getReadItems() { - return readItems; - } - - public void setReadItems(List readItems) { - this.readItems = readItems; - } - - public List getStarredItems() { - return starredItems; - } - - public void setStarredItems(List starredItems) { - this.starredItems = starredItems; - } - - public List getUnstarredItems() { - return unstarredItems; - } - - public void setUnstarredItems(List unstarredItems) { - this.unstarredItems = unstarredItems; - } - - public long getLastModified() { - return lastModified; - } - - public void setLastModified(long lastModified) { - this.lastModified = lastModified; - } -} diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.kt new file mode 100644 index 00000000..974d0154 --- /dev/null +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsSyncData.kt @@ -0,0 +1,11 @@ +package com.readrops.api.services.nextcloudnews + +import com.readrops.db.pojo.StarItem + +data class NextNewsSyncData( + var lastModified: Long = 0, + var unreadItems: List = listOf(), + var readItems: List = listOf(), + var starredItems: List = listOf(), + var unstarredItems: List = listOf(), +) \ No newline at end of file