-
Notifications
You must be signed in to change notification settings - Fork 9
Add new functions that use HttpRequest and Try to eventually replace Fuel and Promises #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a stab at this! 🚀
@@ -45,13 +49,43 @@ object Namespaces { | |||
class OPDS1Parser { | |||
companion object { | |||
|
|||
suspend fun parseUrlString(url: String): Try<ParseData, Exception> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be interesting to take a client
argument to let the app provide its own implementation if necessary.
Also an additional parseRequest()
API taking directly an HttpRequest
would let the app customize the HTTP headers, timeouts and other settings without a custom HttpClient
. This way we don't need to provide parseUrlString(url: String, headers: MutableMap<String, String>)
.
suspend fun parseUrlString(url: String): Try<ParseData, Exception> { | |
suspend fun parseUrlString(url: String, client: HttpClient = DefaultHttpClient()): Try<ParseData, Exception> { | |
... | |
} | |
suspend fun parseRequest(request: HttpRequest, client: HttpClient = DefaultHttpClient()) ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can actually just have one function in that case: Accepts a URL as a string, and accepts an HttpClient with the default being DefaultHttpClient. And parseRequest
sounds better than parseUrlString
.
I wonder why you want to make HTTP requests inside a parser... Am I missing something? |
That's a good point. Down the line, I'd like to offer a more high-level API which would handle:
Some of these will need control over the HTTP requests. But for this PR, I think the goal is mostly to keep feature parity with the existing implementation while deprecating Fuel and kovenant. |
Yeah, this PR was about replacing Kovenant and Fuel. I just realized that the old functions that still use Fuel can actually use the new Http service, as long as they still use Kovenant to return a Promise. That will at least remove the need for Fuel though. |
- Add an optional HttpClient to each new function - Add a new function that accepts a HttpRequest - Replace existing functions using Fuel to use new Http
@mickael-menu made the suggested changes. |
Thanks @stevenzeck! |
This PR creates new functions that use the DefaultHttpClient and Try to eventually replace the existing ones that use Fuel and Promises.
parseUrlString
functions are the replacements for theparseURL
ones (applicable to OPDS1Parser and OPDS2Parser)retrieveOpenSearchTemplate
is the replacement forfetchOpenSearchTemplate
(OPDS1Parser)parseURL
andfetchOpenSearchTemplate
are both marked as deprecated with a warning (both)parseRequest
, that accepts an HttpRequest and an optional HttpClientI took the liberty of naming the new functions, but feel free to change them.