mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Remote Retrofit 1.9.
This commit is contained in:
parent
27a613c8bb
commit
7798fb02b9
6 changed files with 15 additions and 20 deletions
|
@ -4,12 +4,14 @@ import com.beust.kobalt.KobaltException
|
|||
import com.beust.kobalt.misc.CountingFileRequestBody
|
||||
import com.beust.kobalt.misc.log
|
||||
import okhttp3.*
|
||||
import retrofit.mime.TypedFile
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Http {
|
||||
class TypedFile(val mimeType: String, val file: File)
|
||||
|
||||
fun get(user: String?, password: String?, url: String) : Response {
|
||||
val client = OkHttpClient()
|
||||
val request = Request.Builder().url(url)
|
||||
|
@ -47,7 +49,7 @@ class Http {
|
|||
error: (Response) -> Unit = DEFAULT_ERROR_RESPONSE) {
|
||||
|
||||
val fullHeaders = Headers.Builder()
|
||||
fullHeaders.set("Content-Type", file.mimeType())
|
||||
fullHeaders.set("Content-Type", file.mimeType)
|
||||
headers.names().forEach { fullHeaders.set(it, headers.get(it)) }
|
||||
|
||||
user?.let {
|
||||
|
@ -59,9 +61,9 @@ class Http {
|
|||
.url(url)
|
||||
val request =
|
||||
(if (post)
|
||||
requestBuilder.post(CountingFileRequestBody(file.file(), file.mimeType(), progressCallback))
|
||||
requestBuilder.post(CountingFileRequestBody(file.file, file.mimeType, progressCallback))
|
||||
else
|
||||
requestBuilder.put(CountingFileRequestBody(file.file(), file.mimeType(), progressCallback)))
|
||||
requestBuilder.put(CountingFileRequestBody(file.file, file.mimeType, progressCallback)))
|
||||
.build()
|
||||
|
||||
log(2, "Uploading $file to $url")
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.beust.kobalt.internal.DocUrl
|
|||
import com.beust.kobalt.maven.Http
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.google.inject.Inject
|
||||
import retrofit.RetrofitError
|
||||
import retrofit.mime.TypedFile
|
||||
import retrofit2.Call
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
@ -73,13 +71,13 @@ class GithubApi2 @Inject constructor(
|
|||
.execute()
|
||||
.body()
|
||||
|
||||
uploadAsset(accessToken, response.uploadUrl!!, TypedFile("application/zip", zipFile),
|
||||
uploadAsset(accessToken, response.uploadUrl!!, Http.TypedFile("application/zip", zipFile),
|
||||
tagName)
|
||||
.toBlocking()
|
||||
.forEach { action ->
|
||||
log(1, "\n${zipFile.name} successfully uploaded")
|
||||
}
|
||||
} catch(e: RetrofitError) {
|
||||
} catch(e: Exception) {
|
||||
throw KobaltException("Couldn't upload release: " + e.message, e)
|
||||
// val error = parseRetrofitError(e)
|
||||
// throw KobaltException("Couldn't upload release, ${error.message}: "
|
||||
|
@ -87,13 +85,13 @@ class GithubApi2 @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun uploadAsset(token: String, uploadUrl: String, typedFile: TypedFile, tagName: String)
|
||||
private fun uploadAsset(token: String, uploadUrl: String, typedFile: Http.TypedFile, tagName: String)
|
||||
: Observable<UploadAssetResponse> {
|
||||
val strippedUrl = uploadUrl.substring(0, uploadUrl.indexOf("{"))
|
||||
val fileName = typedFile.file().name
|
||||
val fileName = typedFile.file.name
|
||||
val url = "$strippedUrl?name=$fileName&label=$fileName"
|
||||
val headers = okhttp3.Headers.of("Authorization", "token $token")
|
||||
val totalSize = typedFile.file().length()
|
||||
val totalSize = typedFile.file.length()
|
||||
http.uploadFile(url = url, file = typedFile, headers = headers, post = true, // Github requires POST
|
||||
progressCallback = http.percentProgressCallback(totalSize))
|
||||
|
||||
|
@ -123,7 +121,7 @@ class GithubApi2 @Inject constructor(
|
|||
throw KobaltException("Couldn't find the latest release")
|
||||
}
|
||||
}
|
||||
} catch(e: RetrofitError) {
|
||||
} catch(e: Exception) {
|
||||
log(1, "Couldn't retrieve releases from github: " + e.message)
|
||||
e.printStackTrace()
|
||||
// val error = parseRetrofitError(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue