pull/32/head
parent
eea048dc70
commit
8dca2c885e
@ -1,27 +0,0 @@ |
|||||||
package io.legado.app.data.api; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import kotlinx.coroutines.Deferred; |
|
||||||
import retrofit2.Response; |
|
||||||
import retrofit2.http.GET; |
|
||||||
import retrofit2.http.HeaderMap; |
|
||||||
import retrofit2.http.QueryMap; |
|
||||||
import retrofit2.http.Url; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by GKF on 2018/1/21. |
|
||||||
* get web content |
|
||||||
*/ |
|
||||||
|
|
||||||
public interface IHttpGetApi { |
|
||||||
@GET |
|
||||||
Deferred<Response<String>> get(@Url String url, |
|
||||||
@HeaderMap Map<String, String> headers); |
|
||||||
|
|
||||||
@GET |
|
||||||
Deferred<Response<String>> getMap(@Url String url, |
|
||||||
@QueryMap(encoded = true) Map<String, String> queryMap, |
|
||||||
@HeaderMap Map<String, String> headers); |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,29 @@ |
|||||||
|
package io.legado.app.data.api |
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred |
||||||
|
import retrofit2.Response |
||||||
|
import retrofit2.http.GET |
||||||
|
import retrofit2.http.HeaderMap |
||||||
|
import retrofit2.http.QueryMap |
||||||
|
import retrofit2.http.Url |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by GKF on 2018/1/21. |
||||||
|
* get web content |
||||||
|
*/ |
||||||
|
|
||||||
|
interface IHttpGetApi { |
||||||
|
@GET |
||||||
|
operator fun get( |
||||||
|
@Url url: String, |
||||||
|
@HeaderMap headers: Map<String, String> |
||||||
|
): Deferred<Response<String>> |
||||||
|
|
||||||
|
@GET |
||||||
|
fun getMap( |
||||||
|
@Url url: String, |
||||||
|
@QueryMap(encoded = true) queryMap: Map<String, String>, |
||||||
|
@HeaderMap headers: Map<String, String> |
||||||
|
): Deferred<Response<String>> |
||||||
|
|
||||||
|
} |
@ -1,32 +0,0 @@ |
|||||||
package io.legado.app.data.api; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import kotlinx.coroutines.Deferred; |
|
||||||
import okhttp3.RequestBody; |
|
||||||
import retrofit2.Response; |
|
||||||
import retrofit2.http.Body; |
|
||||||
import retrofit2.http.FieldMap; |
|
||||||
import retrofit2.http.FormUrlEncoded; |
|
||||||
import retrofit2.http.HeaderMap; |
|
||||||
import retrofit2.http.POST; |
|
||||||
import retrofit2.http.Url; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by GKF on 2018/1/29. |
|
||||||
* post |
|
||||||
*/ |
|
||||||
|
|
||||||
public interface IHttpPostApi { |
|
||||||
|
|
||||||
@FormUrlEncoded |
|
||||||
@POST |
|
||||||
Deferred<Response<String>> postMap(@Url String url, |
|
||||||
@FieldMap(encoded = true) Map<String, String> fieldMap, |
|
||||||
@HeaderMap Map<String, String> headers); |
|
||||||
|
|
||||||
@POST |
|
||||||
Deferred<Response<String>> postBody(@Url String url, |
|
||||||
@Body RequestBody body, |
|
||||||
@HeaderMap Map<String, String> headers); |
|
||||||
} |
|
@ -0,0 +1,29 @@ |
|||||||
|
package io.legado.app.data.api |
||||||
|
|
||||||
|
import kotlinx.coroutines.Deferred |
||||||
|
import okhttp3.RequestBody |
||||||
|
import retrofit2.Response |
||||||
|
import retrofit2.http.* |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by GKF on 2018/1/29. |
||||||
|
* post |
||||||
|
*/ |
||||||
|
|
||||||
|
interface IHttpPostApi { |
||||||
|
|
||||||
|
@FormUrlEncoded |
||||||
|
@POST |
||||||
|
fun postMap( |
||||||
|
@Url url: String, |
||||||
|
@FieldMap(encoded = true) fieldMap: Map<String, String>, |
||||||
|
@HeaderMap headers: Map<String, String> |
||||||
|
): Deferred<Response<String>> |
||||||
|
|
||||||
|
@POST |
||||||
|
fun postBody( |
||||||
|
@Url url: String, |
||||||
|
@Body body: RequestBody, |
||||||
|
@HeaderMap headers: Map<String, String> |
||||||
|
): Deferred<Response<String>> |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package io.legado.app.model |
||||||
|
|
||||||
|
import io.legado.app.data.api.IHttpGetApi |
||||||
|
import io.legado.app.data.api.IHttpPostApi |
||||||
|
import io.legado.app.data.entities.BookSource |
||||||
|
import io.legado.app.help.http.HttpHelper |
||||||
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
||||||
|
import kotlinx.coroutines.CoroutineScope |
||||||
|
import kotlinx.coroutines.Dispatchers.IO |
||||||
|
import kotlinx.coroutines.MainScope |
||||||
|
import kotlinx.coroutines.launch |
||||||
|
|
||||||
|
class WebBook(val bookSource: BookSource) : CoroutineScope by MainScope() { |
||||||
|
|
||||||
|
fun searchBook(key: String, page: Int?, success: (() -> Unit), error: (() -> Unit)) { |
||||||
|
launch(IO) { |
||||||
|
val searchRule = bookSource.getSearchRule() |
||||||
|
searchRule?.searchUrl?.let { searchUrl -> |
||||||
|
val analyzeUrl = AnalyzeUrl(searchUrl) |
||||||
|
val res = when { |
||||||
|
analyzeUrl.method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService<IHttpPostApi>( |
||||||
|
analyzeUrl.baseUrl |
||||||
|
).postBody( |
||||||
|
analyzeUrl.url, |
||||||
|
analyzeUrl.body, |
||||||
|
analyzeUrl.headerMap |
||||||
|
).await() |
||||||
|
analyzeUrl.fieldMap.isEmpty() -> HttpHelper.getApiService<IHttpGetApi>( |
||||||
|
analyzeUrl.baseUrl |
||||||
|
)[analyzeUrl.url, analyzeUrl.headerMap].await() |
||||||
|
else -> HttpHelper.getApiService<IHttpGetApi>(analyzeUrl.baseUrl) |
||||||
|
.getMap(analyzeUrl.url, analyzeUrl.fieldMap, analyzeUrl.headerMap).await() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,6 +0,0 @@ |
|||||||
package io.legado.app.model.book |
|
||||||
|
|
||||||
class All { |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
package io.legado.app.model.book |
|
||||||
|
|
||||||
class BookChapterList { |
|
||||||
|
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
package io.legado.app.model.book |
|
||||||
|
|
||||||
class BookContent { |
|
||||||
|
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
package io.legado.app.model.book |
|
||||||
|
|
||||||
class BookInfo { |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,5 @@ |
|||||||
|
package io.legado.app.model.webbook |
||||||
|
|
||||||
|
class BookChapterList { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package io.legado.app.model.webbook |
||||||
|
|
||||||
|
class BookContent { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package io.legado.app.model.webbook |
||||||
|
|
||||||
|
class BookInfo { |
||||||
|
|
||||||
|
} |
@ -1,4 +1,4 @@ |
|||||||
package io.legado.app.model.book |
package io.legado.app.model.webbook |
||||||
|
|
||||||
import io.legado.app.data.entities.SearchBook |
import io.legado.app.data.entities.SearchBook |
||||||
|
|
Loading…
Reference in new issue