Skip to content

Commit c6ce214

Browse files
committed
Support to update userId
1 parent cd4e1dd commit c6ce214

File tree

3 files changed

+27
-50
lines changed

3 files changed

+27
-50
lines changed

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto+Login.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fun Pluto.resendValidationEmail(
7777
}
7878

7979
fun Pluto.loginWithAccount(
80-
address: String,
80+
account: String,
8181
password: String,
8282
success: (() -> Unit)? = null,
8383
error: ((PlutoError) -> Unit)? = null,
@@ -88,7 +88,7 @@ fun Pluto.loginWithAccount(
8888
error?.invoke(PlutoError.badRequest)
8989
return
9090
}
91-
plutoService.loginWithAccount(LoginWithAccountPostData(address, password, deviceId, appId))
91+
plutoService.loginWithAccount(LoginWithAccountPostData(account, password, deviceId, appId))
9292
.apply {
9393
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
9494
override fun onFailure(

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/Pluto+User.kt

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,55 +61,24 @@ fun Pluto.myInfo(
6161
)
6262
}
6363

64+
fun Pluto.updateUserId(
65+
userId: String,
66+
success: () -> Unit,
67+
error: ((PlutoError) -> Unit)? = null,
68+
handler: Pluto.PlutoRequestHandler? = null
69+
) {
70+
val postData = UpdateUserInfoPutData(null, null, userId)
71+
updateUserInfo(postData, success, error, handler)
72+
}
73+
6474
fun Pluto.updateName(
6575
name: String,
6676
success: () -> Unit,
6777
error: ((PlutoError) -> Unit)? = null,
6878
handler: Pluto.PlutoRequestHandler? = null
6979
) {
70-
getAuthorizationHeader(
71-
completion = { header ->
72-
if (header == null) {
73-
handler?.setCall(null)
74-
error?.invoke(PlutoError.notSignin)
75-
return@getAuthorizationHeader
76-
}
77-
78-
val body = UpdateUserInfoPutData(name, null)
79-
plutoService.updateUserInfo(body, header).apply {
80-
enqueue(object : Callback<PlutoResponse> {
81-
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
82-
t.printStackTrace()
83-
error?.invoke(PlutoError.badRequest)
84-
}
85-
86-
override fun onResponse(
87-
call: Call<PlutoResponse>,
88-
response: Response<PlutoResponse>
89-
) {
90-
val plutoResponse = response.body()
91-
if (plutoResponse != null) {
92-
if (plutoResponse.statusOK()) {
93-
success()
94-
} else {
95-
error?.invoke(plutoResponse.errorCode())
96-
}
97-
} else {
98-
error?.invoke(
99-
parseErrorCodeFromErrorBody(
100-
response.errorBody(),
101-
gson
102-
)
103-
)
104-
}
105-
}
106-
})
107-
}.also {
108-
handler?.setCall(it)
109-
}
110-
},
111-
handler = handler
112-
)
80+
val postData = UpdateUserInfoPutData(name, null, null)
81+
updateUserInfo(postData, success, error, handler)
11382
}
11483

11584
fun Pluto.uploadAvatar(
@@ -122,6 +91,16 @@ fun Pluto.uploadAvatar(
12291
val outputStream = ByteArrayOutputStream()
12392
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
12493
val base64 = Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)
94+
val postData = UpdateUserInfoPutData(null, base64, null)
95+
updateUserInfo(postData, success, error, handler)
96+
}
97+
98+
private fun Pluto.updateUserInfo(
99+
postData: UpdateUserInfoPutData,
100+
success: () -> Unit,
101+
error: ((PlutoError) -> Unit)? = null,
102+
handler: Pluto.PlutoRequestHandler? = null
103+
) {
125104
getAuthorizationHeader(
126105
completion = { header ->
127106
if (header == null) {
@@ -130,8 +109,7 @@ fun Pluto.uploadAvatar(
130109
return@getAuthorizationHeader
131110
}
132111

133-
val body = UpdateUserInfoPutData(null, base64)
134-
plutoService.updateUserInfo(body, header).apply {
112+
plutoService.updateUserInfo(postData, header).apply {
135113
enqueue(object : Callback<PlutoResponse> {
136114
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
137115
t.printStackTrace()
@@ -166,5 +144,3 @@ fun Pluto.uploadAvatar(
166144
handler = handler
167145
)
168146
}
169-
170-

pluto-kotlin-client-sdk/src/main/java/com/mushare/plutosdk/PlutoService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ class LoginWithGooglePostData(
8989

9090
class UpdateUserInfoPutData(
9191
@field:SerializedName("name") var name: String?,
92-
@field:SerializedName("avatar") var avatar: String?
92+
@field:SerializedName("avatar") var avatar: String?,
93+
@field:SerializedName("avatar") var userId: String?
9394
)

0 commit comments

Comments
 (0)