-
Notifications
You must be signed in to change notification settings - Fork 38
Edge Identity iOS implementation #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,4 @@ | |
|
|
||
| @interface RCTAEPEdgeIdentity : NSObject <RCTBridgeModule> | ||
|
|
||
| @end | ||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,11 @@ | |
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| #import "RCTAEPEdgeIdentity.h" | ||
| @import AEPEdgeIdentity; | ||
| @import AEPCore; | ||
| #import "RCTAEPEdgeIdentity.h" | ||
| #import "RCTAEPEdgeIdentityDataBridge.h" | ||
|
|
||
|
|
||
| @implementation RCTAEPEdgeIdentity | ||
|
|
||
|
|
@@ -39,6 +41,36 @@ - (dispatch_queue_t)methodQueue | |
| }]; | ||
| } | ||
|
|
||
| RCT_EXPORT_METHOD(getIdentities:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock)reject) { | ||
|
|
||
| [AEPMobileEdgeIdentity getIdentities:^(AEPIdentityMap * _Nullable IdentityMap, NSError * _Nullable error) { | ||
|
|
||
| if (error) { | ||
| [self handleError:error rejecter:reject errorLocation:@"getIdentities"]; | ||
| } else { | ||
| resolve([RCTAEPEdgeIdentityDataBridge dictionaryFromIdentityMap:IdentityMap]); | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| RCT_EXPORT_METHOD(updateIdentities:(nonnull NSDictionary*) map) { | ||
| AEPIdentityMap *convertMap = [RCTAEPEdgeIdentityDataBridge dictionaryToIdentityMap:map]; | ||
|
|
||
| [AEPMobileEdgeIdentity updateIdentities:(AEPIdentityMap * _Nonnull) convertMap]; | ||
| } | ||
|
|
||
| RCT_EXPORT_METHOD(removeIdentity:(nonnull NSDictionary*)item | ||
| namespace:(NSString *)namespace) { | ||
|
|
||
| AEPIdentityItem *convertItem = [RCTAEPEdgeIdentityDataBridge dictionaryToIdentityItem:item]; | ||
|
|
||
| if (!convertItem || !namespace) { | ||
| return; | ||
| } | ||
|
|
||
| [AEPMobileEdgeIdentity removeIdentityItem:(AEPIdentityItem * _Nonnull) convertItem withNamespace:(NSString * _Nonnull) namespace]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here, item is nullable, but then the AEPMobileEdgeIdentity removeIdentityItem expects a nonnull, make sure the items is not null before calling this api
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What to do if the dictionary is nil in dictionaryToIdneityItem? I return it to nil right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First of all dictionaryToIdentityItem should not be null but if it evaluates to null you send null, and you cannot pass null item to removeIdentityMap, so you can just log an error and exit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have something like |
||
| } | ||
|
|
||
| #pragma mark - Helper methods | ||
|
|
||
| - (void) handleError:(NSError *) error rejecter:(RCTPromiseRejectBlock) reject errorLocation:(NSString *) location { | ||
|
|
@@ -59,4 +91,4 @@ - (void) handleError:(NSError *) error rejecter:(RCTPromiseRejectBlock) reject e | |
|
|
||
| } | ||
|
|
||
| @end | ||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2021 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| @import AEPEdgeIdentity; | ||
|
|
||
| @interface RCTAEPEdgeIdentityDataBridge : NSObject | ||
|
|
||
| + (NSDictionary *_Nullable)dictionaryFromIdentityMap: (nullable AEPIdentityMap *) map; | ||
|
|
||
| + (AEPIdentityMap *_Nonnull)dictionaryToIdentityMap: (nonnull NSDictionary *) dict; | ||
|
|
||
| + (AEPIdentityItem *_Nullable)dictionaryToIdentityItem: (nullable NSDictionary *) dict; | ||
|
|
||
| + (AEPAuthenticatedState) authStateFromString: (nullable NSString *) authStateString; | ||
|
|
||
| + (NSString *_Nullable)stringFromAuthState: (AEPAuthenticatedState) authState; | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| Copyright 2021 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| #import "RCTAEPEdgeIdentityDataBridge.h" | ||
|
|
||
| @implementation RCTAEPEdgeIdentityDataBridge | ||
|
|
||
| static NSString* const ID_KEY = @"id"; | ||
| static NSString* const IS_PRIMARY_KEY = @"primary"; | ||
| static NSString* const AUTH_STATE_KEY = @"authenticatedState"; | ||
| static NSString* const ITEM_KEY = @"items"; | ||
| static NSString* const AUTHENTICATED = @"authenticated"; | ||
| static NSString* const LOGGED_OUT = @"loggedOut"; | ||
| static NSString* const AMBIGUOUS = @"ambiguous"; | ||
|
|
||
| + (NSDictionary *)dictionaryFromIdentityMap: (nullable AEPIdentityMap *) idmap { | ||
emdobrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NSMutableDictionary *mapDict = [NSMutableDictionary dictionary]; | ||
|
|
||
| if (!idmap){ | ||
| return mapDict; | ||
| } | ||
|
|
||
| for (NSString *namespace in idmap.namespaces) { | ||
| NSArray* items = [idmap getItemsWithNamespace:namespace]; | ||
|
|
||
| NSMutableArray *mapArray = [NSMutableArray array]; | ||
|
|
||
| for (AEPIdentityItem *item in items){ | ||
| NSMutableDictionary *itemdict = [NSMutableDictionary dictionary]; | ||
| itemdict[IS_PRIMARY_KEY] = @(item.primary); | ||
| itemdict[AUTH_STATE_KEY] = [RCTAEPEdgeIdentityDataBridge stringFromAuthState:(item.authenticatedState)]; | ||
| itemdict[ID_KEY] = item.id ; | ||
|
|
||
| [mapArray addObject:itemdict]; | ||
| } | ||
| if (mapArray.count !=0) { | ||
| [mapDict setObject:mapArray forKey:namespace]; | ||
| } | ||
| } | ||
|
|
||
| return mapDict; | ||
| } | ||
|
|
||
| + (nonnull AEPIdentityMap *)dictionaryToIdentityMap: (nonnull NSDictionary *) dict { | ||
| AEPIdentityMap *identityMap = [[AEPIdentityMap alloc] init]; | ||
| NSDictionary *itemsMap = [[dict objectForKey:ITEM_KEY] isKindOfClass:[NSDictionary class]] ? [dict objectForKey:ITEM_KEY] : nil; | ||
emdobrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!itemsMap){ | ||
| return identityMap; | ||
| } | ||
|
|
||
| NSArray <NSString*>* namespaces = [itemsMap allKeys]; | ||
|
|
||
| for (NSString *namespace in namespaces){ | ||
| NSArray* items = [itemsMap objectForKey:namespace]; | ||
| for (NSDictionary *itemMap in items){ | ||
| AEPIdentityItem *item = [RCTAEPEdgeIdentityDataBridge dictionaryToIdentityItem:itemMap]; | ||
|
|
||
| if (item){ | ||
| [identityMap addItem:item withNamespace:namespace]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return identityMap; | ||
| } | ||
|
|
||
| + (AEPIdentityItem *)dictionaryToIdentityItem: (nullable NSDictionary *) dict { | ||
|
|
||
| if (!dict) { | ||
| return nil; | ||
| } | ||
|
|
||
| NSString *identifier = [[dict objectForKey:ID_KEY] isKindOfClass:[NSString class]] ? [dict objectForKey:ID_KEY] : nil; | ||
|
|
||
| NSString *authenticatedString = [[dict objectForKey:AUTH_STATE_KEY] isKindOfClass:[NSString class]] ? [dict objectForKey:AUTH_STATE_KEY] : nil; | ||
|
|
||
| AEPAuthenticatedState authenticatedState = [RCTAEPEdgeIdentityDataBridge authStateFromString:(authenticatedString)]; | ||
|
|
||
| BOOL primary = [[dict objectForKey:IS_PRIMARY_KEY] boolValue]; | ||
|
|
||
| return [[AEPIdentityItem alloc] initWithId:identifier authenticatedState:authenticatedState primary:primary]; | ||
| } | ||
|
|
||
| + (AEPAuthenticatedState) authStateFromString: (nullable NSString *) authStateString { | ||
| if (!authStateString){ | ||
| return AEPAuthenticatedStateAmbiguous; | ||
| } | ||
|
|
||
| if ([authStateString isEqualToString:AUTHENTICATED]) { | ||
| return AEPAuthenticatedStateAuthenticated; | ||
| } else if ([authStateString isEqualToString:LOGGED_OUT]) { | ||
| return AEPAuthenticatedStateLoggedOut; | ||
| } | ||
|
|
||
| return AEPAuthenticatedStateAmbiguous; | ||
| } | ||
|
|
||
| + (NSString *) stringFromAuthState: (AEPAuthenticatedState) authState { | ||
| if (!authState){ | ||
| return AMBIGUOUS; | ||
| } | ||
|
|
||
| switch (authState) { | ||
| case AEPAuthenticatedStateAuthenticated: | ||
| return AUTHENTICATED; | ||
| case AEPAuthenticatedStateLoggedOut: | ||
| return LOGGED_OUT; | ||
| default: | ||
| return AMBIGUOUS; | ||
| } | ||
| } | ||
|
|
||
| @end | ||
Uh oh!
There was an error while loading. Please reload this page.