Manos Chorianopoulos

added getProfile implementation

This diff is collapsed. Click to expand it.
......@@ -2177,6 +2177,65 @@ public final class WarplySDK {
}
}
// MARK: - Profile
/// Get user profile details
/// - Parameters:
/// - completion: Completion handler with profile model
/// - failureCallback: Failure callback with error code
public func getProfile(completion: @escaping (ProfileModel?) -> Void, failureCallback: @escaping (Int) -> Void) {
Task {
do {
let endpoint = Endpoint.getProfile
let response = try await networkService.requestRaw(endpoint)
await MainActor.run {
if response["status"] as? Int == 1 {
let dynatraceEvent = LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_get_profile_loyalty"
dynatraceEvent._parameters = nil
self.postFrameworkEvent("dynatrace", sender: dynatraceEvent)
if let responseDataResult = response["result"] as? [String: Any] {
let profileModel = ProfileModel(dictionary: responseDataResult)
completion(profileModel)
} else {
completion(nil)
}
} else {
let dynatraceEvent = LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_get_profile_loyalty"
dynatraceEvent._parameters = nil
self.postFrameworkEvent("dynatrace", sender: dynatraceEvent)
failureCallback(-1)
}
}
} catch {
await MainActor.run {
self.handleError(error, context: "getProfile", endpoint: "getProfile", failureCallback: failureCallback)
}
}
}
}
/// Get user profile details (async/await variant)
/// - Returns: Profile model
/// - Throws: WarplyError if the request fails
public func getProfile() async throws -> ProfileModel {
return try await withCheckedThrowingContinuation { continuation in
getProfile(completion: { profile in
if let profile = profile {
continuation.resume(returning: profile)
} else {
continuation.resume(throwing: WarplyError.networkError)
}
}, failureCallback: { errorCode in
continuation.resume(throwing: WarplyError.unknownError(errorCode))
})
}
}
// MARK: - Market
/// Get market pass details
......
......@@ -85,6 +85,9 @@ public enum Endpoint {
case validateCoupon(coupon: [String: Any])
case redeemCoupon(productId: String, productUuid: String, merchantId: String)
// Profile
case getProfile
// Events
case sendEvent(eventName: String, priority: Bool)
......@@ -127,7 +130,7 @@ public enum Endpoint {
return "/api/mobile/v2/{appUUID}/context/"
// Authenticated Context endpoints - /oauth/{appUUID}/context
case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
return "/oauth/{appUUID}/context"
// Session endpoints - /api/session/{sessionUuid}
......@@ -156,7 +159,7 @@ public enum Endpoint {
switch self {
case .register, .changePassword, .resetPassword, .requestOtp, .verifyTicket, .refreshToken, .logout, .getCampaigns, .getCampaignsPersonalized,
.getCoupons, .getCouponSets, .getAvailableCoupons,
.getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon, .getMerchants, .sendEvent, .sendDeviceInfo, .getCosmoteUser:
.getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon, .getMerchants, .sendEvent, .sendDeviceInfo, .getCosmoteUser:
return .POST
case .getSingleCampaign, .getNetworkStatus:
return .GET
......@@ -295,6 +298,14 @@ public enum Endpoint {
]
]
case .getProfile:
return [
"consumer_data": [
"action": "handle_user_details",
"process": "get"
]
]
// Card Management endpoints - nested structure with cards wrapper
case .addCard(let cardNumber, let cardIssuer, let cardHolder, let expirationMonth, let expirationYear):
return [
......@@ -433,7 +444,7 @@ public enum Endpoint {
return .standardContext
// Authenticated Context - /oauth/{appUUID}/context
case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
return .authenticatedContext
// Authentication - /oauth/{appUUID}/login, /oauth/{appUUID}/token
......@@ -475,7 +486,7 @@ public enum Endpoint {
return .standard
// Bearer Token Authentication (loyalty headers + Authorization: Bearer)
case .changePassword, .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
case .changePassword, .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon:
return .bearerToken
// Basic Authentication (loyalty headers + Authorization: Basic)
......
......@@ -950,6 +950,21 @@ extension NetworkService {
return response
}
// MARK: - Profile Methods
/// Get user profile details
/// - Returns: Response dictionary containing user profile information
/// - Throws: NetworkError if request fails
public func getProfile() async throws -> [String: Any] {
print("🔄 [NetworkService] Getting user profile...")
let endpoint = Endpoint.getProfile
let response = try await requestRaw(endpoint)
print("✅ [NetworkService] Get profile request completed")
return response
}
// MARK: - Coupon Operations Methods
/// Validate a coupon for the user
......