Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pluto-kotlin-client-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'maven-publish'

buildscript {
ext.versionCode = 11
ext.versionName = '0.3.2'
ext.versionName = '0.4'
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.mushare.plutosdk

import android.util.Patterns
import com.mushare.plutosdk.Pluto.Companion.appId
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

fun Pluto.registerByEmail(
address: String,
fun Pluto.register(
userId: String,
mail: String,
password: String,
name: String,
success: () -> Unit,
error: ((PlutoError) -> Unit)? = null,
handler: Pluto.PlutoRequestHandler? = null
) {
plutoService.registerWithEmail(RegisterWithEmailPostData(address, password, name, appId), getLanguage()).apply {
val postData = RegisterPostData(userId, mail, password, name, appId)
plutoService.register(postData, getLanguage()).apply {
enqueue(object : Callback<PlutoResponse> {
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
t.printStackTrace()
Expand All @@ -39,12 +42,17 @@ fun Pluto.registerByEmail(
}

fun Pluto.resendValidationEmail(
address: String,
account: String,
success: () -> Unit,
error: ((PlutoError) -> Unit)? = null,
handler: Pluto.PlutoRequestHandler? = null
) {
plutoService.resendValidationEmail(EmailPostData(address, appId), getLanguage()).apply {
val postData =
if (Patterns.EMAIL_ADDRESS.matcher(account).matches())
ResendValidationEmailPostData(null, account, appId)
else
ResendValidationEmailPostData(account, null, appId)
plutoService.resendValidationEmail(postData, getLanguage()).apply {
enqueue(object : Callback<PlutoResponse> {
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
t.printStackTrace()
Expand All @@ -70,7 +78,7 @@ fun Pluto.resendValidationEmail(
}

fun Pluto.loginWithAccount(
address: String,
account: String,
password: String,
success: (() -> Unit)? = null,
error: ((PlutoError) -> Unit)? = null,
Expand All @@ -81,25 +89,32 @@ fun Pluto.loginWithAccount(
error?.invoke(PlutoError.badRequest)
return
}
plutoService.loginWithAccount(LoginWithAccountPostData(address, password, deviceId, appId)).apply {
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
override fun onFailure(call: Call<PlutoResponseWithBody<LoginResponse>>, t: Throwable) {
t.printStackTrace()
error?.invoke(PlutoError.badRequest)
}
plutoService.loginWithAccount(LoginWithAccountPostData(account, password, deviceId, appId))
.apply {
enqueue(object : Callback<PlutoResponseWithBody<LoginResponse>> {
override fun onFailure(
call: Call<PlutoResponseWithBody<LoginResponse>>,
t: Throwable
) {
t.printStackTrace()
error?.invoke(PlutoError.badRequest)
}

override fun onResponse(call: Call<PlutoResponseWithBody<LoginResponse>>, response: Response<PlutoResponseWithBody<LoginResponse>>) {
val plutoResponse = response.body()
if (plutoResponse != null) {
handleLogin(plutoResponse, success, error)
} else {
error?.invoke(parseErrorCodeFromErrorBody(response.errorBody(), gson))
override fun onResponse(
call: Call<PlutoResponseWithBody<LoginResponse>>,
response: Response<PlutoResponseWithBody<LoginResponse>>
) {
val plutoResponse = response.body()
if (plutoResponse != null) {
handleLogin(plutoResponse, success, error)
} else {
error?.invoke(parseErrorCodeFromErrorBody(response.errorBody(), gson))
}
}
}
})
}.also {
handler?.setCall(it)
}
})
}.also {
handler?.setCall(it)
}
}

fun Pluto.loginWithGoogle(
Expand All @@ -120,7 +135,10 @@ fun Pluto.loginWithGoogle(
error?.invoke(PlutoError.badRequest)
}

override fun onResponse(call: Call<PlutoResponseWithBody<LoginResponse>>, response: Response<PlutoResponseWithBody<LoginResponse>>) {
override fun onResponse(
call: Call<PlutoResponseWithBody<LoginResponse>>,
response: Response<PlutoResponseWithBody<LoginResponse>>
) {
val plutoResponse = response.body()
if (plutoResponse != null) {
handleLogin(plutoResponse, success, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun Pluto.myInfo(
completion = { header ->
if (header == null) {
handler?.setCall(null)
error?.invoke(PlutoError.notSignin)
error?.invoke(PlutoError.notSignIn)
return@getAuthorizationHeader
}

Expand Down Expand Up @@ -61,55 +61,24 @@ fun Pluto.myInfo(
)
}

fun Pluto.updateUserId(
userId: String,
success: () -> Unit,
error: ((PlutoError) -> Unit)? = null,
handler: Pluto.PlutoRequestHandler? = null
) {
val postData = UpdateUserInfoPutData(null, null, userId)
updateUserInfo(postData, success, error, handler)
}

fun Pluto.updateName(
name: String,
success: () -> Unit,
error: ((PlutoError) -> Unit)? = null,
handler: Pluto.PlutoRequestHandler? = null
) {
getAuthorizationHeader(
completion = { header ->
if (header == null) {
handler?.setCall(null)
error?.invoke(PlutoError.notSignin)
return@getAuthorizationHeader
}

val body = UpdateUserInfoPutData(name, null)
plutoService.updateUserInfo(body, header).apply {
enqueue(object : Callback<PlutoResponse> {
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
t.printStackTrace()
error?.invoke(PlutoError.badRequest)
}

override fun onResponse(
call: Call<PlutoResponse>,
response: Response<PlutoResponse>
) {
val plutoResponse = response.body()
if (plutoResponse != null) {
if (plutoResponse.statusOK()) {
success()
} else {
error?.invoke(plutoResponse.errorCode())
}
} else {
error?.invoke(
parseErrorCodeFromErrorBody(
response.errorBody(),
gson
)
)
}
}
})
}.also {
handler?.setCall(it)
}
},
handler = handler
)
val postData = UpdateUserInfoPutData(name, null, null)
updateUserInfo(postData, success, error, handler)
}

fun Pluto.uploadAvatar(
Expand All @@ -122,16 +91,25 @@ fun Pluto.uploadAvatar(
val outputStream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
val base64 = Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)
val postData = UpdateUserInfoPutData(null, base64, null)
updateUserInfo(postData, success, error, handler)
}

private fun Pluto.updateUserInfo(
postData: UpdateUserInfoPutData,
success: () -> Unit,
error: ((PlutoError) -> Unit)? = null,
handler: Pluto.PlutoRequestHandler? = null
) {
getAuthorizationHeader(
completion = { header ->
if (header == null) {
handler?.setCall(null)
error?.invoke(PlutoError.notSignin)
error?.invoke(PlutoError.notSignIn)
return@getAuthorizationHeader
}

val body = UpdateUserInfoPutData(null, base64)
plutoService.updateUserInfo(body, header).apply {
plutoService.updateUserInfo(postData, header).apply {
enqueue(object : Callback<PlutoResponse> {
override fun onFailure(call: Call<PlutoResponse>, t: Throwable) {
t.printStackTrace()
Expand Down Expand Up @@ -166,5 +144,3 @@ fun Pluto.uploadAvatar(
handler = handler
)
}


Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ enum class PlutoError(val value: Int) {
unknown(-99999),
badRequest(-99998),
parseError(-99997),
notSignin(1001),
notSignIn(1001),
mailAlreadyRegister(2001),
mailNotExist(2002),
mailNotVerified(2003),
mailAlreadyVerified(2004),
userNameNotExist(2005),
userNameExist(2006),
userIdNotExist(2005),
userIdExist(2006),
passwordNotSet(2009),
sendMailFailure(2011),
invalidPassword(3001),
invalidRefreshToken(3002),
invalidJWTToken(3003);
invalidJWTToken(3003),
invalidGoogleIDToken(3004),
invalidAvatarFormat(3006),
jwtTokenExpired(3008),
invalidAccessToken(3009),
invalidApplication(3010),
refreshTokenExpired(3011);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface PlutoService {
): Call<PlutoResponseWithBody<RefreshAuthResponse>>

@POST("v1/user/register")
fun registerWithEmail(
@Body body: RegisterWithEmailPostData,
fun register(
@Body body: RegisterPostData,
@Header("Accept-Language") language: String
): Call<PlutoResponse>

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

Expand Down Expand Up @@ -55,13 +55,20 @@ class RefreshAuthPostData(
@field:SerializedName("app_id") var appId: String
)

class RegisterWithEmailPostData(
class RegisterPostData(
@field:SerializedName("user_id") var userId: String,
@field:SerializedName("mail") var mail: String,
@field:SerializedName("password") var password: String,
@field:SerializedName("name") var name: String,
@field:SerializedName("app_id") var appId: String
)

class ResendValidationEmailPostData(
@field:SerializedName("user_id") var userId: String?,
@field:SerializedName("mail") var mail: String?,
@field:SerializedName("app_id") var appId: String
)

class EmailPostData(
@field:SerializedName("mail") var mail: String,
@field:SerializedName("app_id") var appId: String
Expand All @@ -82,5 +89,6 @@ class LoginWithGooglePostData(

class UpdateUserInfoPutData(
@field:SerializedName("name") var name: String?,
@field:SerializedName("avatar") var avatar: String?
@field:SerializedName("avatar") var avatar: String?,
@field:SerializedName("avatar") var userId: String?
)