forked from kittinunf/fuel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fuel-core] Integate Stetho (kittinunf#571)
* Integate Stetho * Added DefaultHook for no-op
- Loading branch information
1 parent
8b5553a
commit a2c22d3
Showing
18 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dependencies { | ||
api(project(":fuel")) | ||
implementation(Kotlin.stdlib) | ||
implementation(Stetho.plugin) | ||
implementation(Stetho.StethoUrlConnection.plugin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle.kts. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.github.kittinunf.fuel.stetho" /> |
28 changes: 28 additions & 0 deletions
28
fuel-stetho/src/main/java/com/kittinunf/fuel/stetho/StethoHook.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.kittinunf.fuel.stetho | ||
|
||
import com.facebook.stetho.urlconnection.ByteArrayRequestEntity | ||
import com.facebook.stetho.urlconnection.StethoURLConnectionManager | ||
import com.github.kittinunf.fuel.core.Request | ||
import com.github.kittinunf.fuel.core.Client | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.net.HttpURLConnection | ||
|
||
class StethoHook(val friendlyName: String = "StethoFuelConnectionManager") : Client.Hook { | ||
val stetho = StethoURLConnectionManager(friendlyName) | ||
|
||
override fun preConnect(connection: HttpURLConnection, request: Request) { | ||
stetho.preConnect(connection, ByteArrayRequestEntity(request.body.toByteArray())) | ||
} | ||
|
||
override fun interpretResponseStream(inputStream: InputStream): InputStream = | ||
stetho.interpretResponseStream(inputStream) | ||
|
||
override fun postConnect() { | ||
stetho.postConnect() | ||
} | ||
|
||
override fun httpExchangeFailed(exception: IOException) { | ||
stetho.httpExchangeFailed(exception) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">fuel-stetho</string> | ||
</resources> |
11 changes: 11 additions & 0 deletions
11
fuel/src/main/kotlin/com/github/kittinunf/fuel/core/Client.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package com.github.kittinunf.fuel.core | ||
|
||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.net.HttpURLConnection | ||
|
||
interface Client { | ||
fun executeRequest(request: Request): Response | ||
suspend fun awaitRequest(request: Request): Response = executeRequest(request) | ||
|
||
interface Hook { | ||
fun preConnect(connection: HttpURLConnection, request: Request) | ||
fun interpretResponseStream(inputStream: InputStream): InputStream | ||
fun postConnect() | ||
fun httpExchangeFailed(exception: IOException) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
fuel/src/main/kotlin/com/github/kittinunf/fuel/core/DefaultHook.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.kittinunf.fuel.core | ||
|
||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.net.HttpURLConnection | ||
|
||
internal class DefaultHook : Client.Hook { | ||
override fun preConnect(connection: HttpURLConnection, request: Request) { | ||
// no-op | ||
} | ||
|
||
override fun interpretResponseStream(inputStream: InputStream): InputStream = inputStream | ||
|
||
override fun postConnect() { | ||
// no-op | ||
} | ||
|
||
override fun httpExchangeFailed(exception: IOException) { | ||
// no-op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
sample/src/main/kotlin/com/example/fuel/SampleApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.fuel | ||
|
||
import android.app.Application | ||
import com.facebook.stetho.Stetho | ||
|
||
class SampleApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
Stetho.initializeWithDefaults(this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters