Skip to content

Commit

Permalink
Merge pull request #33 from yoavst/master
Browse files Browse the repository at this point in the history
Non android support
  • Loading branch information
Kittinun committed Nov 3, 2015
2 parents 6c83b4d + 58e9203 commit c8625b2
Show file tree
Hide file tree
Showing 15 changed files with 813 additions and 170 deletions.
40 changes: 7 additions & 33 deletions fuel/build.gradle
Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin'

repositories {

jcenter()

}

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "0.57"
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
abortOnError false
}

}

dependencies {

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testCompile "junit:junit:$junit_version"
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile "org.robolectric:robolectric:$robolectric_version"
testCompile "com.google.android:android:4.1.1.4"
}

buildscript {
Expand All @@ -61,5 +30,10 @@ buildscript {
}
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

//apply from: '../gradle/install.gradle'
//apply from: '../gradle/bintray.gradle'
6 changes: 3 additions & 3 deletions fuel/src/main/kotlin/fuel/core/Deserializable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ public interface ResponseDeserializable<out T : Any> : Deserializable<T> {

}

internal fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U, handler: (Request, Response, Either<FuelError, T>) -> Unit) {
fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U, handler: (Request, Response, Either<FuelError, T>) -> Unit) {
response(deserializable, { request, response, value ->
handler(this@response, response, Either.Right(value))
}, { request, response, error ->
handler(this@response, response, Either.Left(error))
})
}

internal fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U, handler: Handler<T>) {
fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U, handler: Handler<T>) {
response(deserializable, { request, response, value ->
handler.success(request, response, value)
}, { request, response, error ->
handler.failure(request, response, error)
})
}

internal fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U,
private fun <T: Any, U : Deserializable<T>> Request.response(deserializable: U,
success: (Request, Response, T) -> Unit,
failure: (Request, Response, FuelError) -> Unit) {
taskRequest.apply {
Expand Down
10 changes: 9 additions & 1 deletion fuel/src/main/kotlin/fuel/core/Either.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ sealed public class Either<out L, out R> {
public operator abstract fun component1(): L?
public operator abstract fun component2(): R?

public fun fold(fl: (L) -> Unit, fr: (R) -> Unit) {
public inline fun fold(fl: (L) -> Unit, fr: (R) -> Unit) {
return when (this) {
is Left<L, R> -> fl(this.left)
is Right<L, R> -> fr(this.right)
else -> throw UnsupportedOperationException()
}
}

public inline fun left(fl: (L) -> Unit) {
if (this is Left<L, R>) fl(this.left)
}

public inline fun right(fr: (R) -> Unit) {
if (this is Right<L, R>) fr(this.right)
}

public fun swap(): Either<R, L> {
return when (this) {
is Left<L, R> -> Right(this.left)
Expand Down
4 changes: 2 additions & 2 deletions fuel/src/main/kotlin/fuel/core/Encoding.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fuel.core

import android.net.Uri
import fuel.Fuel
import fuel.util.toHexString
import java.net.URI
import java.net.URL
import java.net.URLEncoder
import kotlin.properties.Delegates
Expand Down Expand Up @@ -58,7 +58,7 @@ public class Encoding : Fuel.RequestConvertible {
override val request by lazy { encoder(httpMethod, urlString, parameters) }

private fun createUrl(path: String): URL {
val pathUri = Uri.parse(path)
val pathUri = URI(path)
//give precedence to local path
if (baseUrlString == null || pathUri.scheme != null) return URL(path)

Expand Down
4 changes: 2 additions & 2 deletions fuel/src/main/kotlin/fuel/core/Manager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fuel.core

import fuel.Fuel
import fuel.toolbox.HttpClient
import fuel.util.AndroidMainThreadExecutor
import fuel.util.DefaultExecutor
import fuel.util.readWriteLazy
import java.util.concurrent.Executor
import java.util.concurrent.ExecutorService
Expand Down Expand Up @@ -31,7 +31,7 @@ public class Manager {
}

//callback executor
public var callbackExecutor: Executor by readWriteLazy { AndroidMainThreadExecutor() }
public var callbackExecutor: Executor by readWriteLazy { DefaultExecutor() }

companion object {

Expand Down
25 changes: 3 additions & 22 deletions fuel/src/main/kotlin/fuel/core/Request.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package fuel.core

import android.util.Base64
import fuel.util.copyTo
import fuel.util.readWriteLazy
import fuel.util.toHexString
import org.json.JSONObject
import fuel.util.*
import java.io.*
import java.net.URL
import java.net.URLConnection
Expand Down Expand Up @@ -73,15 +69,6 @@ public class Request {
}
}
}

public fun jsonDeserializer(): Deserializable<JSONObject> {
return object : Deserializable<JSONObject> {
override fun deserialize(response: Response): JSONObject {
return JSONObject(String(response.data))
}
}
}

}

//interfaces
Expand Down Expand Up @@ -181,16 +168,10 @@ public class Request {

public fun responseString(handler: Handler<String>): Unit = response(Request.stringDeserializer(), handler)

//jsonObject
public fun responseJson(handler: (Request, Response, Either<FuelError, JSONObject>) -> Unit): Unit =
response(Request.jsonDeserializer(), handler)

public fun responseJson(handler: Handler<JSONObject>): Unit = response(Request.jsonDeserializer(), handler)

//object
public fun <T: Any> responseObject(deserializer: ResponseDeserializable<T>, handler: (Request, Response, Either<FuelError, T>) -> Unit): Unit = response(deserializer, handler)
public fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: (Request, Response, Either<FuelError, T>) -> Unit): Unit = response(deserializer, handler)

public fun <T: Any> responseObject(deserializer: ResponseDeserializable<T>, handler: Handler<T>): Unit = response(deserializer, handler)
public fun <T : Any> responseObject(deserializer: ResponseDeserializable<T>, handler: Handler<T>): Unit = response(deserializer, handler)

public fun cUrlString(): String {
val elements = arrayListOf("$ curl -i")
Expand Down
19 changes: 0 additions & 19 deletions fuel/src/main/kotlin/fuel/util/AndroidMainThreadExecutor.kt

This file was deleted.

Loading

0 comments on commit c8625b2

Please sign in to comment.