Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 08b0dbc

Browse files
committed
prepare 0.6.1
1 parent f143b2d commit 08b0dbc

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unrelease
8+
9+
## [0.6.1] - 2020-10-23
810
### Added
911
- dynamic context in the main suspend methods
1012
- error code for missing read url
1113

14+
### Changed
15+
- updated okhttp dependency from 3.13 to 4.9
16+
1217
## [0.6.0] - 2020-10-13
1318
### Added
1419
- additional parameters `sendToSignIn`, `appDetails` for `BlockstackSignIn`

blockstack-sdk/src/main/java/org/blockstack/android/sdk/BlockstackSession.kt

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import kotlinx.coroutines.CoroutineDispatcher
77
import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.withContext
99
import me.uport.sdk.core.hexToByteArray
10-
import okhttp3.*
10+
import okhttp3.Call
1111
import okhttp3.MediaType.Companion.toMediaType
12-
import okio.ByteString
12+
import okhttp3.OkHttpClient
13+
import okhttp3.Request
14+
import okhttp3.RequestBody
15+
import okhttp3.RequestBody.Companion.toRequestBody
1316
import okio.ByteString.Companion.encodeUtf8
1417
import okio.ByteString.Companion.toByteString
1518
import org.blockstack.android.sdk.ecies.signContent
@@ -23,7 +26,6 @@ import org.kethereum.model.ECKeyPair
2326
import org.kethereum.model.PrivateKey
2427
import org.kethereum.model.PublicKey
2528
import org.komputing.khash.sha256.extensions.sha256
26-
import org.komputing.khex.extensions.hexToByteArray
2729
import org.komputing.khex.model.HexString
2830
import java.io.IOException
2931
import java.math.BigInteger
@@ -82,7 +84,7 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
8284

8385
val userData = authResponseToUserData(tokenPayload, nameLookupUrl, appPrivateKey, coreSessionToken, authResponse)
8486

85-
this@BlockstackSession.appPrivateKey = appPrivateKey
87+
this@BlockstackSession.appPrivateKey = appPrivateKey
8688
sessionStore.updateUserData(userData)
8789

8890
return@withContext Result(userData)
@@ -333,7 +335,7 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
333335
* @property a result object wiht a `String` representation of a url from
334336
* which you can read the file that was just put.
335337
*/
336-
suspend fun putFile(path: String, content: Any, options: PutFileOptions): Result<out String> = withContext(dispatcher){
338+
suspend fun putFile(path: String, content: Any, options: PutFileOptions): Result<out String> = withContext(dispatcher) {
337339
Log.d(TAG, "putFile: path: ${path} options: ${options}")
338340
val gaiaHubConfiguration = getOrSetLocalGaiaHubConnection()
339341
val valid = content is String || content is ByteArray
@@ -379,35 +381,35 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
379381
}
380382

381383

382-
try {
383-
val response = hub.uploadToGaiaHub(path, requestContent, gaiaHubConfiguration, contentType)
384-
if (!response.isSuccessful) {
385-
return@withContext Result(null, ResultError(ErrorCode.NetworkError, "upload to gaia failed: ${response.code}", response.code.toString()))
386-
}
387-
val responseText = response.body?.string()
388-
if (responseText !== null) {
389-
if (!options.shouldEncrypt() && options.shouldSign()) {
390-
val signedContent = signContent(requestContent.toByteArray(), getSignKey(options))
391-
try {
392-
val sigResponse = hub.uploadToGaiaHub("$path$SIGNATURE_FILE_EXTENSION", signedContent.toJSONByteString(), gaiaHubConfig!!, "application/json")
393-
if (!sigResponse.isSuccessful) {
394-
return@withContext Result(null, ResultError(ErrorCode.NetworkError, "failed to upload putFile signature $responseText", sigResponse.code.toString()))
395-
}
396-
} catch (e: Exception) {
397-
return@withContext Result(null, ResultError(ErrorCode.UnknownError, "invalid response from putFile signature $responseText"))
384+
try {
385+
val response = hub.uploadToGaiaHub(path, requestContent, gaiaHubConfiguration, contentType)
386+
if (!response.isSuccessful) {
387+
return@withContext Result(null, ResultError(ErrorCode.NetworkError, "upload to gaia failed: ${response.code}", response.code.toString()))
388+
}
389+
val responseText = response.body?.string()
390+
if (responseText !== null) {
391+
if (!options.shouldEncrypt() && options.shouldSign()) {
392+
val signedContent = signContent(requestContent.toByteArray(), getSignKey(options))
393+
try {
394+
val sigResponse = hub.uploadToGaiaHub("$path$SIGNATURE_FILE_EXTENSION", signedContent.toJSONByteString(), gaiaHubConfig!!, "application/json")
395+
if (!sigResponse.isSuccessful) {
396+
return@withContext Result(null, ResultError(ErrorCode.NetworkError, "failed to upload putFile signature $responseText", sigResponse.code.toString()))
398397
}
398+
} catch (e: Exception) {
399+
return@withContext Result(null, ResultError(ErrorCode.UnknownError, "invalid response from putFile signature $responseText"))
399400
}
400-
401-
val responseJSON = JSONObject(responseText)
402-
return@withContext Result(responseJSON.getString("publicURL"))
403-
} else {
404-
return@withContext Result(null, ResultError(ErrorCode.UnknownError, "invalid response from putFile $responseText"))
405401
}
406-
} catch (e: Exception) {
407-
Log.d(TAG, e.message, e)
408-
return@withContext Result(null, ResultError(ErrorCode.UnknownError, e.message
409-
?: e.toString()))
402+
403+
val responseJSON = JSONObject(responseText)
404+
return@withContext Result(responseJSON.getString("publicURL"))
405+
} else {
406+
return@withContext Result(null, ResultError(ErrorCode.UnknownError, "invalid response from putFile $responseText"))
410407
}
408+
} catch (e: Exception) {
409+
Log.d(TAG, e.message, e)
410+
return@withContext Result(null, ResultError(ErrorCode.UnknownError, e.message
411+
?: e.toString()))
412+
}
411413

412414

413415
}
@@ -440,7 +442,7 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
440442
}
441443

442444

443-
suspend fun deleteFile(path: String, options: DeleteFileOptions = DeleteFileOptions()): Result<out Unit> = withContext(dispatcher){
445+
suspend fun deleteFile(path: String, options: DeleteFileOptions = DeleteFileOptions()): Result<out Unit> = withContext(dispatcher) {
444446
try {
445447
val response = hub.deleteFromGaiaHub(path, options.gaiaHubConfig ?: gaiaHubConfig!!)
446448
if (response != null) {
@@ -492,7 +494,7 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
492494
hub.getFullReadUrl(path, gaiaHubConfig)
493495
}
494496

495-
return if (readUrl == Blockstack.NO_URL){
497+
return if (readUrl == Blockstack.NO_URL) {
496498
Result(value = null, error = ResultError(ErrorCode.MissingReadUrl, "${options.username} has not yet used the app"))
497499
} else {
498500
Result(readUrl)
@@ -559,7 +561,7 @@ class BlockstackSession(private val sessionStore: ISessionStore, private val app
559561
.addHeader("Authorization", "bearer ${hubConfig.token}")
560562
.addHeader("Referrer-Policy", "no-referrer")
561563

562-
.method("POST", RequestBody.create(CONTENT_TYPE_JSON.toMediaType(), pageRequest))
564+
.method("POST", pageRequest.toRequestBody(CONTENT_TYPE_JSON.toMediaType()))
563565
.build()
564566
}
565567

blockstack-sdk/src/main/java/org/blockstack/android/sdk/model/Hub.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import me.uport.sdk.jwt.model.JwtHeader
1212
import me.uport.sdk.signer.KPSigner
1313
import okhttp3.*
1414
import okhttp3.MediaType.Companion.toMediaType
15+
import okhttp3.RequestBody.Companion.toRequestBody
1516
import okio.ByteString
1617
import org.blockstack.android.sdk.BlockstackSession
1718
import org.blockstack.android.sdk.toBtcAddress
@@ -125,7 +126,7 @@ class Hub(val callFactory: Call.Factory = OkHttpClient()) {
125126

126127
val builder = Request.Builder()
127128
.url(url)
128-
builder.method("POST", RequestBody.create(contentType.toMediaType(), content))
129+
builder.method("POST", content.toRequestBody(contentType.toMediaType()))
129130
builder.addHeader("Content-Type", contentType)
130131
builder.addHeader("Authorization", "bearer ${hubConfig.token}")
131132
builder.addHeader("Referrer-Policy", "no-referrer")

0 commit comments

Comments
 (0)