Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Fuel and Kovenant dependencies #364

Merged
merged 4 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ navigator.addInputListener(DirectionalNavigationAdapter(

`DirectionalNavigationAdapter` offers a lot of customization options. Take a look at its API.

### Removal of Fuel and Kovenant

Both the Fuel and Kovenant libraries have been completely removed from the toolkit. With that, several deprecated functions have also been removed.

#### opds/OPDS1Parser

* Both `parseURL(url: URL)` and `parseURL(headers: MutableMap<String, String>, url: URL)` have been replaced with `parseUrlString(url: String, client: HttpClient = DefaultHttpClient())`.
* `fetchOpenSearchTemplate(feed: Feed)` has been replaced with `retrieveOpenSearchTemplate(feed: Feed)`.

#### opds/OPDS2Parser

* Both `parseURL(url: URL)` and `parseURL(headers: MutableMap<String, String>, url: URL)` have been replaced with `parseUrlString(url: String, client: HttpClient = DefaultHttpClient())`.

#### shared/FuelPromiseExtension

* `Request.promise()`

#### shared/format/Deprecated

* `Response.sniffFormat` has been replaced with `org.readium.r2.shared.util.mediatype.sniffMediaType`

#### shared/util/mediatype/Extensions

* `Response.sniffMediaType(...)` has been replaced with `org.readium.r2.shared.util.mediatype.sniffMediaType`


## 2.3.0

Expand Down
1 change: 0 additions & 1 deletion readium/opds/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.timber)
implementation(libs.joda.time)
implementation("nl.komponents.kovenant:kovenant:3.3.0")
implementation(libs.kotlinx.coroutines.core)

// Tests
Expand Down
18 changes: 0 additions & 18 deletions readium/opds/src/main/java/org/readium/r2/opds/Extensions.kt

This file was deleted.

84 changes: 0 additions & 84 deletions readium/opds/src/main/java/org/readium/r2/opds/OPDS1Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
package org.readium.r2.opds

import java.net.URL
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.then
import org.joda.time.DateTime
import org.readium.r2.shared.extensions.toList
import org.readium.r2.shared.extensions.toMap
Expand Down Expand Up @@ -60,29 +58,6 @@ class OPDS1Parser {
}
}

@Deprecated(
"Use `parseRequest` or `parseUrlString` with coroutines instead",
ReplaceWith("OPDS1Parser.parseUrlString(url)"),
DeprecationLevel.WARNING
)
fun parseURL(url: URL): Promise<ParseData, Exception> {
return DefaultHttpClient().fetchPromise(HttpRequest(url.toString())) then {
this.parse(xmlData = it.body, url = url)
}
}

@Deprecated(
"Use `parseRequest` or `parseUrlString` with coroutines instead",
ReplaceWith("OPDS1Parser.parseUrlString(url)"),
DeprecationLevel.WARNING
)
@Suppress("unused")
fun parseURL(headers: MutableMap<String, String>, url: URL): Promise<ParseData, Exception> {
return DefaultHttpClient().fetchPromise(HttpRequest(url = url.toString(), headers = headers)) then {
this.parse(xmlData = it.body, url = url)
}
}

fun parse(xmlData: ByteArray, url: URL): ParseData {
val root = XmlParser().parse(xmlData.inputStream())
return if (root.name == "feed")
Expand Down Expand Up @@ -254,65 +229,6 @@ class OPDS1Parser {
}
}

@Deprecated(
"Use `retrieveOpenSearchTemplate` with coroutines instead",
ReplaceWith("OPDS1Parser.retrieveOpenSearchTemplate(feed)"),
DeprecationLevel.WARNING
)
@Suppress("unused")
fun fetchOpenSearchTemplate(feed: Feed): Promise<String?, Exception> {

var openSearchURL: URL? = null
var selfMimeType: String? = null

for (link in feed.links) {
if (link.rels.contains("self")) {
if (link.type != null) {
selfMimeType = link.type
}
} else if (link.rels.contains("search")) {
openSearchURL = URL(link.href)
}
}

val unwrappedURL = openSearchURL?.let {
return@let it
}

return DefaultHttpClient().fetchPromise(HttpRequest(unwrappedURL.toString())) then {

val document = XmlParser().parse(it.body.inputStream())

val urls = document.get("Url", Namespaces.Search)

var typeAndProfileMatch: ElementNode? = null
var typeMatch: ElementNode? = null

selfMimeType?.let { s ->

val selfMimeParams = parseMimeType(mimeTypeString = s)
for (url in urls) {
val urlMimeType = url.getAttr("type") ?: continue
val otherMimeParams = parseMimeType(mimeTypeString = urlMimeType)
if (selfMimeParams.type == otherMimeParams.type) {
if (typeMatch == null) {
typeMatch = url
}
if (selfMimeParams.parameters["profile"] == otherMimeParams.parameters["profile"]) {
typeAndProfileMatch = url
break
}
}
}
val match = typeAndProfileMatch ?: (typeMatch ?: urls[0])
val template = match.getAttr("template")

template
}
null
}
}

private fun parseEntry(entry: ElementNode, baseUrl: URL): Publication? {
// A title is mandatory
val title = entry.getFirst("title", Namespaces.Atom)?.text
Expand Down
25 changes: 0 additions & 25 deletions readium/opds/src/main/java/org/readium/r2/opds/OPDS2Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
package org.readium.r2.opds

import java.net.URL
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.then
import org.joda.time.DateTime
import org.json.JSONArray
import org.json.JSONObject
Expand Down Expand Up @@ -53,29 +51,6 @@ class OPDS2Parser {
}
}

@Deprecated(
"Use `parseRequest` or `parseUrlString` with coroutines instead",
ReplaceWith("OPDS2Parser.parseUrlString(url)"),
DeprecationLevel.WARNING
)
fun parseURL(url: URL): Promise<ParseData, Exception> {
return DefaultHttpClient().fetchPromise(HttpRequest(url.toString())) then {
this.parse(it.body, url)
}
}

@Deprecated(
"Use `parseRequest` or `parseUrlString` with coroutines instead",
ReplaceWith("OPDS2Parser.parseUrlString(url)"),
DeprecationLevel.WARNING
)
@Suppress("unused")
fun parseURL(headers: MutableMap<String, String>, url: URL): Promise<ParseData, Exception> {
return DefaultHttpClient().fetchPromise(HttpRequest(url = url.toString(), headers = headers)) then {
this.parse(it.body, url)
}
}

fun parse(jsonData: ByteArray, url: URL): ParseData {
return if (isFeed(jsonData)) {
ParseData(parseFeed(jsonData, url), null, 2)
Expand Down
8 changes: 0 additions & 8 deletions readium/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,8 @@ apply(from = "$rootDir/scripts/publish-module.gradle")
dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.browser)
implementation("com.github.kittinunf.fuel:fuel-android:2.3.1")
implementation("com.github.kittinunf.fuel:fuel:2.3.1")
implementation(libs.timber)
implementation(libs.joda.time)
implementation("nl.komponents.kovenant:kovenant-android:3.3.0")
implementation("nl.komponents.kovenant:kovenant-combine:3.3.0")
implementation("nl.komponents.kovenant:kovenant-core:3.3.0")
implementation("nl.komponents.kovenant:kovenant-functional:3.3.0")
implementation("nl.komponents.kovenant:kovenant-jvm:3.3.0")
implementation("nl.komponents.kovenant:kovenant:3.3.0")
implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.json)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.readium.r2.shared.format

import com.github.kittinunf.fuel.core.Response
import java.net.HttpURLConnection
import org.readium.r2.shared.util.mediatype.MediaType as NewMediaType
import org.readium.r2.shared.util.mediatype.Sniffer
Expand All @@ -25,14 +24,6 @@ typealias FormatSniffers = Sniffers
@Deprecated("Renamed SnifferContext", replaceWith = ReplaceWith("org.readium.r2.shared.util.mediatype.SnifferContext"), level = DeprecationLevel.ERROR)
typealias FormatSnifferContext = SnifferContext

@Deprecated("Renamed to another package", ReplaceWith("org.readium.r2.shared.util.mediatype.sniffMediaType"), level = DeprecationLevel.ERROR)
suspend fun Response.sniffFormat(
mediaTypes: List<String> = emptyList(),
fileExtensions: List<String> = emptyList(),
sniffers: List<Sniffer> = NewMediaType.sniffers
): NewMediaType? =
sniffMediaType(mediaTypes, fileExtensions, sniffers)

@Deprecated("Renamed to another package", ReplaceWith("org.readium.r2.shared.util.mediatype.sniffMediaType"), level = DeprecationLevel.ERROR)
suspend fun HttpURLConnection.sniffFormat(
bytes: (() -> ByteArray)? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.readium.r2.shared.util.mediatype

import com.github.kittinunf.fuel.core.Response
import java.net.HttpURLConnection
import org.readium.r2.shared.extensions.extension

Expand Down Expand Up @@ -41,28 +40,3 @@ suspend fun HttpURLConnection.sniffMediaType(
MediaType.of(mediaTypes = allMediaTypes, fileExtensions = allFileExtensions, sniffers = sniffers)
}
}

/**
* Resolves the format for this [Response], with optional extra file extension and media type
* hints.
*/
suspend fun Response.sniffMediaType(
mediaTypes: List<String> = emptyList(),
fileExtensions: List<String> = emptyList(),
sniffers: List<Sniffer> = MediaType.sniffers
): MediaType? {
val allMediaTypes = mediaTypes.toMutableList()
val allFileExtensions = fileExtensions.toMutableList()

// The value of the `Content-Type` HTTP header.
allMediaTypes.addAll(0, headers["Content-Type"])

// The URL file extension.
url.extension?.let {
allFileExtensions.add(0, it)
}

// TODO: The suggested filename extension, part of the HTTP header `Content-Disposition`.

return MediaType.ofBytes({ data }, mediaTypes = allMediaTypes, fileExtensions = allFileExtensions, sniffers = sniffers)
}
Loading