Skip to content
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

Make Parsing Methods Type Safe #1040

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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 @@ -35,7 +35,7 @@ - (instancetype)initWithJsonDictionary:(PBMJsonDictionary *)jsonDictionary {
_targeting = jsonDictionary[@"targeting"];
_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