Skip to content

Commit

Permalink
feat: implemented get product info method in sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
xeewii committed Jun 25, 2024
1 parent c5d719d commit 4a3e65f
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Params : AbstractParams<Params>() {
enum class Parameter(override val value: String) : ParamInterface {
LIMIT("limit"),
ITEM("item"),
ITEM_ID("item_id"),
PRICE("price"),
LOCATIONS("locations"),

Expand Down
26 changes: 26 additions & 0 deletions personalizatio-sdk/src/main/kotlin/com/personalizatio/SDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.personalizatio.entities.recommended.RecommendedEntity
import com.personalizatio.notification.NotificationHandler
import com.personalizatio.notification.NotificationHelper
import com.personalizatio.notifications.Source
import com.personalizatio.products.OnProductsListener
import com.personalizatio.products.ProductsManager
import com.personalizatio.recommended.OnRecommendedListener
import com.personalizatio.recommended.RecommendedManager
import com.personalizatio.stories.StoriesManager
Expand Down Expand Up @@ -59,6 +61,10 @@ open class SDK {
RecommendedManager(this)
}

private val productsManager: ProductsManager by lazy {
ProductsManager(this)
}

/**
* @param shopId Shop key
*/
Expand Down Expand Up @@ -334,6 +340,26 @@ open class SDK {
recommendedManager.recommend(recommenderCode, listener)
}

/**
* Request a product info
*
* @param productId Product ID
* @param listener Callback
*/
fun getProductInfo(productId: String, listener: OnApiCallbackListener) {
productsManager.getProductInfo(productId, listener)
}

/**
* Request a product info
*
* @param productId Product ID
* @param listener Callback
*/
fun getProductInfo(productId: String, listener: OnProductsListener) {
productsManager.getProductInfo(productId, listener)
}

/**
* Event tracking
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.personalizatio.entities.products.productInfo


import com.google.gson.annotations.SerializedName

data class Category(
@SerializedName("branch")
val branch: Int,
@SerializedName("id")
val id: String,
@SerializedName("level")
val level: Int,
@SerializedName("name")
val name: String,
@SerializedName("name_with_parent")
val nameWithParent: String,
@SerializedName("parent_id")
val parentId: String,
@SerializedName("url")
val url: String,
@SerializedName("url_handle")
val urlHandle: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.personalizatio.entities.products.productInfo


import com.google.gson.annotations.SerializedName

data class ImageDownloadData(
@SerializedName("could_be_widgetable")
val couldBeWidgetable: Boolean,
@SerializedName("image")
val image: String,
@SerializedName("image_changed")
val imageChanged: Boolean,
@SerializedName("name")
val name: String,
@SerializedName("persisted")
val persisted: Boolean,
@SerializedName("price")
val price: String,
@SerializedName("time")
val time: String,
@SerializedName("url")
val url: String,
@SerializedName("widgetable")
val widgetable: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.personalizatio.entities.products.productInfo


class Locations
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.personalizatio.entities.products.productInfo


import com.google.gson.annotations.SerializedName

data class ProductInfoEntity(
@SerializedName("brand")
val brand: String,
@SerializedName("brand_downcase")
val brandDowncase: String,
@SerializedName("categories")
val categories: List<Category>,
@SerializedName("category_ids")
val categoryIds: List<String>,
@SerializedName("child_age_max")
val childAgeMax: Int,
@SerializedName("child_age_min")
val childAgeMin: Int,
@SerializedName("child_gender")
val childGender: String,
@SerializedName("child_type")
val childType: String,
@SerializedName("currency")
val currency: String,
@SerializedName("description")
val description: String,
@SerializedName("discount")
val discount: Boolean,
@SerializedName("ignored")
val ignored: Boolean,
@SerializedName("image_download_data")
val imageDownloadData: ImageDownloadData,
@SerializedName("image_download_start_at")
val imageDownloadStartAt: String,
@SerializedName("is_available")
val isAvailable: Boolean,
@SerializedName("is_child")
val isChild: Boolean,
@SerializedName("locations")
val locations: Locations,
@SerializedName("name")
val name: String,
@SerializedName("picture")
val picture: String,
@SerializedName("price")
val price: String,
@SerializedName("sales_rate")
val salesRate: Int,
@SerializedName("uniqid")
val uniqid: String,
@SerializedName("url")
val url: String,
@SerializedName("widgetable")
val widgetable: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.personalizatio.products

import com.personalizatio.entities.products.productInfo.ProductInfoEntity

interface OnProductsListener {
fun onGetProductInfo(productInfoEntity: ProductInfoEntity) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.personalizatio.products

import com.google.gson.Gson
import com.personalizatio.Params
import com.personalizatio.SDK
import com.personalizatio.api.OnApiCallbackListener
import com.personalizatio.entities.products.productInfo.ProductInfoEntity
import org.json.JSONObject

internal class ProductsManager(val sdk: SDK) {

internal fun getProductInfo(productId: String, listener: OnProductsListener) {
getProductInfo(productId, object : OnApiCallbackListener() {
override fun onSuccess(response: JSONObject?) {
response?.let {
val productInfoEntity = Gson().fromJson(it.toString(), ProductInfoEntity::class.java)
listener.onGetProductInfo(productInfoEntity)
}
}
})
}

internal fun getProductInfo(productId: String, listener: OnApiCallbackListener) {
val params = Params().put(Params.Parameter.ITEM_ID, productId)
sdk.getAsync("products/get/", params.build(), listener)
}
}

0 comments on commit 4a3e65f

Please sign in to comment.