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
18 changes: 14 additions & 4 deletions Virtusize/Sources/Internal/API/APIEndpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ internal enum APIEndpoints {
// MARK: - Properties
var hostname: String {
switch self {
case .productCheck, .productTypes, .storeProducts:
return Virtusize.environment.servicesUrl()
case .productCheck:
return Virtusize.environment.servicesUrl()

case .productTypes, .storeProducts:
if Virtusize.params?.serviceEnvironment == true {
return Virtusize.environment.servicesUrl()
} else {
return Virtusize.environment.rawValue
}

case .getItemSizeRecommendation:
return Virtusize.environment.getSizeUrl()
case .getShoeSizeRecommendation:
Expand Down Expand Up @@ -120,14 +128,16 @@ internal enum APIEndpoints {
case .storeProducts(let productId):
// Store local copy to avoid repeated access during string interpolation
let isProd = Virtusize.environment.isProdEnv
let envPathForServicesAPI = isProd ? "" : "/stg"
let hasServiceEnvironment = Virtusize.params?.serviceEnvironment == true
let envPathForServicesAPI = !isProd && hasServiceEnvironment ? "/stg" : ""
components.path = "\(envPathForServicesAPI)/a/api/v3/store-products/\(productId)"
components.queryItems = jsonFormatQueryItems()

case .productTypes:
// Store local copy to avoid repeated access during string interpolation
let isProd = Virtusize.environment.isProdEnv
let envPathForServicesAPI = isProd ? "" : "/stg"
let hasServiceEnvironment = Virtusize.params?.serviceEnvironment == true
let envPathForServicesAPI = !isProd && hasServiceEnvironment ? "/stg" : ""
components.path = "\(envPathForServicesAPI)/a/api/v3/product-types"

case .sessions:
Expand Down
8 changes: 6 additions & 2 deletions Virtusize/Sources/Models/VirtusizeParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public class VirtusizeParams {
internal let showSNSButtons: Bool
/// The branch name of testing environment. When specified, overrides the default endpoint of the Virtusize web app.
internal let branch: String?
/// The Boolean value to determine whether to use or not services.virtusize.com url
internal let serviceEnvironment: Bool
/// The Boolean value to determine whether to show or hide the privacy policy
internal let showPrivacyPolicy: Bool

/// Initializes the VirtusizeParams class
init(
region: VirtusizeRegion,
Expand All @@ -53,7 +55,8 @@ public class VirtusizeParams {
detailsPanelCards: [VirtusizeInfoCategory],
showSNSButtons: Bool,
branch: String?,
showPrivacyPolicy: Bool
serviceEnvironment: Bool,
showPrivacyPolicy: Bool,
) {
self.region = region
self.language = language
Expand All @@ -63,6 +66,7 @@ public class VirtusizeParams {
self.showSNSButtons = showSNSButtons
self.branch = branch
self.showPrivacyPolicy = showPrivacyPolicy
self.serviceEnvironment = serviceEnvironment
}

/// Gets the script in JavaScript to be called to pass params to the Virtusize web app
Expand Down
7 changes: 7 additions & 0 deletions Virtusize/Sources/Models/VirtusizeParamsBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class VirtusizeParamsBuilder {
private var detailsPanelCards: [VirtusizeInfoCategory] = VirtusizeInfoCategory.allCases
private var showSNSButtons: Bool = true
private var showPrivacyPolicy: Bool = true
private var serviceEnvironment: Bool = true
private var branch: String?

public init() {}
Expand Down Expand Up @@ -71,6 +72,11 @@ public class VirtusizeParamsBuilder {
return self
}

public func setServiceEnvironment(_ value: Bool) -> VirtusizeParamsBuilder {
serviceEnvironment = value
return self
}

public func build() -> VirtusizeParams {
/// Assigns the region value to a default one corresponding the Virtusize environment
region = Virtusize.environment.virtusizeRegion()
Expand All @@ -82,6 +88,7 @@ public class VirtusizeParamsBuilder {
detailsPanelCards: detailsPanelCards,
showSNSButtons: showSNSButtons,
branch: branch,
serviceEnvironment: serviceEnvironment,
showPrivacyPolicy: showPrivacyPolicy
)
}
Expand Down