diff --git a/.gitignore b/.gitignore index 12ce8f4..e853089 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gradle build +/out /service_account.json /app-release.apk diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt index f16c277..adf0e03 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt @@ -5,6 +5,7 @@ import com.github.ajalt.clikt.parameters.types.* import com.github.vacxe.googleplaycli.actions.model.* import com.github.vacxe.googleplaycli.core.BaseCommand import java.io.File +import java.nio.file.Path object Commands { object Apks { @@ -262,4 +263,62 @@ object Commands { override fun run(api: PlayStoreApi) = api.ordersRefund(OrdersRefundModel(packageName, orderId, revoke)) } } + + object Inappproducts { + + class Delete : BaseCommand(name = "delete", actionDescription = "Delete an in-app product for an app") { + private val sku: String by option("--sku", "-s", help = "Unique identifier for the in-app product").required() + + override fun run(api: PlayStoreApi) = api.inappproductsDelete(InappproductsDeleteModel(packageName, sku)) + } + + class Get : BaseCommand(name = "get", actionDescription = "Returns information about the in-app product specified") { + private val sku: String by option("--sku", "-s", help = "Unique identifier for the in-app product").required() + + override fun run(api: PlayStoreApi) = api.inappproductsGet(InappproductsGetModel(packageName, sku)) + } + + class Insert : BaseCommand(name = "insert", actionDescription = "Creates a new in-app product for an app") { + private val jsonPath: Path by option("--file", "-f", help = "Json file path").path(mustExist = true, canBeDir = false).required() + private val autoConvertMissingPrices: Boolean by option("--auto-convert-missing-prices", "-a", help = """ + If true the prices for all regions targeted by the parent app that don't have a price specified for + this in-app product will be auto converted to the target currency based on the default price. + Defaults to false. (optional) + """.trimIndent() + ).flag() + + override fun run(api: PlayStoreApi) = api.inappproductsInsert(InappproductsInsertModel(packageName, jsonPath, autoConvertMissingPrices)) + } + + class List : BaseCommand(name = "list", actionDescription = "List all the in-app products for an Android app, both subscriptions and managed in-app products") { + override fun run(api: PlayStoreApi) = api.inappproductsList(DefaultModel(packageName)) + } + + class Patch : BaseCommand(name = "patch", actionDescription = "Updates the details of an in-app product. This method supports patch semantics") { + private val sku: String by option("--sku", "-s", help = "Unique identifier for the in-app product").required() + private val jsonPath: Path by option("--file", "-f", help = "Json file path").path(mustExist = true, canBeDir = false).required() + private val autoConvertMissingPrices: Boolean by option("--auto-convert-missing-prices", "-a", help = """ + If true the prices for all regions targeted by the parent app that don't have a price specified for + this in-app product will be auto converted to the target currency based on the default price. + Defaults to false. (optional) + """.trimIndent() + ).flag() + + override fun run(api: PlayStoreApi) = api.inappproductsPatch(InappproductsPatchModel(packageName, sku, jsonPath, autoConvertMissingPrices)) + } + + class Update : BaseCommand(name = "update", actionDescription = "Updates the details of an in-app product") { + private val sku: String by option("--sku", "-s", help = "Unique identifier for the in-app product").required() + private val jsonPath: Path by option("--file", "-f", help = "Json file path").path(mustExist = true, canBeDir = false).required() + private val autoConvertMissingPrices: Boolean by option("--auto-convert-missing-prices", "-a", help = """ + If true the prices for all regions targeted by the parent app that don't have a price specified for + this in-app product will be auto converted to the target currency based on the default price. + Defaults to false. (optional) + """.trimIndent() + ).flag() + + override fun run(api: PlayStoreApi) = api.inappproductsUpdate(InappproductsUpdateModel(packageName, sku, jsonPath, autoConvertMissingPrices)) + } + } + } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt index ad0ec2b..6ede31c 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt @@ -22,7 +22,8 @@ class PlayStoreApi : Tracks, Internalappsharingartifacts, Orders, - Reviews { + Reviews, + Inappproducts { override val androidPublisher: AndroidPublisher diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt index 989c452..242f809 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt @@ -67,5 +67,13 @@ fun main(args: Array) { subcmd("orders") { addCmd { Commands.Orders.Refund() } } + subcmd("inappproducts") { + addCmd { Commands.Inappproducts.Delete() } + addCmd { Commands.Inappproducts.Get() } + addCmd { Commands.Inappproducts.Insert() } + addCmd { Commands.Inappproducts.List() } + addCmd { Commands.Inappproducts.Patch() } + addCmd { Commands.Inappproducts.Update() } + } }.main(args) } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Inappproducts.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Inappproducts.kt new file mode 100644 index 0000000..c276262 --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/Inappproducts.kt @@ -0,0 +1,63 @@ +package com.github.vacxe.googleplaycli.actions + +import com.github.vacxe.googleplaycli.actions.model.DefaultModel +import com.github.vacxe.googleplaycli.actions.model.InappproductsDeleteModel +import com.github.vacxe.googleplaycli.actions.model.InappproductsGetModel +import com.github.vacxe.googleplaycli.actions.model.InappproductsInsertModel +import com.github.vacxe.googleplaycli.actions.model.InappproductsPatchModel +import com.github.vacxe.googleplaycli.actions.model.InappproductsUpdateModel +import com.google.api.services.androidpublisher.model.InAppProduct +import com.google.api.services.androidpublisher.model.InappproductsListResponse +import java.nio.file.Files + +interface Inappproducts : BaseAction { + + fun inappproductsDelete(model: InappproductsDeleteModel): Void { + return androidPublisher.inappproducts().delete(model.packageName, model.sku).execute() + } + + fun inappproductsGet(model: InappproductsGetModel): InAppProduct { + return androidPublisher.inappproducts().get(model.packageName, model.sku).execute() + } + + fun inappproductsInsert(model: InappproductsInsertModel): InAppProduct { + val product = Files.newInputStream(model.jsonPath).use { + androidPublisher.jsonFactory.fromInputStream(it, InAppProduct::class.java) + } + + return androidPublisher + .inappproducts() + .insert(model.packageName, product) + .setAutoConvertMissingPrices(model.autoConvertMissingPrices) + .execute() + } + + fun inappproductsList(model: DefaultModel): InappproductsListResponse { + return androidPublisher.inappproducts().list(model.packageName).execute() + } + + fun inappproductsPatch(model: InappproductsPatchModel): InAppProduct { + val product = Files.newInputStream(model.jsonPath).use { + androidPublisher.jsonFactory.fromInputStream(it, InAppProduct::class.java) + } + + return androidPublisher + .inappproducts() + .patch(model.packageName, model.sku, product) + .setAutoConvertMissingPrices(model.autoConvertMissingPrices) + .execute() + } + + fun inappproductsUpdate(model: InappproductsUpdateModel): InAppProduct { + val product = Files.newInputStream(model.jsonPath).use { + androidPublisher.jsonFactory.fromInputStream(it, InAppProduct::class.java) + } + + return androidPublisher + .inappproducts() + .update(model.packageName, model.sku, product) + .setAutoConvertMissingPrices(model.autoConvertMissingPrices) + .execute() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsDeleteModel.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsDeleteModel.kt new file mode 100644 index 0000000..835be8e --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsDeleteModel.kt @@ -0,0 +1,6 @@ +package com.github.vacxe.googleplaycli.actions.model + +class InappproductsDeleteModel( + val packageName: String, + val sku: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsGetModel.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsGetModel.kt new file mode 100644 index 0000000..9d49f64 --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsGetModel.kt @@ -0,0 +1,6 @@ +package com.github.vacxe.googleplaycli.actions.model + +class InappproductsGetModel( + val packageName: String, + val sku: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsInsertModel.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsInsertModel.kt new file mode 100644 index 0000000..640492e --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsInsertModel.kt @@ -0,0 +1,9 @@ +package com.github.vacxe.googleplaycli.actions.model + +import java.nio.file.Path + +class InappproductsInsertModel( + val packageName: String, + val jsonPath: Path, + val autoConvertMissingPrices: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsPatchModel.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsPatchModel.kt new file mode 100644 index 0000000..f020f79 --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsPatchModel.kt @@ -0,0 +1,10 @@ +package com.github.vacxe.googleplaycli.actions.model + +import java.nio.file.Path + +class InappproductsPatchModel( + val packageName: String, + val sku: String, + val jsonPath: Path, + val autoConvertMissingPrices: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsUpdateModel.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsUpdateModel.kt new file mode 100644 index 0000000..38948f3 --- /dev/null +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/actions/model/InappproductsUpdateModel.kt @@ -0,0 +1,10 @@ +package com.github.vacxe.googleplaycli.actions.model + +import java.nio.file.Path + +class InappproductsUpdateModel( + val packageName: String, + val sku: String, + val jsonPath: Path, + val autoConvertMissingPrices: Boolean +) \ No newline at end of file