Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dx 746 variants implementation #68

Merged
merged 7 commits into from
Sep 12, 2024
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
23 changes: 16 additions & 7 deletions contentstack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android.buildFeatures.buildConfig true
mavenPublishing {
publishToMavenCentral(SonatypeHost.DEFAULT)
signAllPublications()
coordinates("com.contentstack.sdk", "android", "3.16.1")
coordinates("com.contentstack.sdk", "android", "4.0.0")

pom {
name = "contentstack-android"
Expand Down Expand Up @@ -112,18 +112,27 @@ android {

def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
def getPropertyOrEmpty = { key ->
def value = localProperties.getProperty(key)
return value != null ? "$value" : "\"\""
}
def variantsArray = localProperties.getProperty('variantsUID')?.split(",")?.collect { it.trim() }
def variantsAsArrayString = variantsArray ? 'new String[] {' + variantsArray.collect { "\"$it\"" }.join(", ") + '}' : "new String[0]"
buildTypes {
debug {
debuggable true
testCoverageEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

buildConfigField "String", "host", localProperties['host']
buildConfigField "String", "APIKey", localProperties['APIKey']
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
buildConfigField "String", "environment", localProperties['environment']
buildConfigField "String", "contentTypeUID", localProperties['contentType']
buildConfigField "String", "assetUID", localProperties['assetUid']
buildConfigField "String", "host", getPropertyOrEmpty('host')
buildConfigField "String", "APIKey", getPropertyOrEmpty('APIKey')
buildConfigField "String", "deliveryToken", getPropertyOrEmpty('deliveryToken')
buildConfigField "String", "environment", getPropertyOrEmpty('environment')
buildConfigField "String", "contentTypeUID", getPropertyOrEmpty('contentType')
buildConfigField "String", "assetUID", getPropertyOrEmpty('assetUid')
buildConfigField "String", "variantUID", getPropertyOrEmpty('variantUID')
buildConfigField "String", "variantEntryUID", getPropertyOrEmpty('variantEntryUID')
buildConfigField "String[]", "variantsUID", variantsAsArrayString
}
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class EntryTestCase {
private static final String CONTENT_TYPE_UID = BuildConfig.contentTypeUID;
private static CountDownLatch latch;
private static Stack stack;
private static String variantUID = BuildConfig.variantUID;
private static String variantEntryUID = BuildConfig.variantEntryUID;
private static String[] variantsUID = BuildConfig.variantsUID;


@BeforeClass
Expand Down Expand Up @@ -319,4 +322,26 @@ public void onCompletion(ResponseType responseType, Error error) {
latch.await();
}

@Test
public void VariantsTestSingleUid(){
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantUID);
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
assertEquals(variantUID, entry.getHeaders().get("x-cs-variant-uid"));
System.out.println(entry.toJSON());
}
});
}
@Test
public void VariantsTestArray(){
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantsUID);
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
System.out.println(entry.toJSON());
}
});
}

}
36 changes: 36 additions & 0 deletions contentstack/src/main/java/com/contentstack/sdk/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -1494,4 +1494,40 @@ public Entry includeMetadata() {
}
return this;
}
/**
* method variants
* memberof Entry
* description The variant header will be added to client
* returns {Entry}
* example
* import contentstack from '@contentstack/delivery-sdk'
*
* Stack stack = contentstack.Stack("apiKey", "deliveryToken",
* "environment");
* Entry entry =
* stack.contentType("user").entry("entry_uid").variant("variant_uid").fetch();
*/
public Entry variants(String variants){
if (variants != null && variants.length() > 0) {
this.localHeader.put("x-cs-variant-uid", variants.trim());
}
return this;

}
public Entry variants(String[] variants){
if (variants != null && variants.length > 0) {
List<String> variantList = new ArrayList<>();
for (String variant : variants) {
if(variant != null && !variant.trim().isEmpty())
variantList.add(variant.trim());
}
if(!variantList.isEmpty()){
this.localHeader.put("x-cs-variant-uid", String.join(", ", variantList));
}
}
return this;
}
public ArrayMap<String, Object> getHeaders() {
return localHeader;
}
}
Loading