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
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ data class ApiRequest(
* @param environment the Virtusize environment that is used in network requests
* @param apiKey the API key that is unique for every Virtusize client
* @param userId the user ID that is unique from the client system
* @param serviceEnvironment the Boolean value to determine whether to use or not services.virtusize.com url
*/
object VirtusizeApi {
const val DEFAULT_AOYAMA_VERSION = "3.4.2"

private var environment = VirtusizeEnvironment.GLOBAL
private lateinit var apiKey: String
private var branch: String? = null
private var serviceEnvironment: Boolean = true

var currentUserId: String? = null
private set
Expand All @@ -70,17 +72,20 @@ object VirtusizeApi {
* @param key the API key that is unique for every Virtusize client
* @param userId the user ID that is unique from the client system
* @param branch the testing environment branch name
* @param serviceEnv the Boolean value to determine whether to use or not services.virtusize.com url
*/
fun init(
env: VirtusizeEnvironment,
key: String,
userId: String,
branch: String?,
serviceEnv: Boolean = true,
) {
environment = env
apiKey = key
currentUserId = userId
this.branch = branch
this.serviceEnvironment = serviceEnv
}

fun setUserId(userId: String) {
Expand Down Expand Up @@ -301,9 +306,15 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getStoreProductInfo(productId: String): ApiRequest {
val baseUrl =
if (serviceEnvironment) {
environment.servicesApiUrl()
} else {
environment.defaultApiUrl()
}
val url =
Uri.parse(
environment.defaultApiUrl() +
baseUrl +
VirtusizeEndpoint.StoreProducts.path +
productId,
)
Expand All @@ -319,8 +330,14 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getProductTypes(): ApiRequest {
val baseUrl =
if (serviceEnvironment) {
environment.servicesApiUrl()
} else {
environment.defaultApiUrl()
}
val url =
Uri.parse(environment.servicesApiUrl() + VirtusizeEndpoint.ProductType.path)
Uri.parse(baseUrl + VirtusizeEndpoint.ProductType.path)
.buildUpon()
.build()
.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ internal class VirtusizeApiTest {
val actualApiRequest = VirtusizeApi.getStoreProductInfo("16099122")

val expectedUrl =
"https://staging.virtusize.com/a/api/v3/store-products/16099122" +
"https://services.virtusize.com/stg/a/api/v3/store-products/16099122" +
"?format=json"

val expectedApiRequest = ApiRequest(expectedUrl, HttpMethod.GET)
Expand Down
14 changes: 14 additions & 0 deletions virtusize/src/main/java/com/virtusize/android/VirtusizeBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.virtusize.android.data.local.virtusizeRegion
* @param showSNSButtons the Boolean value to determine whether the Virtusize web app will display the SNS buttons
* @param branch the branch name of targeted Virtusize environment when specified
* @param showPrivacyPolicy the Boolean value to determine whether to show or hide the privacy policy
* @param serviceEnvironment the Boolean value to determine whether to use or not services.virtusize.com url
*/
class VirtusizeBuilder {
private var userId: String? = null
Expand All @@ -39,6 +40,7 @@ class VirtusizeBuilder {
private var showSNSButtons: Boolean = true
private var branch: String? = null
private var showPrivacyPolicy: Boolean = true
private var serviceEnvironment: Boolean = true

/**
* This method is used to add the application context to the Virtusize builder
Expand Down Expand Up @@ -161,6 +163,17 @@ class VirtusizeBuilder {
return this
}

/**
* Sets up whether to use services.virtusize.com url
* By default value set to TRUE
* @param serviceEnvironment the Boolean value
* @return [VirtusizeBuilder]
*/
fun setServiceEnvironment(serviceEnvironment: Boolean): VirtusizeBuilder {
this.serviceEnvironment = serviceEnvironment
return this
}

/**
* Builds the Virtusize object from the passed data and returns the Virtusize object
* @return Virtusize
Expand All @@ -187,6 +200,7 @@ class VirtusizeBuilder {
showSNSButtons = showSNSButtons,
branch = branch,
showPrivacyPolicy = showPrivacyPolicy,
serviceEnvironment = serviceEnvironment,
)
return Virtusize.init(context = context!!, params = params)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ internal class VirtusizeImpl(
key = params.apiKey!!,
userId = params.externalUserId ?: "",
branch = params.branch,
serviceEnv = params.serviceEnvironment,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.virtusize.android.SharedPreferencesHelper
* @param showSNSButtons the Boolean value to determine whether the Virtusize web app will display the SNS buttons
* @param branch the branch name of targeted Virtusize testing environment when specified
* @param showPrivacyPolicy the Boolean value to determine whether to show or hide the privacy policy
* @param serviceEnvironment the Boolean value to determine whether to use or not services.virtusize.com url
*/
data class VirtusizeParams(
internal val context: Context,
Expand All @@ -32,6 +33,7 @@ data class VirtusizeParams(
internal val showSNSButtons: Boolean,
internal val branch: String?,
internal val showPrivacyPolicy: Boolean,
internal val serviceEnvironment: Boolean,
) {
/**
* Returns the virtusize parameter string to be passed to the JavaScript function vsParamsFromSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.virtusize.android.data.local.virtusizeRegion
* @param showSNSButtons the Boolean value to determine whether the Virtusize web app will display the SNS buttons
* @param branch the branch name of targeted Virtusize environment when specified
* @param showPrivacyPolicy the Boolean value to determine whether to show or hide the privacy policy
* @param serviceEnvironment the Boolean value to determine whether to use or not services.virtusize.com url
*/
class VirtusizeFlutterBuilder {
private var userId: String? = null
Expand All @@ -40,6 +41,7 @@ class VirtusizeFlutterBuilder {
private var branch: String? = null
private var virtusizeFlutterPresenter: VirtusizeFlutterPresenter? = null
private var showPrivacyPolicy: Boolean = true
private var serviceEnvironment: Boolean = true

/**
* This method is used to add the application context to the Virtusize builder
Expand Down Expand Up @@ -173,6 +175,17 @@ class VirtusizeFlutterBuilder {
return this
}

/**
* Sets up whether to use services.virtusize.com url
* By default value set to TRUE
* @param serviceEnvironment the Boolean value
* @return [VirtusizeFlutterBuilder]
*/
fun setServiceEnvironment(serviceEnvironment: Boolean): VirtusizeFlutterBuilder {
this.serviceEnvironment = serviceEnvironment
return this
}

/**
* Builds the VirtusizeFlutter object from the passed data and returns the VirtusizeFlutter object
* @return VirtusizeFlutter
Expand All @@ -199,6 +212,7 @@ class VirtusizeFlutterBuilder {
showSNSButtons = showSNSButtons,
branch = branch,
showPrivacyPolicy = showPrivacyPolicy,
serviceEnvironment = serviceEnvironment,
)
return VirtusizeFlutter.init(
context = context!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ internal class VirtusizeFlutterImpl(
key = params.apiKey!!,
userId = params.externalUserId ?: "",
branch = params.branch,
serviceEnv = params.serviceEnvironment,
)
}

Expand Down