Skip to content

Commit

Permalink
Merge pull request #116 from adobe/staging
Browse files Browse the repository at this point in the history
Staging to Main Optimize 5.1.0
  • Loading branch information
akhiljain1907 authored Oct 3, 2024
2 parents 5384183 + c025f41 commit 93540ad
Show file tree
Hide file tree
Showing 15 changed files with 820 additions and 53 deletions.
2 changes: 1 addition & 1 deletion AEPOptimize.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AEPOptimize"
s.version = "5.0.1"
s.version = "5.1.0"
s.summary = "Experience Platform Optimize extension for Adobe Experience Platform Mobile SDK. Written and maintained by Adobe."
s.description = <<-DESC
The Experience Platform Optimize extension provides APIs to enable real-time personalization workflows in the Adobe Experience Platform SDKs using Adobe Target or Adobe Journey Optimizer Offer Decisioning.
Expand Down
8 changes: 6 additions & 2 deletions AEPOptimize.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
78AF6DBB284FD9AA0022EB24 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78AF6DB9284FD9AA0022EB24 /* MainInterface.storyboard */; };
78AF6DBF284FD9AA0022EB24 /* AEPOptimizeDemoAppExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 78AF6DB5284FD9AA0022EB24 /* AEPOptimizeDemoAppExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
79AF0BBA3B4B3F0D2B46C847 /* Pods_AEPOptimize.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89FA9F1584C29AFB176C28B9 /* Pods_AEPOptimize.framework */; };
B6B401C52C8052210082B3FE /* OptimizeError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6B401C42C8052210082B3FE /* OptimizeError.swift */; };
C8076C4D265EE786006BEC5D /* TargetProduct.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8076C3F265EE768006BEC5D /* TargetProduct.swift */; };
C8076C52265EE789006BEC5D /* TargetOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8076C46265EE776006BEC5D /* TargetOrder.swift */; };
C8076C57265EE78E006BEC5D /* DictionaryRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8076C45265EE776006BEC5D /* DictionaryRowView.swift */; };
Expand Down Expand Up @@ -187,6 +188,7 @@
AB699BC71E1531AB6A02B9AD /* Pods-shared-AEPOptimizeDemoAppExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-shared-AEPOptimizeDemoAppExtension.debug.xcconfig"; path = "Target Support Files/Pods-shared-AEPOptimizeDemoAppExtension/Pods-shared-AEPOptimizeDemoAppExtension.debug.xcconfig"; sourceTree = "<group>"; };
AB8BAF0E948D2E2747418C4E /* Pods-FunctionalTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FunctionalTests.debug.xcconfig"; path = "Target Support Files/Pods-FunctionalTests/Pods-FunctionalTests.debug.xcconfig"; sourceTree = "<group>"; };
B588A06BD3941420A1C1CBC5 /* Pods-AEPOptimizeDemoObjC.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AEPOptimizeDemoObjC.debug.xcconfig"; path = "Target Support Files/Pods-AEPOptimizeDemoObjC/Pods-AEPOptimizeDemoObjC.debug.xcconfig"; sourceTree = "<group>"; };
B6B401C42C8052210082B3FE /* OptimizeError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptimizeError.swift; sourceTree = "<group>"; };
BEA1EA2DAE5E666C7DEEA655 /* Pods-UnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnitTests.debug.xcconfig"; path = "Target Support Files/Pods-UnitTests/Pods-UnitTests.debug.xcconfig"; sourceTree = "<group>"; };
C2AB724370848D9EA2ABD4AA /* Pods-AEPOptimizeDemoAppExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AEPOptimizeDemoAppExtension.release.xcconfig"; path = "Target Support Files/Pods-AEPOptimizeDemoAppExtension/Pods-AEPOptimizeDemoAppExtension.release.xcconfig"; sourceTree = "<group>"; };
C592630F611720CFBE4F0009 /* Pods_AEPOptimizeDemoObjC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AEPOptimizeDemoObjC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -517,6 +519,7 @@
C88C5F1126152DAB003AE3DE /* DecisionScope.swift */,
C88C5EDC2614F640003AE3DE /* Offer.swift */,
C8DE6B692684181A0076623F /* Offer+Tracking.swift */,
B6B401C42C8052210082B3FE /* OptimizeError.swift */,
C88C5EE02614F693003AE3DE /* OfferType.swift */,
C88C5F0D26152CFF003AE3DE /* OptimizeProposition.swift */,
C8DE6BEE2686848A0076623F /* Proposition+Tracking.swift */,
Expand Down Expand Up @@ -1224,6 +1227,7 @@
C88C5F0E26152CFF003AE3DE /* OptimizeProposition.swift in Sources */,
C88C5F1226152DAB003AE3DE /* DecisionScope.swift in Sources */,
C88C5E952613249C003AE3DE /* OptimizeConstants.swift in Sources */,
B6B401C52C8052210082B3FE /* OptimizeError.swift in Sources */,
C88C5EE12614F693003AE3DE /* OfferType.swift in Sources */,
C88C5F4126187F0B003AE3DE /* String+Optimize.swift in Sources */,
C8276BE4261EC74F00508873 /* Array+Optimize.swift in Sources */,
Expand Down Expand Up @@ -1652,7 +1656,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 5.0.1;
MARKETING_VERSION = 5.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.adobe.aep.AEPOptimize;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1681,7 +1685,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 5.0.1;
MARKETING_VERSION = 5.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.adobe.aep.AEPOptimize;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
13 changes: 9 additions & 4 deletions Sources/AEPOptimize/Event+Optimize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import Foundation
extension Event {
// MARK: - AEP Response Event handle

/// Verify event type and source for Edge error response event.
var isEdgeErrorResponseEvent: Bool {
type == EventType.edge && source == OptimizeConstants.EventSource.EDGE_ERROR_RESPONSE
}

/// Verify event type and source for Edge personalization:decisions event.
var isPersonalizationDecisionResponse: Bool {
type == EventType.edge && source == OptimizeConstants.EventSource.EDGE_PERSONALIZATION_DECISIONS
Expand Down Expand Up @@ -57,15 +62,15 @@ extension Event {
return try? JSONDecoder().decode(T.self, from: jsonData)
}

/// Creates a response event with specified AEPError type added in the Event data.
/// - Parameter error: type of AEPError
/// Creates a response event with specified AEPOptimizeError type added in the Event data.
/// - Parameter error: type of AEPOptimizeError
/// - Returns: error response Event
func createErrorResponseEvent(_ error: AEPError) -> Event {
func createErrorResponseEvent(_ error: AEPOptimizeError) -> Event {
createResponseEvent(name: OptimizeConstants.EventNames.OPTIMIZE_RESPONSE,
type: EventType.optimize,
source: EventSource.responseContent,
data: [
OptimizeConstants.EventDataKeys.RESPONSE_ERROR: error.rawValue
OptimizeConstants.EventDataKeys.RESPONSE_ERROR: error
])
}
}
4 changes: 2 additions & 2 deletions Sources/AEPOptimize/Offer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Offer: NSObject, Codable {
@objc public let etag: String

/// Offer priority score
@objc public let score: Int
@objc public let score: Double

/// Offer schema string
@objc public let schema: String
Expand Down Expand Up @@ -72,7 +72,7 @@ public class Offer: NSObject, Codable {
// Try and decode format, if present. Target response doesn't contain etag, so setting the default value to empty string.
etag = try container.decodeIfPresent(String.self, forKey: .etag) ?? ""

score = try container.decodeIfPresent(Int.self, forKey: .score) ?? 0
score = try container.decodeIfPresent(Double.self, forKey: .score) ?? 0

schema = try container.decode(String.self, forKey: .schema)

Expand Down
30 changes: 26 additions & 4 deletions Sources/AEPOptimize/Optimize+PublicAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ public extension Optimize {
/// - Parameter data: Additional free-form data to be sent in the personalization request.
@objc(updatePropositions:withXdm:andData:)
static func updatePropositions(for decisionScopes: [DecisionScope], withXdm xdm: [String: Any]?, andData data: [String: Any]? = nil) {
updatePropositions(for: decisionScopes, withXdm: xdm, andData: data, nil)
}

/// This API dispatches an Event for the Edge network extension to fetch decision propositions for the provided decision scopes from the decisioning Services enabled behind Experience Edge.
///
/// The returned decision propositions are cached in memory in the Optimize SDK extension and can be retrieved using `getPropositions(for:_:)` API.
/// - Parameter decisionScopes: An array of decision scopes.
/// - Parameter xdm: Additional XDM-formatted data to be sent in the personalization request.
/// - Parameter data: Additional free-form data to be sent in the personalization request.
/// - Parameter completion: Optional completion handler invoked with map of successful decision scopes to propositions and errors, if any
@objc(updatePropositions:withXdm:andData:completion:)
static func updatePropositions(for decisionScopes: [DecisionScope], withXdm xdm: [String: Any]?, andData data: [String: Any]? = nil, _ completion: (([DecisionScope: OptimizeProposition]?, Error?) -> Void)? = nil) {
let flattenedDecisionScopes = decisionScopes
.filter { $0.isValid }
.compactMap { $0.asDictionary() }

guard !flattenedDecisionScopes.isEmpty else {
Log.warning(label: OptimizeConstants.LOG_TAG,
"Cannot update propositions, provided decision scopes array is empty or has invalid items.")
let aepOptimizeError = AEPOptimizeError.createAEPOptimizInvalidRequestError()
completion?(nil, aepOptimizeError)
return
}

Expand All @@ -53,8 +67,16 @@ public extension Optimize {
type: EventType.optimize,
source: EventSource.requestContent,
data: eventData)

MobileCore.dispatch(event: event)
MobileCore.dispatch(event: event, timeout: 10) { responseEvent in
guard let responseEvent = responseEvent else {
let timeoutError = AEPOptimizeError.createAEPOptimizeTimeoutError()
completion?(nil, timeoutError)
return
}
let result = responseEvent.data?[OptimizeConstants.EventDataKeys.PROPOSITIONS] as? [DecisionScope: OptimizeProposition]
let error = responseEvent.data?[OptimizeConstants.EventDataKeys.RESPONSE_ERROR] as? AEPOptimizeError
completion?(result, error)
}
}

/// This API retrieves the previously fetched decisions for the provided decision scopes from the in-memory extension cache.
Expand Down Expand Up @@ -93,8 +115,8 @@ public extension Optimize {
return
}

if let error = responseEvent.data?[OptimizeConstants.EventDataKeys.RESPONSE_ERROR] as? AEPError {
completion(nil, error)
if let error = responseEvent.data?[OptimizeConstants.EventDataKeys.RESPONSE_ERROR] as? AEPOptimizeError {
completion(nil, error.aepError)
return
}

Expand Down
Loading

0 comments on commit 93540ad

Please sign in to comment.