Skip to content

Commit

Permalink
[NSDK-215] Update Virtusize WebView URL - General Use (#115)
Browse files Browse the repository at this point in the history
* Change the web view URL

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fix unit tests

* Add and fix unit tests

* Make VirtusizeApiTest internal

* Fix unit tests

* Make tests internal

* Change the URL

* Add unit test for fetchLatestAoyamaVersion

* Change the web view background color

* Refactor the way to get the response of a/aoyama/latest.txt

* Use DEFAULT_AOYAMA_VERSION for the version string

* Add VirtusizeApiResponseFormat for the VirtusizeApiTask

* Update pre-push script

* Fix unit test

* Remove suspend
  • Loading branch information
akueisara committed Oct 13, 2024
1 parent 8b862e7 commit 61cb36b
Show file tree
Hide file tree
Showing 18 changed files with 481 additions and 371 deletions.
15 changes: 14 additions & 1 deletion .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ status=$?

if [ "$status" = 0 ] ; then
echo "ktlint check ran successfully."
exit 0
else
echo "ktlint check failed. Formatting with ktlint..."
./gradlew ktlintFormat
exit 1
fi

echo "Running unit tests..."

./gradlew testDebugUnitTest --daemon

status=$? # Update the status after running unit tests

if [ "$status" = 0 ] ; then
echo "Unit tests ran successfully."
exit 0
else
echo "Unit tests failed."
exit 1
fi
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2.5.6
* Update the Virtusize WebView URL - General Use

## 2.5.5

* Updated Size Recommendation API related URL, request model, response model.
* Added environment related size recommendation base URLs.
* Updated unit test

## 2.5.1

* Handle SNS auth for web view apps
Expand Down
6 changes: 5 additions & 1 deletion virtusize-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
}

android {
namespace 'com.virtusize.android.core'
compileSdk 34

defaultConfig {
Expand Down Expand Up @@ -36,13 +37,16 @@ android {
jvmTarget = '17'
}

kotlin.sourceSets.configureEach { sourceSet ->
sourceSet.languageSettings.enableLanguageFeature("DataObjects")
}

testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
namespace 'com.virtusize.android.core'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ data class ApiRequest(
* @param userId the user ID that is unique from the client system
*/
object VirtusizeApi {
const val DEFAULT_AOYAMA_VERSION = "3.3.1"

private var environment = VirtusizeEnvironment.GLOBAL
private lateinit var apiKey: String
private lateinit var userId: String
Expand Down Expand Up @@ -84,7 +86,7 @@ object VirtusizeApi {
*/
fun productCheck(product: VirtusizeProduct): ApiRequest {
val urlBuilder =
Uri.parse(environment.servicesApiUrl() + VirtusizeEndpoint.ProductCheck.getPath())
Uri.parse(environment.servicesApiUrl() + VirtusizeEndpoint.ProductCheck.path)
.buildUpon()
.appendQueryParameter("apiKey", apiKey)
.appendQueryParameter("externalId", product.externalId)
Expand All @@ -93,15 +95,26 @@ object VirtusizeApi {
return ApiRequest(url, HttpMethod.GET)
}

fun fetchLatestAoyamaVersion(): ApiRequest {
val url =
Uri.parse(environment.virtusizeUrl() + VirtusizeEndpoint.LatestAoyamaVersion.path)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.GET)
}

/**
* Gets the Virtusize web view URL for a VirtusizeProduct
*
* @param version the version of the Virtusize web view
* @return the Virtusize web view URL as String
*/
fun virtusizeWebViewURL(): String {
val urlBuilder = Uri.parse(
environment.virtusizeUrl() + VirtusizeEndpoint.VirtusizeWebView.getPath(environment)
)
.buildUpon()
fun virtusizeWebViewURL(version: String = DEFAULT_AOYAMA_VERSION): String {
val urlBuilder =
Uri.parse(
environment.virtusizeUrl() + VirtusizeEndpoint.VirtusizeWebView(version = version).path,
).buildUpon()
return urlBuilder.build().toString()
}

Expand All @@ -111,13 +124,14 @@ object VirtusizeApi {
* @return ApiRequest
*/
fun sendProductImageToBackend(product: VirtusizeProduct): ApiRequest {
val url = Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.ProductMetaDataHints.getPath()
)
.buildUpon()
.build()
.toString()
val url =
Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.ProductMetaDataHints.path,
)
.buildUpon()
.build()
.toString()
val params = mutableMapOf<String, Any>()
product.productCheckData?.data?.storeId?.let {
params["store_id"] = it.toString()
Expand Down Expand Up @@ -224,10 +238,11 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun sendOrder(order: VirtusizeOrder): ApiRequest {
val url = Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.Orders.getPath())
.buildUpon()
.build()
.toString()
val url =
Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.Orders.path)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.POST, order.paramsToMap(apiKey, userId).toMutableMap())
}

Expand All @@ -237,15 +252,16 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getStoreInfo(): ApiRequest {
val url = Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.StoreViewApiKey.getPath() +
apiKey
)
.buildUpon()
.appendQueryParameter("format", "json")
.build()
.toString()
val url =
Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.StoreViewApiKey.path +
apiKey,
)
.buildUpon()
.appendQueryParameter("format", "json")
.build()
.toString()
return ApiRequest(url, HttpMethod.GET)
}

Expand All @@ -255,15 +271,16 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getStoreProductInfo(productId: String): ApiRequest {
val url = Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.StoreProducts.getPath() +
productId
)
.buildUpon()
.appendQueryParameter("format", "json")
.build()
.toString()
val url =
Uri.parse(
environment.defaultApiUrl() +
VirtusizeEndpoint.StoreProducts.path +
productId,
)
.buildUpon()
.appendQueryParameter("format", "json")
.build()
.toString()
return ApiRequest(url, HttpMethod.GET)
}

Expand All @@ -272,10 +289,11 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getProductTypes(): ApiRequest {
val url = Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.ProductType.getPath())
.buildUpon()
.build()
.toString()
val url =
Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.ProductType.path)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.GET)
}

Expand All @@ -284,18 +302,20 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getI18n(language: VirtusizeLanguage): ApiRequest {
val url = Uri.parse(I18N_URL + VirtusizeEndpoint.I18N.getPath() + language.value)
.buildUpon()
.build()
.toString()
val url =
Uri.parse(I18N_URL + VirtusizeEndpoint.I18N.path + language.value)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.GET)
}

fun getSessions(): ApiRequest {
val url = Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.Sessions.getPath())
.buildUpon()
.build()
.toString()
val url =
Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.Sessions.path)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.POST)
}

Expand All @@ -304,10 +324,11 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun deleteUser(): ApiRequest {
val url = Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.User.getPath())
.buildUpon()
.build()
.toString()
val url =
Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.User.path)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.DELETE)
}

Expand All @@ -316,12 +337,13 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getUserProducts(): ApiRequest {
val url = Uri.parse(
environment.defaultApiUrl() + VirtusizeEndpoint.UserProducts.getPath()
)
.buildUpon()
.build()
.toString()
val url =
Uri.parse(
environment.defaultApiUrl() + VirtusizeEndpoint.UserProducts.path,
)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.GET, authorization = true)
}

Expand All @@ -330,12 +352,13 @@ object VirtusizeApi {
* @see ApiRequest
*/
fun getUserBodyProfile(): ApiRequest {
val url = Uri.parse(
environment.defaultApiUrl() + VirtusizeEndpoint.UserBodyMeasurements.getPath()
)
.buildUpon()
.build()
.toString()
val url =
Uri.parse(
environment.defaultApiUrl() + VirtusizeEndpoint.UserBodyMeasurements.path,
)
.buildUpon()
.build()
.toString()
return ApiRequest(url, HttpMethod.GET, authorization = true)
}

Expand All @@ -354,7 +377,7 @@ object VirtusizeApi {
val bodyProfileRecommendedSizeParams =
BodyProfileRecommendedSizeParams(productTypes, storeProduct, userBodyProfile)
val url =
Uri.parse("${environment.sizeRecommendationApiBaseUrl()}${VirtusizeEndpoint.GetSize.getPath()}")
Uri.parse("${environment.sizeRecommendationApiBaseUrl()}${VirtusizeEndpoint.GetSize.path}")
.buildUpon()
.build()
.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.virtusize.android.network

enum class VirtusizeApiResponseFormat {
JSON,
STRING,
}
Loading

0 comments on commit 61cb36b

Please sign in to comment.