Skip to content

Commit

Permalink
Fix context data structure (#688)
Browse files Browse the repository at this point in the history
* fix context data structure

* move import
  • Loading branch information
marcelklinek authored Oct 31, 2022
1 parent 1ad2e39 commit f85eacd
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 20 deletions.
6 changes: 6 additions & 0 deletions PrebidMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
606FAC5222022932008EAE5E /* AdUnitSwizzleHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 606FAC5122022932008EAE5E /* AdUnitSwizzleHelper.swift */; };
60C0381F2204AF5D0082B32C /* DispatcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979177962201AF5F00E624CE /* DispatcherTests.swift */; };
60C038242204AF5D0082B32C /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97826AA621FB4F1B001E2C05 /* Constants.swift */; };
799109FB28F99C2B004837B4 /* PBMORTBAppExt.m in Sources */ = {isa = PBXBuildFile; fileRef = 799109FA28F99C2B004837B4 /* PBMORTBAppExt.m */; };
92028EA627F0D89E00783470 /* NativeAdConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92028EA527F0D89E00783470 /* NativeAdConfiguration.swift */; };
920E8D6D28084BF200E6313B /* VideoControlsConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920E8D6C28084BF200E6313B /* VideoControlsConfigTests.swift */; };
922AFC61273491F000732C53 /* PBMLocationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5BC376BC271F1CFE00444D5E /* PBMLocationManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -1365,6 +1366,8 @@
60C0382B2204BB190082B32C /* PrebidMobileTest-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PrebidMobileTest-Bridging-Header.h"; sourceTree = "<group>"; };
60D792FB217E229B0080F428 /* PrebidMobileTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PrebidMobileTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
60D79302217E229B0080F428 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
799109FA28F99C2B004837B4 /* PBMORTBAppExt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PBMORTBAppExt.m; sourceTree = "<group>"; };
799109FC28F99C7D004837B4 /* PBMORTBAppExt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBMORTBAppExt.h; sourceTree = "<group>"; };
92028EA527F0D89E00783470 /* NativeAdConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAdConfiguration.swift; sourceTree = "<group>"; };
920E8D6C28084BF200E6313B /* VideoControlsConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoControlsConfigTests.swift; sourceTree = "<group>"; };
922AFC8727352B0100732C53 /* MockUserAgentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUserAgentService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1960,6 +1963,8 @@
5BC37678271F1CFD00444D5E /* PBMORTBUser.m */,
5BC3768B271F1CFD00444D5E /* PBMORTBVideo.h */,
5BC376A4271F1CFD00444D5E /* PBMORTBVideo.m */,
799109FA28F99C2B004837B4 /* PBMORTBAppExt.m */,
799109FC28F99C7D004837B4 /* PBMORTBAppExt.h */,
);
path = ORTB;
sourceTree = "<group>";
Expand Down Expand Up @@ -4083,6 +4088,7 @@
5BC37A90271F1D0000444D5E /* InterstitialAdUnitDelegate.swift in Sources */,
5BC37A88271F1D0000444D5E /* RewardedAdUnitDelegate.swift in Sources */,
5BC378DB271F1CFF00444D5E /* PBMORTBDeal.m in Sources */,
799109FB28F99C2B004837B4 /* PBMORTBAppExt.m in Sources */,
925A641627317A39009E72F9 /* HiddenWebViewManager.swift in Sources */,
5BC3796C271F1D0000444D5E /* PBMVastCreativeLinear.m in Sources */,
928E5A7027F0F743000ADA1A /* ContextSubType.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions PrebidMobile/PrebidMobileRendering/ORTB/PBMORTBApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#import "PBMORTBAbstract.h"

@class PBMORTBPublisher;
@class PBMORTBAppExtPrebid;
@class PBMORTBAppExt;
@class PBMORTBAppContent;

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN

//Placeholder for exchange-specific extensions to OpenRTB.
//Note: ext is not supported.
@property (nonatomic, strong) PBMORTBAppExtPrebid *extPrebid;
@property (nonatomic, strong) PBMORTBAppExt *ext;

- (instancetype )init;

Expand Down
12 changes: 4 additions & 8 deletions PrebidMobile/PrebidMobileRendering/ORTB/PBMORTBApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "PBMORTBAbstract+Protected.h"

#import "PBMORTBPublisher.h"
#import "PBMORTBAppExtPrebid.h"
#import "PBMORTBAppExt.h"
#import "PBMORTBAppContent.h"

@implementation PBMORTBApp
Expand All @@ -30,7 +30,7 @@ - (nonnull instancetype )init {
_sectioncat = @[];
_pagecat = @[];
_publisher = [[PBMORTBPublisher alloc] init];
_extPrebid = [[PBMORTBAppExtPrebid alloc] init];
_ext = [[PBMORTBAppExt alloc] init];
_content = [[PBMORTBAppContent alloc] init];

return self;
Expand Down Expand Up @@ -62,11 +62,7 @@ - (nonnull PBMJsonDictionary *)toJsonDictionary {
ret[@"keywords"] = self.keywords;
ret[@"publisher"] = [[self.publisher toJsonDictionary] nullIfEmpty];
ret[@"content"] = [[self.content toJsonDictionary] nullIfEmpty];

PBMJsonDictionary * const extPrebidDic = [self.extPrebid toJsonDictionary];
if (extPrebidDic.count) {
ret[@"ext"] = @{@"prebid": extPrebidDic};
}
ret[@"ext"] = [[self.ext toJsonDictionary] nullIfEmpty];

[ret pbmRemoveEmptyVals];

Expand All @@ -90,7 +86,7 @@ - (instancetype)initWithJsonDictionary:(nonnull PBMJsonDictionary *)jsonDictiona
_paid = jsonDictionary[@"paid"];
_publisher = [[PBMORTBPublisher alloc] initWithJsonDictionary:jsonDictionary[@"publisher"]];
_keywords = jsonDictionary[@"keywords"];
_extPrebid = [[PBMORTBAppExtPrebid alloc] initWithJsonDictionary:jsonDictionary[@"ext"][@"prebid"]];
_ext = [[PBMORTBAppExt alloc] initWithJsonDictionary:jsonDictionary[@"ext"]];
_content = [[PBMORTBAppContent alloc] initWithJsonDictionary:jsonDictionary[@"content"]];

return self;
Expand Down
35 changes: 35 additions & 0 deletions PrebidMobile/PrebidMobileRendering/ORTB/PBMORTBAppExt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*   Copyright 2018-2021 Prebid.org, Inc.
 Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import "PBMORTBAbstract.h"

@class PBMORTBAppExtPrebid;


NS_ASSUME_NONNULL_BEGIN

@interface PBMORTBAppExt : PBMORTBAbstract

@property (nonatomic, strong) PBMORTBAppExtPrebid *prebid;
@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSArray<NSString *> *> *data;

- (instancetype )init;




@end

NS_ASSUME_NONNULL_END
53 changes: 53 additions & 0 deletions PrebidMobile/PrebidMobileRendering/ORTB/PBMORTBAppExt.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*   Copyright 2018-2021 Prebid.org, Inc.
 Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import "PBMORTBAppExtPrebid.h"
#import "PBMORTBAppExt.h"
#import "PBMORTBAbstract+Protected.h"

@implementation PBMORTBAppExt

- (nonnull instancetype )init {
if (!(self = [super init])) {
return nil;
}

_prebid = [[PBMORTBAppExtPrebid alloc] init];

return self;
}

- (nonnull PBMJsonDictionary *)toJsonDictionary {
PBMMutableJsonDictionary *ret = [PBMMutableJsonDictionary new];
PBMJsonDictionary * const extPrebidDic = [self.prebid toJsonDictionary];
if (extPrebidDic.count) {
ret[@"prebid"] = extPrebidDic;
}

ret[@"data"] = self.data;
return ret;
}

- (instancetype)initWithJsonDictionary:(nonnull PBMJsonDictionary *)jsonDictionary {
if (!(self = [self init])) {
return nil;
}
_data = jsonDictionary[@"data"];
_prebid = [[PBMORTBAppExtPrebid alloc] initWithJsonDictionary:jsonDictionary[@"prebid"]];
return self;
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, copy, nullable) NSString *source;
@property (nonatomic, copy, nullable) NSString *version;
@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSArray<NSString *> *> *data;

@end

Expand Down
2 changes: 0 additions & 2 deletions PrebidMobile/PrebidMobileRendering/ORTB/PBMORTBAppExtPrebid.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ - (nonnull PBMJsonDictionary *)toJsonDictionary {
PBMMutableJsonDictionary *ret = [PBMMutableJsonDictionary new];
ret[@"source"] = self.source;
ret[@"version"] = self.version;
ret[@"data"] = self.data;
return ret;
}

Expand All @@ -32,7 +31,6 @@ - (instancetype)initWithJsonDictionary:(nonnull PBMJsonDictionary *)jsonDictiona
}
_source = jsonDictionary[@"source"];
_version = jsonDictionary[@"version"];
_data = jsonDictionary[@"data"];
return self;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "PBMWinNotifierBlock.h"

#import "PBMORTBAppContent.h"
#import "PBMORTBAppExt.h"

#import "PrebidMobileSwiftHeaders.h"
#import <PrebidMobile/PrebidMobile-Swift.h>
Expand Down Expand Up @@ -132,8 +133,9 @@ - (void)buildBidRequest:(nonnull PBMORTBBidRequest *)bidRequest {
bidRequest.user.data = userData;
}

PBMORTBAppExtPrebid * const appExtPrebid = bidRequest.app.extPrebid;
appExtPrebid.data = self.targeting.contextDataDictionary;
PBMORTBAppExt * const appExt = bidRequest.app.ext;
PBMORTBAppExtPrebid * const appExtPrebid = appExt.prebid;
appExt.data = self.targeting.contextDataDictionary;

for (PBMORTBImp *nextImp in bidRequest.imp) {
nextImp.impID = [NSUUID UUID].UUIDString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,17 @@ class PBMORTBAbstractTest : XCTestCase {

func testAppExtPrebidToJsonString() {
let pbmORTBApp = PBMORTBApp()
let appExtPrebid = pbmORTBApp.extPrebid
let appExtPrebid = pbmORTBApp.ext.prebid

codeAndDecode(abstract: appExtPrebid, expectedString: "{}")

appExtPrebid.source = "openx"
appExtPrebid.version = sdkVersion
appExtPrebid.data = ["app_categories": ["news", "movies"]]
pbmORTBApp.ext.data = ["app_categories": ["news", "movies"]]

codeAndDecode(abstract: appExtPrebid, expectedString: "{\"data\":{\"app_categories\":[\"news\",\"movies\"]},\"source\":\"openx\",\"version\":\"\(sdkVersion)\"}")
codeAndDecode(abstract: appExtPrebid, expectedString: "{\"source\":\"openx\",\"version\":\"\(sdkVersion)\"}")

codeAndDecode(abstract: pbmORTBApp, expectedString: "{\"ext\":{\"prebid\":{\"data\":{\"app_categories\":[\"news\",\"movies\"]},\"source\":\"openx\",\"version\":\"\(sdkVersion)\"}}}")
codeAndDecode(abstract: pbmORTBApp, expectedString: "{\"ext\":{\"data\":{\"app_categories\":[\"news\",\"movies\"]},\"prebid\":{\"source\":\"openx\",\"version\":\"\(sdkVersion)\"}}}")
}

func testDeviceWithIfaToJsonString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class PrebidParameterBuilderTest: XCTestCase {
XCTAssertEqual(2, objects.count)
XCTAssertEqual(objects.first, userDataObject1)

let extData = bidRequest.app.extPrebid.data!
let extData = bidRequest.app.ext.data!
XCTAssertTrue(extData.keys.count == 1)
let extValues = extData["last_search_keywords"]!.sorted()
XCTAssertEqual(extValues, ["pet", "wolf"])
Expand Down

0 comments on commit f85eacd

Please sign in to comment.