Skip to content

Commit

Permalink
Make Parsing Methods Type Safe (#1040)
Browse files Browse the repository at this point in the history
* Make type safe

* Type check before init

* Check for passthrough response type

* Remove Unnecessary change

* Update PrebidMobile/PrebidMobileRendering/Utilities/PBMFunctions.m

Co-authored-by: David Robles <[email protected]>

* Update PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/ORTB/Prebid/PBMORTBBidExt.m

Co-authored-by: David Robles <[email protected]>

* Update PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/ORTB/Prebid/PBMORTBBidExtPrebid.m

Co-authored-by: David Robles <[email protected]>

* Update PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/ORTB/Prebid/PBMORTBBidResponseExtPrebid.m

Co-authored-by: David Robles <[email protected]>

---------

Co-authored-by: Ankit Rajendra Thanekar <[email protected]>
Co-authored-by: David Robles <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 424c60d commit c04a415
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ - (instancetype)initWithJsonDictionary:(PBMJsonDictionary *)jsonDictionary {
}

#if DEBUG
NSArray * const passthroughDics = jsonDictionary[@"passthrough"];

NSArray<PBMJsonDictionary *> *const passthroughDics = [PBMFunctions dictionariesForPassthrough:jsonDictionary[@"passthrough"]];
_passthrough = nil;
if (passthroughDics) {
NSMutableArray * const newPassthrough = [[NSMutableArray alloc] initWithCapacity:passthroughDics.count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (instancetype)initWithJsonDictionary:(PBMJsonDictionary *)jsonDictionary {
_meta = jsonDictionary[@"meta"];
_type = jsonDictionary[@"type"];

NSArray * const passthroughDics = jsonDictionary[@"passthrough"];
NSArray<PBMJsonDictionary *> *const passthroughDics = [PBMFunctions dictionariesForPassthrough:jsonDictionary[@"passthrough"]];
_passthrough = nil;
if (passthroughDics) {
NSMutableArray * const newPassthrough = [[NSMutableArray alloc] initWithCapacity:passthroughDics.count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ - (instancetype)initWithJsonDictionary:(PBMJsonDictionary *)jsonDictionary {
return nil;
}

NSArray * const passthroughDics = jsonDictionary[@"passthrough"];
NSArray<PBMJsonDictionary *> *const passthroughDics = [PBMFunctions dictionariesForPassthrough:jsonDictionary[@"passthrough"]];
_passthrough = nil;
if (passthroughDics) {
NSMutableArray * const newPassthrough = [[NSMutableArray alloc] initWithCapacity:passthroughDics.count];
Expand Down
3 changes: 2 additions & 1 deletion PrebidMobile/PrebidMobileRendering/Utilities/PBMFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PBMConstants.h"

NS_ASSUME_NONNULL_BEGIN
@interface PBMFunctions : NSObject
Expand All @@ -24,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSDictionary<NSString *, NSString *> *)extractVideoAdParamsFromTheURLString:(NSString *)urlString forKeys:(NSArray *)keys;
+ (BOOL)canLoadVideoAdWithDomain:(NSString *)domain adUnitID:(nullable NSString *)adUnitID adUnitGroupID:(nullable NSString *)adUnitGroupID;
+ (void)checkCertificateChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler;

+ (nullable NSArray<PBMJsonDictionary *> *)dictionariesForPassthrough:(id)passthrough;
//FIXME: move to private fucntions ??
#pragma mark - SDK Info

Expand Down
13 changes: 12 additions & 1 deletion PrebidMobile/PrebidMobileRendering/Utilities/PBMFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "PBMFunctions+Private.h"
#import "PBMFunctions+Testing.h"

#import "PBMConstants.h"
#import "PBMError.h"

#import "PrebidMobileSwiftHeaders.h"
Expand Down Expand Up @@ -231,6 +230,18 @@ + (nullable NSString *)toStringJsonDictionary:(nonnull PBMJsonDictionary *)jsonD
return [jsonString stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
}

+ (nullable NSArray<PBMJsonDictionary *> *)dictionariesForPassthrough:(id)passthrough {
if ([passthrough isKindOfClass:[NSArray<PBMJsonDictionary*> class]]) {
NSArray<PBMJsonDictionary *> *response = passthrough;
return response;
} else if ([passthrough isKindOfClass:[PBMJsonDictionary class]]) {
NSDictionary *response = passthrough;
return @[response];
} else {
return nil;
}
}

#pragma mark - SDK Info

+ (nonnull NSBundle *)bundleForSDK {
Expand Down

0 comments on commit c04a415

Please sign in to comment.