Showing
5 changed files
with
89 additions
and
4 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -2177,6 +2177,65 @@ public final class WarplySDK { | ... | @@ -2177,6 +2177,65 @@ public final class WarplySDK { |
| 2177 | } | 2177 | } |
| 2178 | } | 2178 | } |
| 2179 | 2179 | ||
| 2180 | + // MARK: - Profile | ||
| 2181 | + | ||
| 2182 | + /// Get user profile details | ||
| 2183 | + /// - Parameters: | ||
| 2184 | + /// - completion: Completion handler with profile model | ||
| 2185 | + /// - failureCallback: Failure callback with error code | ||
| 2186 | + public func getProfile(completion: @escaping (ProfileModel?) -> Void, failureCallback: @escaping (Int) -> Void) { | ||
| 2187 | + Task { | ||
| 2188 | + do { | ||
| 2189 | + let endpoint = Endpoint.getProfile | ||
| 2190 | + let response = try await networkService.requestRaw(endpoint) | ||
| 2191 | + | ||
| 2192 | + await MainActor.run { | ||
| 2193 | + if response["status"] as? Int == 1 { | ||
| 2194 | + let dynatraceEvent = LoyaltySDKDynatraceEventModel() | ||
| 2195 | + dynatraceEvent._eventName = "custom_success_get_profile_loyalty" | ||
| 2196 | + dynatraceEvent._parameters = nil | ||
| 2197 | + self.postFrameworkEvent("dynatrace", sender: dynatraceEvent) | ||
| 2198 | + | ||
| 2199 | + if let responseDataResult = response["result"] as? [String: Any] { | ||
| 2200 | + let profileModel = ProfileModel(dictionary: responseDataResult) | ||
| 2201 | + completion(profileModel) | ||
| 2202 | + } else { | ||
| 2203 | + completion(nil) | ||
| 2204 | + } | ||
| 2205 | + } else { | ||
| 2206 | + let dynatraceEvent = LoyaltySDKDynatraceEventModel() | ||
| 2207 | + dynatraceEvent._eventName = "custom_error_get_profile_loyalty" | ||
| 2208 | + dynatraceEvent._parameters = nil | ||
| 2209 | + self.postFrameworkEvent("dynatrace", sender: dynatraceEvent) | ||
| 2210 | + | ||
| 2211 | + failureCallback(-1) | ||
| 2212 | + } | ||
| 2213 | + } | ||
| 2214 | + } catch { | ||
| 2215 | + await MainActor.run { | ||
| 2216 | + self.handleError(error, context: "getProfile", endpoint: "getProfile", failureCallback: failureCallback) | ||
| 2217 | + } | ||
| 2218 | + } | ||
| 2219 | + } | ||
| 2220 | + } | ||
| 2221 | + | ||
| 2222 | + /// Get user profile details (async/await variant) | ||
| 2223 | + /// - Returns: Profile model | ||
| 2224 | + /// - Throws: WarplyError if the request fails | ||
| 2225 | + public func getProfile() async throws -> ProfileModel { | ||
| 2226 | + return try await withCheckedThrowingContinuation { continuation in | ||
| 2227 | + getProfile(completion: { profile in | ||
| 2228 | + if let profile = profile { | ||
| 2229 | + continuation.resume(returning: profile) | ||
| 2230 | + } else { | ||
| 2231 | + continuation.resume(throwing: WarplyError.networkError) | ||
| 2232 | + } | ||
| 2233 | + }, failureCallback: { errorCode in | ||
| 2234 | + continuation.resume(throwing: WarplyError.unknownError(errorCode)) | ||
| 2235 | + }) | ||
| 2236 | + } | ||
| 2237 | + } | ||
| 2238 | + | ||
| 2180 | // MARK: - Market | 2239 | // MARK: - Market |
| 2181 | 2240 | ||
| 2182 | /// Get market pass details | 2241 | /// Get market pass details | ... | ... |
| ... | @@ -85,6 +85,9 @@ public enum Endpoint { | ... | @@ -85,6 +85,9 @@ public enum Endpoint { |
| 85 | case validateCoupon(coupon: [String: Any]) | 85 | case validateCoupon(coupon: [String: Any]) |
| 86 | case redeemCoupon(productId: String, productUuid: String, merchantId: String) | 86 | case redeemCoupon(productId: String, productUuid: String, merchantId: String) |
| 87 | 87 | ||
| 88 | + // Profile | ||
| 89 | + case getProfile | ||
| 90 | + | ||
| 88 | // Events | 91 | // Events |
| 89 | case sendEvent(eventName: String, priority: Bool) | 92 | case sendEvent(eventName: String, priority: Bool) |
| 90 | 93 | ||
| ... | @@ -127,7 +130,7 @@ public enum Endpoint { | ... | @@ -127,7 +130,7 @@ public enum Endpoint { |
| 127 | return "/api/mobile/v2/{appUUID}/context/" | 130 | return "/api/mobile/v2/{appUUID}/context/" |
| 128 | 131 | ||
| 129 | // Authenticated Context endpoints - /oauth/{appUUID}/context | 132 | // Authenticated Context endpoints - /oauth/{appUUID}/context |
| 130 | - case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: | 133 | + case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: |
| 131 | return "/oauth/{appUUID}/context" | 134 | return "/oauth/{appUUID}/context" |
| 132 | 135 | ||
| 133 | // Session endpoints - /api/session/{sessionUuid} | 136 | // Session endpoints - /api/session/{sessionUuid} |
| ... | @@ -156,7 +159,7 @@ public enum Endpoint { | ... | @@ -156,7 +159,7 @@ public enum Endpoint { |
| 156 | switch self { | 159 | switch self { |
| 157 | case .register, .changePassword, .resetPassword, .requestOtp, .verifyTicket, .refreshToken, .logout, .getCampaigns, .getCampaignsPersonalized, | 160 | case .register, .changePassword, .resetPassword, .requestOtp, .verifyTicket, .refreshToken, .logout, .getCampaigns, .getCampaignsPersonalized, |
| 158 | .getCoupons, .getCouponSets, .getAvailableCoupons, | 161 | .getCoupons, .getCouponSets, .getAvailableCoupons, |
| 159 | - .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon, .getMerchants, .sendEvent, .sendDeviceInfo, .getCosmoteUser: | 162 | + .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon, .getMerchants, .sendEvent, .sendDeviceInfo, .getCosmoteUser: |
| 160 | return .POST | 163 | return .POST |
| 161 | case .getSingleCampaign, .getNetworkStatus: | 164 | case .getSingleCampaign, .getNetworkStatus: |
| 162 | return .GET | 165 | return .GET |
| ... | @@ -295,6 +298,14 @@ public enum Endpoint { | ... | @@ -295,6 +298,14 @@ public enum Endpoint { |
| 295 | ] | 298 | ] |
| 296 | ] | 299 | ] |
| 297 | 300 | ||
| 301 | + case .getProfile: | ||
| 302 | + return [ | ||
| 303 | + "consumer_data": [ | ||
| 304 | + "action": "handle_user_details", | ||
| 305 | + "process": "get" | ||
| 306 | + ] | ||
| 307 | + ] | ||
| 308 | + | ||
| 298 | // Card Management endpoints - nested structure with cards wrapper | 309 | // Card Management endpoints - nested structure with cards wrapper |
| 299 | case .addCard(let cardNumber, let cardIssuer, let cardHolder, let expirationMonth, let expirationYear): | 310 | case .addCard(let cardNumber, let cardIssuer, let cardHolder, let expirationMonth, let expirationYear): |
| 300 | return [ | 311 | return [ |
| ... | @@ -433,7 +444,7 @@ public enum Endpoint { | ... | @@ -433,7 +444,7 @@ public enum Endpoint { |
| 433 | return .standardContext | 444 | return .standardContext |
| 434 | 445 | ||
| 435 | // Authenticated Context - /oauth/{appUUID}/context | 446 | // Authenticated Context - /oauth/{appUUID}/context |
| 436 | - case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: | 447 | + case .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: |
| 437 | return .authenticatedContext | 448 | return .authenticatedContext |
| 438 | 449 | ||
| 439 | // Authentication - /oauth/{appUUID}/login, /oauth/{appUUID}/token | 450 | // Authentication - /oauth/{appUUID}/login, /oauth/{appUUID}/token |
| ... | @@ -475,7 +486,7 @@ public enum Endpoint { | ... | @@ -475,7 +486,7 @@ public enum Endpoint { |
| 475 | return .standard | 486 | return .standard |
| 476 | 487 | ||
| 477 | // Bearer Token Authentication (loyalty headers + Authorization: Bearer) | 488 | // Bearer Token Authentication (loyalty headers + Authorization: Bearer) |
| 478 | - case .changePassword, .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: | 489 | + case .changePassword, .getCampaignsPersonalized, .getCoupons, .getMarketPassDetails, .getProfile, .addCard, .getCards, .deleteCard, .getTransactionHistory, .getPointsHistory, .validateCoupon, .redeemCoupon: |
| 479 | return .bearerToken | 490 | return .bearerToken |
| 480 | 491 | ||
| 481 | // Basic Authentication (loyalty headers + Authorization: Basic) | 492 | // Basic Authentication (loyalty headers + Authorization: Basic) | ... | ... |
| ... | @@ -950,6 +950,21 @@ extension NetworkService { | ... | @@ -950,6 +950,21 @@ extension NetworkService { |
| 950 | return response | 950 | return response |
| 951 | } | 951 | } |
| 952 | 952 | ||
| 953 | + // MARK: - Profile Methods | ||
| 954 | + | ||
| 955 | + /// Get user profile details | ||
| 956 | + /// - Returns: Response dictionary containing user profile information | ||
| 957 | + /// - Throws: NetworkError if request fails | ||
| 958 | + public func getProfile() async throws -> [String: Any] { | ||
| 959 | + print("🔄 [NetworkService] Getting user profile...") | ||
| 960 | + let endpoint = Endpoint.getProfile | ||
| 961 | + let response = try await requestRaw(endpoint) | ||
| 962 | + | ||
| 963 | + print("✅ [NetworkService] Get profile request completed") | ||
| 964 | + | ||
| 965 | + return response | ||
| 966 | + } | ||
| 967 | + | ||
| 953 | // MARK: - Coupon Operations Methods | 968 | // MARK: - Coupon Operations Methods |
| 954 | 969 | ||
| 955 | /// Validate a coupon for the user | 970 | /// Validate a coupon for the user | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment