Skip to content

Commit

Permalink
Merge pull request #15 from kittinunf/0.51
Browse files Browse the repository at this point in the history
0.51
  • Loading branch information
Kittinun committed Aug 11, 2015
2 parents da30487 + 8745961 commit 59dfee3
Show file tree
Hide file tree
Showing 22 changed files with 946 additions and 302 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ buildscript {
}
dependencies {
compile 'fuel:fuel:0.5'
compile 'fuel:fuel:0.51'
}
```

Expand Down Expand Up @@ -108,6 +108,11 @@ Fuel.get("http://httpbin.org/get").response { request, response, either ->
``` Kotlin
Fuel.post("http://httpbin.org/post").response { request, response, either ->

}

//if you have body to post manually
Fuel.post("http://httpbin.org/post").body("{ \"foo\" : \"bar\" }").response { request, response, either ->

}
```

Expand Down
17 changes: 8 additions & 9 deletions fuel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ android {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "0.5"
versionName "0.51"
}

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

buildTypes {
Expand All @@ -33,24 +33,23 @@ android {
abortOnError false
}

testOptions {
unitTests.returnDefaultValues = true
}
}

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"
}

buildscript {
ext {
//dependencies version
kotlin_version = '0.12.613'
kotlin_version = '0.12.1230'
junit_version = '4.12'
robolectric_version = '3.0'
}

repositories {
Expand All @@ -62,5 +61,5 @@ buildscript {
}
}

//apply from: '../gradle/install.gradle'
//apply from: '../gradle/bintray.gradle'
apply from: '../gradle/install.gradle'
apply from: '../gradle/bintray.gradle'
89 changes: 57 additions & 32 deletions fuel/src/main/kotlin/fuel/Fuel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,120 +23,145 @@ public class Fuel {

//convenience methods
//get
platformStatic jvmOverloads public fun get(path: String, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun get(path: String, parameters: Map<String, Any?>? = null): Request {
return request(Method.GET, path, parameters)
}

platformStatic jvmOverloads public fun get(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun get(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return request(Method.GET, convertible, parameters)
}

//post
platformStatic jvmOverloads public fun post(path: String, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun post(path: String, parameters: Map<String, Any?>? = null): Request {
return request(Method.POST, path, parameters)
}

platformStatic jvmOverloads public fun post(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun post(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return request(Method.POST, convertible, parameters)
}

//put
platformStatic jvmOverloads public fun put(path: String, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun put(path: String, parameters: Map<String, Any?>? = null): Request {
return request(Method.PUT, path, parameters)
}

platformStatic jvmOverloads public fun put(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun put(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return request(Method.PUT, convertible, parameters)
}

//delete
platformStatic jvmOverloads public fun delete(path: String, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun delete(path: String, parameters: Map<String, Any?>? = null): Request {
return request(Method.DELETE, path, parameters)
}

platformStatic jvmOverloads public fun delete(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
platformStatic jvmOverloads
public fun delete(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return request(Method.DELETE, convertible, parameters)
}

//download
platformStatic jvmOverloads public fun download(path: String, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.download(path, parameters)
platformStatic jvmOverloads
public fun download(path: String, parameters: Map<String, Any?>? = null): Request {
return Manager.instance.download(path, parameters)
}

platformStatic jvmOverloads public fun download(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.download(convertible, parameters)
platformStatic jvmOverloads
public fun download(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return Manager.instance.download(convertible, parameters)
}

//upload
platformStatic jvmOverloads public fun upload(path: String, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.upload(path, parameters)
platformStatic jvmOverloads
public fun upload(path: String, parameters: Map<String, Any?>? = null): Request {
return Manager.instance.upload(path, parameters)
}

platformStatic jvmOverloads public fun upload(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.upload(convertible, parameters)
platformStatic jvmOverloads
public fun upload(convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return Manager.instance.upload(convertible, parameters)
}

//request
private fun request(method: Method, path: String, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.request(method, path, parameters)
return Manager.instance.request(method, path, parameters)
}

private fun request(method: Method, convertible: PathStringConvertible, parameters: Map<String, Any?>? = null): Request {
return Manager.sharedInstance.request(method, convertible, parameters)
return Manager.instance.request(method, convertible, parameters)
}

platformStatic public fun request(convertible: RequestConvertible): Request {
return Manager.sharedInstance.request(convertible)
platformStatic
public fun request(convertible: RequestConvertible): Request {
return Manager.instance.request(convertible)
}

}

}

jvmOverloads public fun String.httpGet(parameters: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpGet(parameters: Map<String, Any?>? = null): Request {
return Fuel.get(this, parameters)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpGet(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpGet(parameter: Map<String, Any?>? = null): Request {
return Fuel.get(this, parameter)
}

jvmOverloads public fun String.httpPost(parameters: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpPost(parameters: Map<String, Any?>? = null): Request {
return Fuel.post(this, parameters)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpPost(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpPost(parameter: Map<String, Any?>? = null): Request {
return Fuel.post(this, parameter)
}

jvmOverloads public fun String.httpPut(parameters: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpPut(parameters: Map<String, Any?>? = null): Request {
return Fuel.put(this, parameters)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpPut(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpPut(parameter: Map<String, Any?>? = null): Request {
return Fuel.put(this, parameter)
}

jvmOverloads public fun String.httpDelete(parameters: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpDelete(parameters: Map<String, Any?>? = null): Request {
return Fuel.delete(this, parameters)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpDelete(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpDelete(parameter: Map<String, Any?>? = null): Request {
return Fuel.delete(this, parameter)
}

jvmOverloads public fun String.httpDownload(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpDownload(parameter: Map<String, Any?>? = null): Request {
return Fuel.download(this, parameter)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpDownload(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpDownload(parameter: Map<String, Any?>? = null): Request {
return Fuel.download(this, parameter)
}

jvmOverloads public fun String.httpUpload(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun String.httpUpload(parameter: Map<String, Any?>? = null): Request {
return Fuel.upload(this, parameter)
}

jvmOverloads public fun Fuel.PathStringConvertible.httpUpload(parameter: Map<String, Any?>? = null): Request {
jvmOverloads
public fun Fuel.PathStringConvertible.httpUpload(parameter: Map<String, Any?>? = null): Request {
return Fuel.upload(this, parameter)
}
9 changes: 5 additions & 4 deletions fuel/src/main/kotlin/fuel/core/FuelError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public class FuelError : Exception() {
var errorData = ByteArray(0)

override fun toString(): String {
return StringBuilder {
append(response.toString())
append("Exception : ${exception.getMessage()}\n")
}.toString()
val elements = arrayListOf(response.toString())
//exception
elements.add("Exception : ${exception.getMessage()}")
return elements.join("\n").toString()
}

}
Loading

0 comments on commit 59dfee3

Please sign in to comment.