Skip to content

Commit

Permalink
Merge pull request #77 from emartech/MV-345-refactor
Browse files Browse the repository at this point in the history
MV-345 refactoring
  • Loading branch information
Alberto-Hernandezg authored Nov 28, 2022
2 parents 5b185ed + 0a5f90c commit 05af43e
Show file tree
Hide file tree
Showing 42 changed files with 2,801 additions and 2,579 deletions.
2 changes: 1 addition & 1 deletion RNEmarsysWrapper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Pod::Spec.new do |s|
s.source_files = "ios/*.{h,m}"
s.requires_arc = true
s.dependency "React", ">= 0.67.3"
s.dependency "EmarsysSDK", "~> 3.2.3"
s.dependency "EmarsysSDK", "~> 3.2.4"

end
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
apply plugin: 'com.android.library'

android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 24
Expand Down Expand Up @@ -46,5 +46,5 @@ repositories {

dependencies {
implementation "com.facebook.react:react-native:+"
implementation "com.emarsys:emarsys-sdk:3.2.6"
implementation "com.emarsys:emarsys-sdk:3.3.0"
}
26 changes: 0 additions & 26 deletions android/src/main/java/com/emarsys/rnwrapper/ArrayUtil.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.emarsys.rnwrapper;

import com.emarsys.predict.api.model.CartItem;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableNativeArray;
Expand All @@ -12,34 +10,10 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ArrayUtil {

public static List<CartItem> arrayToCartList(ReadableArray array) {
int size = array.size();
List<CartItem> items = new ArrayList<>();

for (int i = 0; i < size; i++) {
ReadableMap map = array.getMap(i);

String itemId = "emptyId";
double price = 0.0;
double quantity = 0.0;

if (map.hasKey("itemId")) itemId = map.getString("itemId");
if (map.hasKey("price")) price = map.getDouble("price");
if (map.hasKey("quantity")) quantity = map.getDouble("quantity");

CartItem item = new CartItemImp(itemId, price, quantity);
items.add(item);
}

return items;
}

public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
JSONArray jsonArray = new JSONArray();

Expand Down
22 changes: 10 additions & 12 deletions android/src/main/java/com/emarsys/rnwrapper/LogicParser.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.emarsys.rnwrapper;

import com.emarsys.predict.api.model.CartItem;
import com.emarsys.predict.api.model.Logic;
import com.emarsys.predict.api.model.RecommendationLogic;
import com.facebook.react.bridge.ReadableArray;

import java.util.List;

import static com.emarsys.predict.api.model.RecommendationLogic.ALSO_BOUGHT;
import static com.emarsys.predict.api.model.RecommendationLogic.CART;
import static com.emarsys.predict.api.model.RecommendationLogic.CATEGORY;
Expand All @@ -16,6 +9,12 @@
import static com.emarsys.predict.api.model.RecommendationLogic.RELATED;
import static com.emarsys.predict.api.model.RecommendationLogic.SEARCH;

import com.emarsys.predict.api.model.CartItem;
import com.emarsys.predict.api.model.Logic;
import com.emarsys.predict.api.model.RecommendationLogic;

import java.util.List;

public class LogicParser {

public static Logic parse(String logic) {
Expand Down Expand Up @@ -48,7 +47,7 @@ public static Logic parse(String logic) {
return recommendedLogic;
}

public static Logic parse(String logic, List<String> variants) {
public static Logic parseWithVariants(String logic, List<String> variants) {
Logic recommendLogic;
switch (logic) {
case PERSONAL:
Expand All @@ -63,20 +62,19 @@ public static Logic parse(String logic, List<String> variants) {
return recommendLogic;
}

public static Logic parse(String logic, ReadableArray array) {
public static Logic parseWithCartItems(String logic, List<CartItem> cartItems) {
Logic recommendLogic;
switch (logic) {
case CART:
List<CartItem> items = ArrayUtil.arrayToCartList(array);
recommendLogic = RecommendationLogic.cart(items);
recommendLogic = RecommendationLogic.cart(cartItems);
break;
default:
recommendLogic = RecommendationLogic.search();
}
return recommendLogic;
}

public static Logic parse(String logic, String query) {
public static Logic parseWithQuery(String logic, String query) {
Logic recommendedLogic;
switch (logic) {
case SEARCH:
Expand Down
Loading

0 comments on commit 05af43e

Please sign in to comment.