Skip to content

Commit

Permalink
#1 Add extension plugin parameter to controll submiting review after …
Browse files Browse the repository at this point in the history
…uploading the build file
  • Loading branch information
cosic committed Oct 20, 2024
1 parent d1aa2da commit 190ce42
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ And finally if your configuration is correct you can use gradle task `samsungPub
| defaultLanguageCode | String | The language in which you provide application information. See [Language codes](https://developer.samsung.com/galaxy-store/galaxy-store-developer-api/content-publish-api-reference.html#publish-content-api-added-language-codes) for a list of supported languages. | "RUS" |
| paid | Boolean | Whether app download requires a user payment | false |
| hasGoogleService | Boolean | Whether the app provides the user with any Google™ services | true |
| submitReview | Boolean | Whether app is submitted for review after uploading | false |
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ open class PublishSetting {
*/
var paid: Boolean = false

/**
* Whether app is submitted for review after uploading
*/
var submitReview: Boolean = false

/**
* App has Google service or not
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ru.litres.publish.samsung.exception

class SubmitReviewException(error: String) : Exception(error)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.litres.publish.samsung.models.update

import kotlinx.serialization.Serializable

@Serializable
data class SubmitReviewRequest(
val contentId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ru.litres.publish.samsung.DebugSetting
import ru.litres.publish.samsung.PublishSetting
import ru.litres.publish.samsung.exception.UploadApkException
import ru.litres.publish.samsung.models.update.ApkFile
import ru.litres.publish.samsung.models.update.SubmitReviewRequest
import ru.litres.publish.samsung.models.update.UpdateDataRequest
import ru.litres.publish.samsung.models.update.UpdateDataResponse
import ru.litres.publish.samsung.models.upload.UploadResponse
Expand All @@ -32,6 +33,12 @@ class UpdateAppRepository(
return updateApplication(fileKey, publishSetting)
}

fun submitReview(
publishSetting: PublishSetting,
): Boolean {
return submitReviewApplication(publishSetting)
}

private fun getUploadSessionId(): String {
val sessionResult =
networkClient.post(CREATE_UPLOAD_SESSION)
Expand Down Expand Up @@ -116,15 +123,42 @@ class UpdateAppRepository(
if (updateResponse?.errorMsg != null) throw UploadApkException(updateResponse.errorMsg)

return updateResponse?.contentStatus == SUCCESS_UPDATE_APK_RESULT

}

@Suppress("ReturnCount")
private fun submitReviewApplication(
publishSetting: PublishSetting,
): Boolean {
val contentId = publishSetting.contentId ?: return false
val data =
SubmitReviewRequest(
contentId,
)
val json = Json.encodeToJsonElement(data)

if (debugSetting.dryMode) {
println("Data for submit review: ")
println(json)
return true
}

val submitReviewResult = networkClient.post(SUBMIT_APPLICATION)
.jsonBody(json.jsonObject.toString())
.response()

return submitReviewResult.second.statusCode in SUCCESS_STATUS_CODES
}

companion object {
private const val CREATE_UPLOAD_SESSION = "/seller/createUploadSessionId"
private const val UPLOAD_APK = "/galaxyapi/fileUpload"
private const val UPDATE_APPLICATION = "/seller/contentUpdate"
private const val SUBMIT_APPLICATION = "/seller/contentSubmit"

private const val SESSION_ID_FIELD = "sessionId"
private const val SUCCESS_UPDATE_APK_RESULT = "REGISTERING"
private val SUCCESS_STATUS_CODES = setOf(200, 204)

private const val KB_DIVIDER = 1024
private const val PERCENT_MULTIPLIER = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class PublishBuildUseCase(
} else {
println("-------- Error while updating apk ----------")
}

if (success && publishSetting.submitReview) {
val submitReviewSuccess = updateAppRepository.submitReview(publishSetting)
if (submitReviewSuccess) {
println("-------- Success submit review ----------")
} else {
println("-------- Error while submit review ----------")
}
}
}

// if dry mode - return fake file
Expand Down

0 comments on commit 190ce42

Please sign in to comment.