-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from Ecwid/slug-info-api
Add SlugInfo API to api client
- Loading branch information
Showing
7 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedSlugInfoRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |
9 changes: 9 additions & 0 deletions
9
src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/SlugInfoRequestRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |