Skip to content

Commit

Permalink
Merge pull request #342 from Ecwid/slug-info-api
Browse files Browse the repository at this point in the history
Add SlugInfo API to api client
  • Loading branch information
fomichdenis authored Oct 20, 2023
2 parents 63150f3 + 4db09ff commit 4e21abf
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.ecwid.apiclient.v3.dto.report.request.ReportRequest
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportResponse
import com.ecwid.apiclient.v3.dto.saleschannels.request.*
import com.ecwid.apiclient.v3.dto.saleschannels.response.*
import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo
import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest
import com.ecwid.apiclient.v3.dto.storage.request.*
import com.ecwid.apiclient.v3.dto.storage.result.*
import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest
Expand Down Expand Up @@ -61,6 +63,7 @@ open class ApiClient private constructor(
reportsApiClient: ReportsApiClientImpl,
subscriptionsApiClient: SubscriptionsApiClientImpl,
instantSiteRedirectsApiClient: InstantSiteRedirectsApiClientImpl,
slugInfoApiClient: SlugInfoApiClientImpl,
) :
StoreProfileApiClient by storeProfileApiClient,
ProductsApiClient by productsApiClient,
Expand All @@ -78,7 +81,8 @@ open class ApiClient private constructor(
ApplicationStorageApiClient by applicationStorageApiClient,
ReportsApiClient by reportsApiClient,
SubscriptionsApiClient by subscriptionsApiClient,
InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient {
InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient,
SlugInfoApiClient by slugInfoApiClient {

constructor(apiClientHelper: ApiClientHelper) : this(
apiClientHelper = apiClientHelper,
Expand All @@ -98,7 +102,8 @@ open class ApiClient private constructor(
applicationStorageApiClient = ApplicationStorageApiClientImpl(apiClientHelper),
reportsApiClient = ReportsApiClientImpl(apiClientHelper),
subscriptionsApiClient = SubscriptionsApiClientImpl(apiClientHelper),
instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper)
instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper),
slugInfoApiClient = SlugInfoApiClientImpl(apiClientHelper),
)

companion object {
Expand Down Expand Up @@ -282,3 +287,7 @@ interface InstantSiteRedirectsApiClient {
fun createInstantSiteRedirects(request: InstantSiteRedirectsCreateRequest): InstantSiteRedirectsCreateResult
fun deleteInstantSiteRedirect(request: InstantSiteRedirectDeleteRequest): InstantSiteRedirectsDeleteResult
}

interface SlugInfoApiClient {
fun getSlugInfo(request: SlugInfoRequest): FetchedSlugInfo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.ecwid.apiclient.v3.dto.sluginfo

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class FetchedSlugInfo(
val status: String = "",
val type: String? = null,
val canonicalSlug: String? = null,
val storeEntityData: EntityData? = null,
val staticContent: StaticContent? = null,
) : ApiFetchedDTO, ApiResultDTO {

data class EntityData(val id: String? = null)

data class StaticContent(
val cssFiles: List<String>? = null,
val htmlCode: String? = null,
val jsCode: String? = null,
val metaDescriptionHtml: String? = null,
val canonicalUrl: String? = null,
val ogTagsHtml: String? = null,
val jsonLDHtml: String? = null,
val hrefLangHtml: String? = null,
val lastUpdated: Long? = null
)

override fun getModifyKind(): ApiFetchedDTO.ModifyKind =
ApiFetchedDTO.ModifyKind.ReadOnly


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ecwid.apiclient.v3.dto.sluginfo

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.responsefields.ResponseFields

data class SlugInfoRequest(
val storeRootPage: Boolean = false,
val slug: String = "",
val getStaticContent: Boolean = false,
val degeneratorParams: Map<String, Any>? = null,
val responseFields: ResponseFields = ResponseFields.All
) : ApiRequest {

override fun toRequestInfo(): RequestInfo = RequestInfo.createGetRequest(
pathSegments = listOf(
"storefront-widget-pages"
),
params = toParams(),
responseFields = responseFields,
)


private fun toParams(): Map<String, String> {
val request = this
return mutableMapOf<String, String>().apply {
put("storeRootPage", storeRootPage.toString())
put("getStaticContent", getStaticContent.toString())
put("slug", slug)
request.degeneratorParams?.let {
request.degeneratorParams.forEach { put(it.key, it.value.toString()) }
}
}.toMap()
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ecwid.apiclient.v3.impl

import com.ecwid.apiclient.v3.ApiClientHelper
import com.ecwid.apiclient.v3.SlugInfoApiClient
import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo
import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest

internal class SlugInfoApiClientImpl(
private val apiClientHelper: ApiClientHelper
) : SlugInfoApiClient {
override fun getSlugInfo(request: SlugInfoRequest): FetchedSlugInfo =
apiClientHelper.makeObjectResultRequest<FetchedSlugInfo>(request)

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
productsSearchRequestNullablePropertyRules,
subscriptionsSearchRequestNullablePropertyRules,
fetchedSubscriptionsNullablePropertyRules,
otherNullablePropertyRules
otherNullablePropertyRules,
fetchedSlugInfoNullablePropertyRules,
fetchedSlugInfoClassesNullablePropertyRules,
slugInfoRequestNullablePropertyRules
).flatten()

sealed class NullablePropertyRule<T, R>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable

val fetchedSlugInfoNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(FetchedSlugInfo::canonicalSlug),
AllowNullable(FetchedSlugInfo::type),
AllowNullable(FetchedSlugInfo::staticContent),
AllowNullable(FetchedSlugInfo::storeEntityData),
)

val fetchedSlugInfoClassesNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(FetchedSlugInfo.EntityData::id),
AllowNullable(FetchedSlugInfo.StaticContent::canonicalUrl),
AllowNullable(FetchedSlugInfo.StaticContent::cssFiles),
AllowNullable(FetchedSlugInfo.StaticContent::jsCode),
AllowNullable(FetchedSlugInfo.StaticContent::hrefLangHtml),
AllowNullable(FetchedSlugInfo.StaticContent::htmlCode),
AllowNullable(FetchedSlugInfo.StaticContent::jsonLDHtml),
AllowNullable(FetchedSlugInfo.StaticContent::lastUpdated),
AllowNullable(FetchedSlugInfo.StaticContent::metaDescriptionHtml),
AllowNullable(FetchedSlugInfo.StaticContent::ogTagsHtml),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable

val slugInfoRequestNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(SlugInfoRequest::degeneratorParams),
)

0 comments on commit 4e21abf

Please sign in to comment.