Skip to content

Commit

Permalink
feat(predict): created implemeteation for predict track methods
Browse files Browse the repository at this point in the history
SUITEDEV-35484

Co-authored-by: LasOri <[email protected]>
  • Loading branch information
davidSchuppa and LasOri committed Apr 10, 2024
1 parent 4e772fb commit f7c32bd
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/EmarsysSDK/API/GenericApi/GenericApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GenericApi<LoggingApiInstance: ActivationAware, GathererApiInstance: Activ

func internalInstance(features: [Feature]) -> ActivationAware {
var result: ActivationAware = loggingInstance
if features.contains(.mobileEngage) {
if features.contains(.mobileEngage) || features.contains(.predict) {
result = internalInstance
}
return result
Expand Down
41 changes: 41 additions & 0 deletions Sources/EmarsysSDK/API/Predict/GathererPredict.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
//
// Copyright © 2024 Emarsys-Technologies Kft. All rights reserved.
//

import Foundation


struct GathererPredict: PredictInstance {
func trackCart(items: [any CartItem]) {

}

func trackPurchase(orderId: String, items: [any CartItem]) {

}

func trackItemView(itemId: String) {

}

func trackCategoryView(categoryPath: String) {

}

func trackSearchTerm(_ searchTerm: String) {

}

func trackTag(_ tag: String, attributes: [String : String]?) {

}

func trackRecommendationClick(product: any Product) {

}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return []
}
}
42 changes: 42 additions & 0 deletions Sources/EmarsysSDK/API/Predict/LoggingPredict.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
//
// Copyright © 2024 Emarsys-Technologies Kft. All rights reserved.
//

import Foundation

struct LoggingPredict: PredictInstance {
let sdkLogger: SdkLogger

func trackCart(items: [any CartItem]) {

}

func trackPurchase(orderId: String, items: [any CartItem]) {

}

func trackItemView(itemId: String) {

}

func trackCategoryView(categoryPath: String) {

}

func trackSearchTerm(_ searchTerm: String) {

}

func trackTag(_ tag: String, attributes: [String : String]?) {

}

func trackRecommendationClick(product: any Product) {

}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return []
}
}
64 changes: 64 additions & 0 deletions Sources/EmarsysSDK/API/Predict/Predict.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
//
// Copyright © 2024 Emarsys-Technologies Kft. All rights reserved.
//

import Foundation

typealias PredictInstance = ActivationAware & PredictApi

class Predict<LoggingInstance: PredictInstance, GathererInstance: PredictInstance, InternalInstance: PredictInstance>: GenericApi<LoggingInstance, GathererInstance, InternalInstance>, PredictInstance {

func trackCart(items: [any CartItem]) {
guard let active = self.active as? PredictApi else {
return
}
active.trackCart(items: items)
}

func trackPurchase(orderId: String, items: [any CartItem]) {
guard let active = self.active as? PredictApi else {
return
}
active.trackPurchase(orderId: orderId, items: items)
}

func trackItemView(itemId: String) {
guard let active = self.active as? PredictApi else {
return
}
active.trackItemView(itemId: itemId)
}

func trackCategoryView(categoryPath: String) {
guard let active = self.active as? PredictApi else {
return
}
active.trackCategoryView(categoryPath: categoryPath)
}

func trackSearchTerm(_ searchTerm: String) {
guard let active = self.active as? PredictApi else {
return
}
active.trackSearchTerm(searchTerm)
}

func trackTag(_ tag: String, attributes: [String : String]?) {
guard let active = self.active as? PredictApi else {
return
}
active.trackTag(tag, attributes: attributes)
}

func trackRecommendationClick(product: any Product) {
guard let active = self.active as? PredictApi else {
return
}
active.trackRecommendationClick(product: product)
}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return []
}
}
18 changes: 9 additions & 9 deletions Sources/EmarsysSDK/API/Predict/PredictApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import Foundation


@SdkActor
protocol PredictApi {
func track(cart items: [CartItem])
func track(purchase orderId: String, _ items: [CartItem])
func track(itemView itemId: String)
func track(categoryView categoryPath: String)
func track(searchTerm: String)
func track(_ tag: String, _ attributes: [String: String]?)
func track(recommendationClick product: Product)
func recommendProducts(_ logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [Product]
func trackCart(items: [CartItem])
func trackPurchase(orderId: String, items: [CartItem])
func trackItemView(itemId: String)
func trackCategoryView(categoryPath: String)
func trackSearchTerm(_ searchTerm: String)
func trackTag(_ tag: String, attributes: [String: String]?)
func trackRecommendationClick(product: Product)
func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [Product]
}
41 changes: 41 additions & 0 deletions Sources/EmarsysSDK/API/Predict/PredictInternal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
//
// Copyright © 2024 Emarsys-Technologies Kft. All rights reserved.
//

import Foundation

class PredictInternal: PredictInstance {
func trackCart(items: [any CartItem]) {

}

func trackPurchase(orderId: String, items: [any CartItem]) {

}

func trackItemView(itemId: String) {

}

func trackCategoryView(categoryPath: String) {

}

func trackSearchTerm(_ searchTerm: String) {

}

func trackTag(_ tag: String, attributes: [String : String]?) {

}

func trackRecommendationClick(product: any Product) {

}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return []
}

}
54 changes: 54 additions & 0 deletions Sources/EmarsysSDKTests/API/Predict/FakePredictApi.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
//
// Copyright © 2024 Emarsys-Technologies Kft. All rights reserved.
//

import Foundation

import Foundation
import mimic
@testable import EmarsysSDK


struct FakePredictApi: PredictInstance, Mimic {
let fnTrackCartItems = Fn<()>()
let fnTrackPurchase = Fn<()>()
let fnTrackItemView = Fn<()>()
let fnTrackCategoryView = Fn<()>()
let fnTrackSearchTerm = Fn<()>()
let fnTrackTag = Fn<()>()
let fnTrackRecommendationClick = Fn<()>()
let fnRecommendProducts = Fn<([Product])>()

func trackCart(items: [any CartItem]) {
return try! self.fnTrackCartItems.invoke(params: items)
}

func trackPurchase(orderId: String, items: [CartItem]) {
return try! self.fnTrackPurchase.invoke(params: orderId, items)
}

func trackItemView(itemId: String) {
return try! self.fnTrackItemView.invoke(params: itemId)
}

func trackCategoryView(categoryPath: String) {
return try! self.fnTrackCategoryView.invoke(params: categoryPath)
}

func trackSearchTerm(_ searchTerm: String) {
return try! self.fnTrackSearchTerm.invoke(params: searchTerm)
}

func trackTag(_ tag: String, attributes: [String: String]?) {
return try! self.fnTrackTag.invoke(params: tag, attributes)
}

func trackRecommendationClick(product: Product) {
return try! self.fnTrackRecommendationClick.invoke(params: product)
}

func recommendProducts(logic: Logic, filters: [Filter]?, limit: Int?, availabilityZone: String?) async -> [any Product] {
return try! self.fnRecommendProducts.invoke(params: logic, filters, limit, availabilityZone)
}
}
Loading

0 comments on commit f7c32bd

Please sign in to comment.