Skip to content

Commit 97f1a73

Browse files
authored
Merge pull request #12 from MuShare/develop/userId
Support userId
2 parents c4e64bb + 766e5f5 commit 97f1a73

File tree

6 files changed

+95
-95
lines changed

6 files changed

+95
-95
lines changed

.idea/codeStyles/Project.xml

Lines changed: 3 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pluto-kotlin-client-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'maven-publish'
55

66
buildscript {
77
ext.versionCode = 11
8-
ext.versionName = '0.3.2'
8+
ext.versionName = '0.4'
99
}
1010

1111
android {

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

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.mushare.plutosdk
22

3+
import android.util.Patterns
34
import com.mushare.plutosdk.Pluto.Companion.appId
45
import retrofit2.Call
56
import retrofit2.Callback
67
import retrofit2.Response
78

8-
fun Pluto.registerByEmail(
9-
address: String,
9+
fun Pluto.register(
10+
userId: String,
11+
mail: String,
1012
password: String,
1113
name: String,
1214
success: () -> Unit,
1315
error: ((PlutoError) -> Unit)? = null,
1416
handler: Pluto.PlutoRequestHandler? = null
1517
) {
16-
plutoService.registerWithEmail(RegisterWithEmailPostData(address, password, name, appId), getLanguage()).apply {
18+
val postData = RegisterPostData(userId, mail, password, name, appId)
19+
plutoService.register(postData, getLanguage()).apply {
1720
enqueue(object : Callback<PlutoResponse> {
1821
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
1922
t.printStackTrace()
@@ -39,12 +42,17 @@ fun Pluto.registerByEmail(
3942
}
4043

4144
fun Pluto.resendValidationEmail(
42-
address: String,
45+
account: String,
4346
success: () -> Unit,
4447
error: ((PlutoError) -> Unit)? = null,
4548
handler: Pluto.PlutoRequestHandler? = null
4649
) {
47-
plutoService.resendValidationEmail(EmailPostData(address, appId), getLanguage()).apply {
50+
val postData =
51+
if (Patterns.EMAIL_ADDRESS.matcher(account).matches())
52+
ResendValidationEmailPostData(null, account, appId)
53+
else
54+
ResendValidationEmailPostData(account, null, appId)
55+
plutoService.resendValidationEmail(postData, getLanguage()).apply {
4856
enqueue(object : Callback<PlutoResponse> {
4957
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
5058
t.printStackTrace()
@@ -70,7 +78,7 @@ fun Pluto.resendValidationEmail(
7078
}
7179

7280
fun Pluto.loginWithAccount(
73-
address: String,
81+
account: String,
7482
password: String,
7583
success: (() -> Unit)? = null,
7684
error: ((PlutoError) -> Unit)? = null,
@@ -81,25 +89,32 @@ fun Pluto.loginWithAccount(
8189
error?.invoke(PlutoError.badRequest)
8290
return
8391
}
84-
plutoService.loginWithAccount(LoginWithAccountPostData(address, password, deviceId, appId)).apply {
85-
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
86-
override fun onFailure(call: Call<PlutoResponseWithBody<LoginResponse>>, t: Throwable) {
87-
t.printStackTrace()
88-
error?.invoke(PlutoError.badRequest)
89-
}
92+
plutoService.loginWithAccount(LoginWithAccountPostData(account, password, deviceId, appId))
93+
.apply {
94+
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
95+
override fun onFailure(
96+
call: Call<PlutoResponseWithBody<LoginResponse>>,
97+
t: Throwable
98+
) {
99+
t.printStackTrace()
100+
error?.invoke(PlutoError.badRequest)
101+
}
90102

91-
override fun onResponse(call: Call<PlutoResponseWithBody<LoginResponse>>, response: Response<PlutoResponseWithBody<LoginResponse>>) {
92-
val plutoResponse = response.body()
93-
if (plutoResponse != null) {
94-
handleLogin(plutoResponse, success, error)
95-
} else {
96-
error?.invoke(parseErrorCodeFromErrorBody(response.errorBody(), gson))
103+
override fun onResponse(
104+
call: Call<PlutoResponseWithBody<LoginResponse>>,
105+
response: Response<PlutoResponseWithBody<LoginResponse>>
106+
) {
107+
val plutoResponse = response.body()
108+
if (plutoResponse != null) {
109+
handleLogin(plutoResponse, success, error)
110+
} else {
111+
error?.invoke(parseErrorCodeFromErrorBody(response.errorBody(), gson))
112+
}
97113
}
98-
}
99-
})
100-
}.also {
101-
handler?.setCall(it)
102-
}
114+
})
115+
}.also {
116+
handler?.setCall(it)
117+
}
103118
}
104119

105120
fun Pluto.loginWithGoogle(
@@ -120,7 +135,10 @@ fun Pluto.loginWithGoogle(
120135
error?.invoke(PlutoError.badRequest)
121136
}
122137

123-
override fun onResponse(call: Call<PlutoResponseWithBody<LoginResponse>>, response: Response<PlutoResponseWithBody<LoginResponse>>) {
138+
override fun onResponse(
139+
call: Call<PlutoResponseWithBody<LoginResponse>>,
140+
response: Response<PlutoResponseWithBody<LoginResponse>>
141+
) {
124142
val plutoResponse = response.body()
125143
if (plutoResponse != null) {
126144
handleLogin(plutoResponse, success, error)

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

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fun Pluto.myInfo(
1818
completion = { header ->
1919
if (header == null) {
2020
handler?.setCall(null)
21-
error?.invoke(PlutoError.notSignin)
21+
error?.invoke(PlutoError.notSignIn)
2222
return@getAuthorizationHeader
2323
}
2424

@@ -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,16 +91,25 @@ 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) {
128107
handler?.setCall(null)
129-
error?.invoke(PlutoError.notSignin)
108+
error?.invoke(PlutoError.notSignIn)
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/PlutoResponse.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,22 @@ enum class PlutoError(val value: Int) {
4747
unknown(-99999),
4848
badRequest(-99998),
4949
parseError(-99997),
50-
notSignin(1001),
50+
notSignIn(1001),
5151
mailAlreadyRegister(2001),
5252
mailNotExist(2002),
5353
mailNotVerified(2003),
5454
mailAlreadyVerified(2004),
55-
userNameNotExist(2005),
56-
userNameExist(2006),
55+
userIdNotExist(2005),
56+
userIdExist(2006),
57+
passwordNotSet(2009),
5758
sendMailFailure(2011),
5859
invalidPassword(3001),
5960
invalidRefreshToken(3002),
60-
invalidJWTToken(3003);
61+
invalidJWTToken(3003),
62+
invalidGoogleIDToken(3004),
63+
invalidAvatarFormat(3006),
64+
jwtTokenExpired(3008),
65+
invalidAccessToken(3009),
66+
invalidApplication(3010),
67+
refreshTokenExpired(3011);
6168
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ interface PlutoService {
1111
): Call<PlutoResponseWithBody<RefreshAuthResponse>>
1212

1313
@POST("v1/user/register")
14-
fun registerWithEmail(
15-
@Body body: RegisterWithEmailPostData,
14+
fun register(
15+
@Body body: RegisterPostData,
1616
@Header("Accept-Language") language: String
1717
): Call<PlutoResponse>
1818

1919
@POST("v1/user/register/verify/mail")
2020
fun resendValidationEmail(
21-
@Body body: EmailPostData,
21+
@Body body: ResendValidationEmailPostData,
2222
@Header("Accept-Language") language: String
2323
): Call<PlutoResponse>
2424

@@ -55,13 +55,20 @@ class RefreshAuthPostData(
5555
@field:SerializedName("app_id") var appId: String
5656
)
5757

58-
class RegisterWithEmailPostData(
58+
class RegisterPostData(
59+
@field:SerializedName("user_id") var userId: String,
5960
@field:SerializedName("mail") var mail: String,
6061
@field:SerializedName("password") var password: String,
6162
@field:SerializedName("name") var name: String,
6263
@field:SerializedName("app_id") var appId: String
6364
)
6465

66+
class ResendValidationEmailPostData(
67+
@field:SerializedName("user_id") var userId: String?,
68+
@field:SerializedName("mail") var mail: String?,
69+
@field:SerializedName("app_id") var appId: String
70+
)
71+
6572
class EmailPostData(
6673
@field:SerializedName("mail") var mail: String,
6774
@field:SerializedName("app_id") var appId: String
@@ -82,5 +89,6 @@ class LoginWithGooglePostData(
8289

8390
class UpdateUserInfoPutData(
8491
@field:SerializedName("name") var name: String?,
85-
@field:SerializedName("avatar") var avatar: String?
92+
@field:SerializedName("avatar") var avatar: String?,
93+
@field:SerializedName("avatar") var userId: String?
8694
)

0 commit comments

Comments
 (0)