Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inappproducts #10

Merged
merged 3 commits into from
May 17, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle

build
/out
/service_account.json
/app-release.apk

Expand Down
59 changes: 59 additions & 0 deletions src/main/kotlin/com/github/vacxe/googleplaycli/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class PlayStoreApi :
Tracks,
Internalappsharingartifacts,
Orders,
Reviews {
Reviews,
Inappproducts {

override val androidPublisher: AndroidPublisher

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,13 @@ fun main(args: Array<String>) {
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)
}
Original file line number Diff line number Diff line change
@@ -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()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.vacxe.googleplaycli.actions.model

class InappproductsDeleteModel(
val packageName: String,
val sku: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.vacxe.googleplaycli.actions.model

class InappproductsGetModel(
val packageName: String,
val sku: String
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)