-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customized HttpResponse Per Platforms (#863)
* HttResponse is now Expect/Actual class to make easier to adding more variables. * Oops * adding more files for Kotlinx Serializations * fixed Apple stuffs * JVM's HttpResponse for body is ResponseBody from OKHttp. * changing JVM Tests * remove empty space
- Loading branch information
Showing
19 changed files
with
113 additions
and
32 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
14 changes: 14 additions & 0 deletions
14
fuel-kotlinx-serialization/src/appleMain/kotlin/fuel/serialization/ResponseExtensions.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,14 @@ | ||
package fuel.serialization | ||
|
||
import com.github.kittinunf.result.Result | ||
import com.github.kittinunf.result.runCatching | ||
import fuel.HttpResponse | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.Json | ||
|
||
public fun <T : Any> HttpResponse.toJson( | ||
json: Json = Json { allowStructuredMapKeys = true }, | ||
deserializationStrategy: DeserializationStrategy<T> | ||
): Result<T?, Throwable> = runCatching { | ||
body?.let { json.decodeFromString(deserializationStrategy, it) } | ||
} |
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
fuel-kotlinx-serialization/src/jvmMain/kotlin/fuel/serialization/ResponseExtensions.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,14 @@ | ||
package fuel.serialization | ||
|
||
import com.github.kittinunf.result.Result | ||
import com.github.kittinunf.result.runCatching | ||
import fuel.HttpResponse | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.Json | ||
|
||
public fun <T : Any> HttpResponse.toJson( | ||
json: Json = Json { allowStructuredMapKeys = true }, | ||
deserializationStrategy: DeserializationStrategy<T> | ||
): Result<T?, Throwable> = runCatching { | ||
json.decodeFromString(deserializationStrategy, body.string()) | ||
} |
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,9 @@ | ||
package fuel | ||
|
||
import platform.Foundation.NSData | ||
|
||
public actual class HttpResponse { | ||
public var statusCode: Int = -1 | ||
public var nsData: NSData? = null | ||
public var body: String? = null | ||
} |
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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
package fuel | ||
|
||
public class HttpResponse { | ||
public var statusCode: Int = -1 | ||
public var body: String = "" | ||
} | ||
public expect class HttpResponse |
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 fuel | ||
|
||
import org.khronos.webgl.ArrayBuffer | ||
import org.w3c.files.Blob | ||
|
||
public actual class HttpResponse { | ||
public var statusCode: Int = -1 | ||
public lateinit var array: ArrayBuffer | ||
public var body: String = "" | ||
public lateinit var blob: Blob | ||
} |
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,8 @@ | ||
package fuel | ||
|
||
import okhttp3.ResponseBody | ||
|
||
public actual class HttpResponse { | ||
public var statusCode: Int = -1 | ||
public lateinit var body: ResponseBody | ||
} |
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