mirror of https://github.com/readrops/Readrops.git
Rename LibUtils to ApiUtils
This commit is contained in:
parent
5e76eb4134
commit
412ec3f1b8
|
@ -4,7 +4,7 @@ import android.accounts.NetworkErrorException
|
|||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.utils.LibUtils
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import com.readrops.api.utils.exceptions.UnknownFormatException
|
||||
import junit.framework.TestCase.*
|
||||
|
@ -46,9 +46,9 @@ class LocalRSSDataSourceTest {
|
|||
val stream = context.resources.assets.open("localfeed/rss_feed.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/xml; charset=UTF-8")
|
||||
.addHeader(LibUtils.ETAG_HEADER, "ETag-value")
|
||||
.addHeader(LibUtils.LAST_MODIFIED_HEADER, "Last-Modified")
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/xml; charset=UTF-8")
|
||||
.addHeader(ApiUtils.ETAG_HEADER, "ETag-value")
|
||||
.addHeader(ApiUtils.LAST_MODIFIED_HEADER, "Last-Modified")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
|
||||
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)
|
||||
|
@ -73,13 +73,13 @@ class LocalRSSDataSourceTest {
|
|||
.addHeader("Content-Type", "application/rss+xml; charset=UTF-8")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
|
||||
val headers = Headers.headersOf(LibUtils.ETAG_HEADER, "ETag", LibUtils.LAST_MODIFIED_HEADER, "Last-Modified")
|
||||
val headers = Headers.headersOf(ApiUtils.ETAG_HEADER, "ETag", ApiUtils.LAST_MODIFIED_HEADER, "Last-Modified")
|
||||
localRSSDataSource.queryRSSResource(url.toString(), headers)
|
||||
|
||||
val request = mockServer.takeRequest()
|
||||
|
||||
assertEquals(request.headers[LibUtils.ETAG_HEADER], "ETag")
|
||||
assertEquals(request.headers[LibUtils.LAST_MODIFIED_HEADER], "Last-Modified")
|
||||
assertEquals(request.headers[ApiUtils.ETAG_HEADER], "ETag")
|
||||
assertEquals(request.headers[ApiUtils.LAST_MODIFIED_HEADER], "Last-Modified")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,7 +87,7 @@ class LocalRSSDataSourceTest {
|
|||
val stream = context.resources.assets.open("localfeed/json/json_feed.json")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/feed+json")
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/feed+json")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
|
||||
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!!
|
||||
|
@ -101,7 +101,7 @@ class LocalRSSDataSourceTest {
|
|||
val stream = context.resources.assets.open("localfeed/atom/atom_feed_no_url_siteurl.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/atom+xml")
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/atom+xml")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
|
||||
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!!
|
||||
|
@ -115,7 +115,7 @@ class LocalRSSDataSourceTest {
|
|||
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed_no_url_siteurl.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/rdf+xml")
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/rdf+xml")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
|
||||
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!!
|
||||
|
|
|
@ -4,7 +4,7 @@ import android.accounts.NetworkErrorException
|
|||
import androidx.annotation.WorkerThread
|
||||
import com.readrops.api.localfeed.json.JSONFeedAdapter
|
||||
import com.readrops.api.localfeed.json.JSONItemsAdapter
|
||||
import com.readrops.api.utils.LibUtils
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import com.readrops.api.utils.exceptions.UnknownFormatException
|
||||
import com.readrops.db.entities.Feed
|
||||
|
@ -36,10 +36,10 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
|||
|
||||
return when {
|
||||
response.isSuccessful -> {
|
||||
val header = response.header(LibUtils.CONTENT_TYPE_HEADER)
|
||||
val header = response.header(ApiUtils.CONTENT_TYPE_HEADER)
|
||||
?: throw UnknownFormatException("Unable to get $url content-type")
|
||||
|
||||
val contentType = LibUtils.parseContentType(header)
|
||||
val contentType = ApiUtils.parseContentType(header)
|
||||
?: throw ParseException("Unable to parse $url content-type")
|
||||
|
||||
var type = LocalRSSHelper.getRSSType(contentType)
|
||||
|
@ -73,10 +73,10 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
|||
val response = queryUrl(url, null)
|
||||
|
||||
return if (response.isSuccessful) {
|
||||
val header = response.header(LibUtils.CONTENT_TYPE_HEADER)
|
||||
val header = response.header(ApiUtils.CONTENT_TYPE_HEADER)
|
||||
?: return false
|
||||
|
||||
val contentType = LibUtils.parseContentType(header)
|
||||
val contentType = ApiUtils.parseContentType(header)
|
||||
?: return false
|
||||
|
||||
var type = LocalRSSHelper.getRSSType(contentType)
|
||||
|
@ -112,8 +112,8 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
|||
|
||||
handleSpecialCases(feed, type, response)
|
||||
|
||||
feed.etag = response.header(LibUtils.ETAG_HEADER)
|
||||
feed.lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER)
|
||||
feed.etag = response.header(ApiUtils.ETAG_HEADER)
|
||||
feed.lastModified = response.header(ApiUtils.LAST_MODIFIED_HEADER)
|
||||
|
||||
return feed
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class RSS2ItemsAdapter : XmlAdapter<List<Item>> {
|
|||
val item = Item().apply {
|
||||
allChildrenAutoIgnore(names) {
|
||||
when (tagName) {
|
||||
"title" -> title = LibUtils.cleanText(nonNullText())
|
||||
"title" -> title = ApiUtils.cleanText(nonNullText())
|
||||
"link" -> link = nonNullText()
|
||||
"author" -> author = nullableText()
|
||||
"dc:creator" -> creators += nullableText()
|
||||
|
@ -60,16 +60,16 @@ class RSS2ItemsAdapter : XmlAdapter<List<Item>> {
|
|||
|
||||
private fun parseEnclosure(konsumer: Konsumer, item: Item) {
|
||||
if (konsumer.attributes.getValueOpt("type") != null
|
||||
&& LibUtils.isMimeImage(konsumer.attributes["type"]) && item.imageLink == null)
|
||||
&& ApiUtils.isMimeImage(konsumer.attributes["type"]) && item.imageLink == null)
|
||||
item.imageLink = konsumer.attributes.getValueOpt("url")
|
||||
}
|
||||
|
||||
private fun isMediumImage(konsumer: Konsumer) = with(konsumer) {
|
||||
attributes.getValueOpt("medium") != null && LibUtils.isMimeImage(attributes["medium"])
|
||||
attributes.getValueOpt("medium") != null && ApiUtils.isMimeImage(attributes["medium"])
|
||||
}
|
||||
|
||||
private fun isTypeImage(konsumer: Konsumer) = with(konsumer) {
|
||||
attributes.getValueOpt("type") != null && LibUtils.isMimeImage(attributes["type"])
|
||||
attributes.getValueOpt("type") != null && ApiUtils.isMimeImage(attributes["type"])
|
||||
}
|
||||
|
||||
private fun parseMediaContent(konsumer: Konsumer, item: Item) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.readrops.api.services.SyncResult;
|
|||
import com.readrops.api.services.SyncType;
|
||||
import com.readrops.api.services.nextcloudnews.json.NextNewsUser;
|
||||
import com.readrops.api.utils.exceptions.ConflictException;
|
||||
import com.readrops.api.utils.LibUtils;
|
||||
import com.readrops.api.utils.ApiUtils;
|
||||
import com.readrops.api.utils.exceptions.UnknownFormatException;
|
||||
import com.readrops.db.entities.Feed;
|
||||
import com.readrops.db.entities.Folder;
|
||||
|
@ -50,7 +50,7 @@ public class NextNewsDataSource {
|
|||
Response<List<Feed>> response = api.createFeed(url, folderId).execute();
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
if (response.code() == LibUtils.HTTP_UNPROCESSABLE)
|
||||
if (response.code() == ApiUtils.HTTP_UNPROCESSABLE)
|
||||
throw new UnknownFormatException();
|
||||
else
|
||||
return null;
|
||||
|
@ -156,9 +156,9 @@ public class NextNewsDataSource {
|
|||
|
||||
if (foldersResponse.isSuccessful())
|
||||
return foldersResponse.body();
|
||||
else if (foldersResponse.code() == LibUtils.HTTP_UNPROCESSABLE)
|
||||
else if (foldersResponse.code() == ApiUtils.HTTP_UNPROCESSABLE)
|
||||
throw new UnknownFormatException();
|
||||
else if (foldersResponse.code() == LibUtils.HTTP_CONFLICT)
|
||||
else if (foldersResponse.code() == ApiUtils.HTTP_CONFLICT)
|
||||
throw new ConflictException();
|
||||
else
|
||||
return new ArrayList<>();
|
||||
|
@ -169,7 +169,7 @@ public class NextNewsDataSource {
|
|||
|
||||
if (response.isSuccessful())
|
||||
return true;
|
||||
else if (response.code() == LibUtils.HTTP_NOT_FOUND)
|
||||
else if (response.code() == ApiUtils.HTTP_NOT_FOUND)
|
||||
throw new Resources.NotFoundException();
|
||||
else
|
||||
return false;
|
||||
|
@ -185,11 +185,11 @@ public class NextNewsDataSource {
|
|||
return true;
|
||||
else {
|
||||
switch (response.code()) {
|
||||
case LibUtils.HTTP_NOT_FOUND:
|
||||
case ApiUtils.HTTP_NOT_FOUND:
|
||||
throw new Resources.NotFoundException();
|
||||
case LibUtils.HTTP_UNPROCESSABLE:
|
||||
case ApiUtils.HTTP_UNPROCESSABLE:
|
||||
throw new UnknownFormatException();
|
||||
case LibUtils.HTTP_CONFLICT:
|
||||
case ApiUtils.HTTP_CONFLICT:
|
||||
throw new ConflictException();
|
||||
default:
|
||||
return false;
|
||||
|
@ -202,7 +202,7 @@ public class NextNewsDataSource {
|
|||
|
||||
if (response.isSuccessful())
|
||||
return true;
|
||||
else if (response.code() == LibUtils.HTTP_NOT_FOUND)
|
||||
else if (response.code() == ApiUtils.HTTP_NOT_FOUND)
|
||||
throw new Resources.NotFoundException();
|
||||
else
|
||||
return false;
|
||||
|
@ -216,7 +216,7 @@ public class NextNewsDataSource {
|
|||
|
||||
if (response.isSuccessful())
|
||||
return true;
|
||||
else if (response.code() == LibUtils.HTTP_NOT_FOUND)
|
||||
else if (response.code() == ApiUtils.HTTP_NOT_FOUND)
|
||||
throw new Resources.NotFoundException();
|
||||
else
|
||||
return false;
|
||||
|
@ -230,7 +230,7 @@ public class NextNewsDataSource {
|
|||
|
||||
if (response.isSuccessful())
|
||||
return true;
|
||||
else if (response.code() == LibUtils.HTTP_NOT_FOUND)
|
||||
else if (response.code() == ApiUtils.HTTP_NOT_FOUND)
|
||||
throw new Resources.NotFoundException();
|
||||
else
|
||||
return false;
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.readrops.api.services.nextcloudnews.adapters
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import com.readrops.db.entities.Item
|
||||
import com.readrops.api.utils.LibUtils
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.extensions.nextNullableString
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.JsonReader
|
||||
|
@ -50,7 +50,7 @@ class NextNewsItemsAdapter : JsonAdapter<List<Item>>() {
|
|||
}
|
||||
}
|
||||
|
||||
if (enclosureMime != null && LibUtils.isMimeImage(enclosureMime!!))
|
||||
if (enclosureMime != null && ApiUtils.isMimeImage(enclosureMime!!))
|
||||
item.imageLink = enclosureLink
|
||||
|
||||
items += item
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.jsoup.Jsoup;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class LibUtils {
|
||||
public final class ApiUtils {
|
||||
|
||||
public static final String HTML_CONTENT_TYPE = "text/html";
|
||||
|
|
@ -3,23 +3,23 @@ package com.readrops.api.utils
|
|||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class LibUtilsTest {
|
||||
class ApiUtilsTest {
|
||||
|
||||
@Test
|
||||
fun contentTypeWithCharsetTest() {
|
||||
assertEquals(LibUtils.parseContentType("application/rss+xml; charset=UTF-8"),
|
||||
assertEquals(ApiUtils.parseContentType("application/rss+xml; charset=UTF-8"),
|
||||
"application/rss+xml")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentTypeWithoutCharsetText() {
|
||||
assertEquals(LibUtils.parseContentType("text/xml"),
|
||||
assertEquals(ApiUtils.parseContentType("text/xml"),
|
||||
"text/xml")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cleanTextTest() {
|
||||
val text = " <p>This is a text<br/>to</p> clean "
|
||||
assertEquals("This is a text to clean", LibUtils.cleanText(text))
|
||||
assertEquals("This is a text to clean", ApiUtils.cleanText(text))
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import com.readrops.api.localfeed.LocalRSSDataSource;
|
||||
import com.readrops.api.services.SyncResult;
|
||||
import com.readrops.api.utils.LibUtils;
|
||||
import com.readrops.api.utils.ApiUtils;
|
||||
import com.readrops.api.utils.exceptions.ParseException;
|
||||
import com.readrops.api.utils.exceptions.UnknownFormatException;
|
||||
import com.readrops.app.utils.FeedInsertionResult;
|
||||
|
@ -69,10 +69,10 @@ public class LocalFeedRepository extends ARepository {
|
|||
try {
|
||||
Headers.Builder headers = new Headers.Builder();
|
||||
if (feed.getEtag() != null) {
|
||||
headers.add(LibUtils.IF_NONE_MATCH_HEADER, feed.getEtag());
|
||||
headers.add(ApiUtils.IF_NONE_MATCH_HEADER, feed.getEtag());
|
||||
}
|
||||
if (feed.getLastModified() != null) {
|
||||
headers.add(LibUtils.IF_MODIFIED_HEADER, feed.getLastModified());
|
||||
headers.add(ApiUtils.IF_MODIFIED_HEADER, feed.getLastModified());
|
||||
}
|
||||
|
||||
Pair<Feed, List<Item>> pair = dataSource.queryRSSResource(feed.getUrl(), headers.build());
|
||||
|
|
|
@ -6,7 +6,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.readrops.api.localfeed.LocalRSSHelper;
|
||||
import com.readrops.api.utils.LibUtils;
|
||||
import com.readrops.api.utils.ApiUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
@ -87,7 +87,7 @@ public final class HtmlParser {
|
|||
Response response = KoinJavaComponent.get(OkHttpClient.class)
|
||||
.newCall(new Request.Builder().url(url).build()).execute();
|
||||
|
||||
if (response.header("Content-Type").contains(LibUtils.HTML_CONTENT_TYPE)) {
|
||||
if (response.header("Content-Type").contains(ApiUtils.HTML_CONTENT_TYPE)) {
|
||||
String body = response.body().string();
|
||||
String head = body.substring(body.indexOf("<head"), body.indexOf("</head>"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue