Skip to content

Commit

Permalink
Release of 0.6.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
soczowinski committed Jun 17, 2023
1 parent 56dffaa commit 75f0eed
Show file tree
Hide file tree
Showing 112 changed files with 1,734 additions and 335 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.6.0] - 2023-06-16
### Added
- new methods for `Content` module
- added predefined `Events`

### Fixed
- apiKey terminology

### Removed
- old `Content` module methods got deprecated

## [0.5.0] - 2023-05-10
### Added
- `Promotions` module
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Synerise Flutter SDK (synerise-flutter-sdk) (0.5.0)
# Synerise Flutter SDK (synerise-flutter-sdk) (0.6.0)

[![Platform](https://img.shields.io/badge/platform-iOS-orange.svg)](https://github.com/synerise/ios-sdk)
[![Platform](https://img.shields.io/badge/platform-Android-orange.svg)](https://github.com/synerise/android-sdk)
Expand Down Expand Up @@ -45,7 +45,7 @@ This will add a line like this to your package's pubspec.yaml (and run an implic

```
dependencies:
synerise_flutter_sdk: ^0.5.0
synerise_flutter_sdk: ^0.6.0
```

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ repositories {
}

dependencies {
implementation 'com.synerise.sdk:synerise-mobile-sdk:5.3.0'
implementation 'com.synerise.sdk:synerise-mobile-sdk:5.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.Log;

import androidx.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.synerise.synerise_flutter_sdk;


import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;

public class SyneriseMethodChannel {
public static MethodChannel methodChannel;
public static MethodChannel methodChannel;

public static void configureChannel(FlutterEngine flutterEngine) {
methodChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "synerise_dart_channel");
}
public static void configureChannel(FlutterEngine flutterEngine) {
methodChannel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "synerise_dart_channel");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.synerise.synerise_flutter_sdk;

import com.synerise.sdk.error.ApiError;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel.Result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import com.synerise.sdk.error.ApiError;
import com.synerise.synerise_flutter_sdk.SyneriseModule;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import com.synerise.sdk.content.model.DocumentsApiQuery;
import com.synerise.sdk.content.model.DocumentsApiQueryType;
import com.synerise.sdk.content.model.ScreenViewResponse;
import com.synerise.sdk.content.model.document.Document;
import com.synerise.sdk.content.model.recommendation.FiltersJoinerRule;
import com.synerise.sdk.content.model.recommendation.RecommendationRequestBody;
import com.synerise.sdk.content.model.recommendation.RecommendationResponse;
import com.synerise.sdk.content.model.screenview.ScreenView;
import com.synerise.sdk.content.widgets.dataModel.Recommendation;
import com.synerise.sdk.core.net.IDataApiCall;
import com.synerise.synerise_flutter_sdk.SyneriseModule;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,6 +37,8 @@ public class SyneriseContent implements SyneriseModule {
private final String ISO8601_FORMAT = "yyyy-MM-dd'T'kk:mm:ss.SSS'Z'";
private IDataApiCall<RecommendationResponse> getRecommendationsApiCall;
private IDataApiCall<ScreenViewResponse> getScreenViewApiCall;
private IDataApiCall<ScreenView> generateScreenViewApiCall;
private IDataApiCall<Document> generateDocumentApiCall;
private Gson gson = new Gson();

public SyneriseContent() {
Expand All @@ -45,17 +49,26 @@ public void handleMethodCall(MethodCall call, MethodChannel.Result result, Strin

switch (calledMethod) {
case "getDocument":
getDocument(call,result);
getDocument(call, result);
return;
case "getDocuments":
getDocuments(call,result);
getDocuments(call, result);
return;
case "getRecommendations":
getRecommendations(call,result);
getRecommendations(call, result);
return;
case "getScreenView":
getScreenView(result);
return;
case "getRecommendationsV2":
getRecommendationsV2(call, result);
return;
case "generateDocument":
generateDocument(call, result);
return;
case "generateScreenView":
generateScreenView(call, result);
return;
}
}

Expand Down Expand Up @@ -151,13 +164,106 @@ public void getScreenView(MethodChannel.Result result) {
}, apiError -> SyneriseModule.executeFailureResult(apiError, result));
}

private ArrayList<Map<String,Object>> recommendationToArrayList(List<Recommendation> array) {
public void getRecommendationsV2(MethodCall call, MethodChannel.Result result) {
Map recommendationOptions = (Map) call.arguments;
String productID = null;
String slugName = null;
if (call.arguments != null) {
productID = (String) recommendationOptions.get("productID");
slugName = (String) recommendationOptions.get("slug");
}
if (getRecommendationsApiCall != null) getRecommendationsApiCall.cancel();

RecommendationRequestBody recommendationRequestBody = new RecommendationRequestBody();
recommendationRequestBody.setProductId(productID);
recommendationRequestBody.setItemsIds(recommendationOptions.get("productIDs") != null ? (ArrayList<String>) recommendationOptions.get("productIDs") : null);
recommendationRequestBody.setItemsExcluded((ArrayList<String>) recommendationOptions.get("itemsExcluded"));
recommendationRequestBody.setAdditionalFilters((String) recommendationOptions.get("additionalFilters"));
if (recommendationOptions.get("filtersJoiner") != null) {
recommendationRequestBody.setFiltersJoiner(getFiltersJoinerRuleFromString((String) recommendationOptions.get("filtersJoiner")));
}
if (recommendationOptions.get("elasticFiltersJoiner") != null) {
recommendationRequestBody.setElasticFiltersJoiner(getFiltersJoinerRuleFromString((String) recommendationOptions.get("elasticFiltersJoiner")));
}
recommendationRequestBody.setAdditionalElasticFilters((String) recommendationOptions.get("additionalElasticFilters"));
recommendationRequestBody.setDisplayAttributes((ArrayList<String>) recommendationOptions.get("displayAttributes"));
recommendationRequestBody.setIncludeContextItems((boolean) recommendationOptions.get("includeContextItems"));

Map<String, Object> recommendationMap = new HashMap<>();

getRecommendationsApiCall = Content.getRecommendationsV2(slugName, recommendationRequestBody);
getRecommendationsApiCall.execute(responseBody -> {
recommendationMap.put("name", responseBody.getName());
recommendationMap.put("correlationID", responseBody.getCorrelationId());
recommendationMap.put("campaignHash", responseBody.getCampaignHash());
recommendationMap.put("campaignID", responseBody.getCampaignId());
recommendationMap.put("schema", responseBody.getSchema());
recommendationMap.put("slug", responseBody.getSlug());
recommendationMap.put("uuid", responseBody.getUuid());
recommendationMap.put("items", recommendationToArrayList(responseBody.getRecommendations()));
SyneriseModule.executeSuccessResult(recommendationMap, result);
}, apiError -> SyneriseModule.executeFailureResult(apiError, result));
}

public void generateDocument(MethodCall call, MethodChannel.Result result) {
String slug = (String) call.arguments;
Map<String, Object> documentMap = new HashMap<>();
if (generateDocumentApiCall != null) generateDocumentApiCall.cancel();
generateDocumentApiCall = Content.generateDocument(slug);
generateDocumentApiCall.execute(document -> {
if (document.getContent() instanceof String) {
try {
HashMap<String, Object> contentMap = new Gson().fromJson((String) document.getContent(), HashMap.class);
documentMap.put("content", contentMap);
} catch (Exception e) {
e.printStackTrace();
}
} else {
documentMap.put("content", document.getContent());
}
documentMap.put("identifier", document.getUuid());
documentMap.put("slug", document.getSlug());
documentMap.put("schema", document.getSchema());
SyneriseModule.executeSuccessResult(documentMap, result);
}, apiError -> SyneriseModule.executeFailureResult(apiError, result));
}

public void generateScreenView(MethodCall call, MethodChannel.Result result) {
String slug = (String) call.arguments;
Map<String, Object> screenViewMap = new HashMap<>();
if (generateScreenViewApiCall != null) generateScreenViewApiCall.cancel();
generateScreenViewApiCall = Content.generateScreenView(slug);
generateScreenViewApiCall.execute(screenView -> {
screenViewMap.put("audience", screenViewAudienceToWritableMap(screenView.getAudience()));
screenViewMap.put("identifier", screenView.getId());
screenViewMap.put("hashString", screenView.getHash());
screenViewMap.put("path", screenView.getPath());
screenViewMap.put("name", screenView.getName());
screenViewMap.put("priority", screenView.getPriority());
screenViewMap.put("data", screenViewDataMapper(screenView.getData()));
try {
Date createdAtDate = new SimpleDateFormat(ISO8601_FORMAT, Locale.getDefault()).parse(screenView.getCreatedAt());
Date updatedAtDate = new SimpleDateFormat(ISO8601_FORMAT, Locale.getDefault()).parse(screenView.getUpdatedAt());
if (createdAtDate != null) {
screenViewMap.put("createdAt", createdAtDate.getTime());
}
if (updatedAtDate != null) {
screenViewMap.put("updatedAt", updatedAtDate.getTime());
}
} catch (ParseException e) {
e.printStackTrace();
}
SyneriseModule.executeSuccessResult(screenViewMap, result);
}, apiError -> SyneriseModule.executeFailureResult(apiError, result));
}

private ArrayList<Map<String, Object>> recommendationToArrayList(List<Recommendation> array) {

ArrayList<Map<String, Object>> arrayList = new ArrayList();
for (int i = 0; i < array.size(); i++) {
Recommendation recommendation = array.get(i);
Map<String, Object> recommendationMap = new HashMap<>();
Map<String,Object> feed = recommendation.getFeed();
Map<String, Object> feed = recommendation.getFeed();
recommendationMap.put("itemID", recommendation.getItemId());
recommendationMap.put("attributes", feed);
arrayList.add(recommendationMap);
Expand All @@ -183,6 +289,15 @@ private Map audienceToWritableMap(Audience audience) {
return audienceMap;
}

private Map screenViewAudienceToWritableMap(com.synerise.sdk.content.model.screenview.Audience audience) {
Map<String, Object> audienceMap = new HashMap<>();
List<String> segmentsList = audience.getSegments();
audienceMap.put("query", audience.getQuery());
audienceMap.put("targetType", audience.getTargetType());
audienceMap.put("segments", segmentsList != null ? listOfStringsToArrayList(segmentsList) : null);
return audienceMap;
}

private Map screenViewDataMapper(Object data) {
Map screenViewData = (Map) data;
String jsonObject = gson.toJson(data);
Expand All @@ -194,6 +309,19 @@ private Map screenViewDataMapper(Object data) {
return screenViewData;
}

private FiltersJoinerRule getFiltersJoinerRuleFromString(String filtersJoiner) {
switch (filtersJoiner) {
case "and":
return FiltersJoinerRule.AND;
case "or":
return FiltersJoinerRule.OR;
case "replace":
return FiltersJoinerRule.REPLACE;
default:
return null;
}
}

public static SyneriseContent getInstance() {
if (instance == null) {
instance = new SyneriseContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void initSynerise(Application app, MethodCall call, MethodChannel.Result
Map dataFull = (Map) call.arguments;
Map data = (Map) dataFull.get("initializationParameters");
Synerise.Builder.with(app, data.get("clientApiKey").toString(), SyneriseConnector.getApplicationName(app))
.baseUrl(data.containsKey("baseUrl") ? data.get("baseUrl").toString() : null)
.syneriseDebugMode(data.containsKey("debugModeEnabled") ? (boolean) data.get("debugModeEnabled") : null)
.crashHandlingEnabled(data.containsKey("crashHandlingEnabled") ? (boolean) data.get("crashHandlingEnabled") : null)
.baseUrl(data.containsKey("baseUrl") ? (String) data.get("baseUrl") : null)
.syneriseDebugMode(data.containsKey("debugModeEnabled") ? (boolean) data.get("debugModeEnabled") : false)
.crashHandlingEnabled(data.containsKey("crashHandlingEnabled") ? (boolean) data.get("crashHandlingEnabled") : false)
.hostApplicationType(HostApplicationType.FLUTTER)
.pushRegistrationRequired(SyneriseNotifications.getPushNotificationsListener())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.synerise.sdk.error.ApiError;
import com.synerise.sdk.injector.Injector;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void onHandledOpenUrl(InAppMessageData inAppMessageData) {
public void onHandledOpenDeepLink(InAppMessageData inAppMessageData) {
Map<String, Object> data = createMapFromInAppMessageData(inAppMessageData);
data.put("deepLink", inAppMessageData.getDeepLink());
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorInAppMessageListener#onDeepLink",data);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorInAppMessageListener#onDeepLink", data);
}

@Override
Expand All @@ -79,7 +78,7 @@ public void onCustomAction(String identifier, HashMap<String, Object> params, In
Map<String, Object> data = createMapFromInAppMessageData(inAppMessageData);
data.put("name", identifier);
data.put("parameters", params);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorInAppMessageListener#onCustomAction",data);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorInAppMessageListener#onCustomAction", data);
}
});
}
Expand All @@ -101,7 +100,7 @@ public void onPresented() {
@Override
public void onClosed() {
Map<String, Object> map = new HashMap<>();
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorBannerListener#onHide",map);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorBannerListener#onHide", map);
super.onClosed();
}
});
Expand Down Expand Up @@ -136,28 +135,28 @@ public static void registerWalkthroughListener() {
@Override
public void onLoadingError(ApiError error) {
Map<String, Object> map = new HashMap<>();
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onLoadingError",map);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onLoadingError", map);
super.onLoadingError(error);
}

@Override
public void onLoaded(WalkthroughResponse walkthrough) {
Map<String, Object> map = new HashMap<>();
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onLoad",map);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onLoad", map);
super.onLoaded(walkthrough);
}

@Override
public void onPresented() {
Map<String, Object> map = new HashMap<>();
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onPresent",map);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onPresent", map);
super.onPresented();
}

@Override
public void onClosed() {
Map<String, Object> map = new HashMap<>();
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onHide",map);
SyneriseMethodChannel.methodChannel.invokeMethod("Injector#InjectorWalkthroughListener#onHide", map);
super.onClosed();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.synerise.synerise_flutter_sdk.modules;

import android.util.Log;

import com.synerise.sdk.client.Client;
import com.synerise.sdk.core.listeners.DataActionListener;
import com.synerise.sdk.core.listeners.OnRegisterForPushListener;
Expand Down Expand Up @@ -31,7 +29,7 @@ public void handleMethodCall(MethodCall call, MethodChannel.Result result, Strin
registerForNotifications(call, result);
return;
case "handleNotification":
handleNotification(call,result);
handleNotification(call, result);
return;
}
}
Expand All @@ -56,7 +54,7 @@ private void handleNotification(MethodCall call, MethodChannel.Result result) {

public static OnRegisterForPushListener getPushNotificationsListener() {
Map<String, Object> map = new HashMap<>();
registerNativeForPushListener = () -> SyneriseMethodChannel.methodChannel.invokeMethod("Notifications#NotificationsListener#onRegistrationRequired",map);
registerNativeForPushListener = () -> SyneriseMethodChannel.methodChannel.invokeMethod("Notifications#NotificationsListener#onRegistrationRequired", map);
return registerNativeForPushListener;
}
}
}
Loading

0 comments on commit 75f0eed

Please sign in to comment.