@@ -61,55 +61,24 @@ fun Pluto.myInfo(
61
61
)
62
62
}
63
63
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
+
64
74
fun Pluto.updateName (
65
75
name : String ,
66
76
success : () -> Unit ,
67
77
error : ((PlutoError ) -> Unit )? = null,
68
78
handler : Pluto .PlutoRequestHandler ? = null
69
79
) {
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)
113
82
}
114
83
115
84
fun Pluto.uploadAvatar (
@@ -122,6 +91,16 @@ fun Pluto.uploadAvatar(
122
91
val outputStream = ByteArrayOutputStream ()
123
92
bitmap.compress(Bitmap .CompressFormat .JPEG , 100 , outputStream)
124
93
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
+ ) {
125
104
getAuthorizationHeader(
126
105
completion = { header ->
127
106
if (header == null ) {
@@ -130,8 +109,7 @@ fun Pluto.uploadAvatar(
130
109
return @getAuthorizationHeader
131
110
}
132
111
133
- val body = UpdateUserInfoPutData (null , base64)
134
- plutoService.updateUserInfo(body, header).apply {
112
+ plutoService.updateUserInfo(postData, header).apply {
135
113
enqueue(object : Callback <PlutoResponse > {
136
114
override fun onFailure (call : Call <PlutoResponse >, t : Throwable ) {
137
115
t.printStackTrace()
@@ -166,5 +144,3 @@ fun Pluto.uploadAvatar(
166
144
handler = handler
167
145
)
168
146
}
169
-
170
-
0 commit comments