Skip to content

Commit

Permalink
feat: remove isSupportRendering
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaPostindustria committed Dec 10, 2024
1 parent e8004f8 commit 3f2d806
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

NS_ASSUME_NONNULL_BEGIN

/// A custom implementation of the ad view renderer.
/// A custom implementation of the renderer.
@interface SampleRenderer : NSObject <PrebidMobilePluginRenderer>

- (instancetype)init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ - (instancetype)init {
return self;
}

- (BOOL)isSupportRenderingFor:(AdFormat *)format {
return [@[AdFormat.banner, AdFormat.video] containsObject:format];
}

- (UIView<PrebidMobileDisplayViewProtocol> * _Nullable)createBannerViewWith:(CGRect)frame
bid:(Bid * _Nonnull)bid
adConfiguration:(AdUnitConfig * _Nonnull)adConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
import UIKit
import PrebidMobile

/// A custom implementation of the ad view renderer.
/// A custom implementation of the renderer.
public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {

public let name = "SampleRenderer"
public let version = "1.0.0"
public var data: [String: Any]?

public func isSupportRendering(for format: PrebidMobile.AdFormat?) -> Bool {
[PrebidMobile.AdFormat.banner, PrebidMobile.AdFormat.video].contains(format)
}

/// This method creates an instance of `SampleAdView`, which is a custom view used to display the ad.
public func createBannerView(
with frame: CGRect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {
public let version = "1.0.0"
public var data: [String: Any]?

public func isSupportRendering(for format: AdFormat?) -> Bool {
[AdFormat.banner, AdFormat.video].contains(format)
}

public func createBannerView(
with frame: CGRect,
bid: Bid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,13 @@ public class PrebidMobilePluginRegister: NSObject {
}
}

/// Returns the list of available renderers for the given ad unit for RTB request
public func getRTBListOfRenderersFor(for adUnitConfig: AdUnitConfig) -> [PrebidMobilePluginRenderer] {
queue.sync {
plugins
.values
.filter { renderer in
adUnitConfig.adFormats.contains { format in
renderer.isSupportRendering(for: format)
}
}
}
}

/// Returns the registered renderer according to the preferred renderer name in the bid response.
/// If no preferred renderer is found, it returns PrebidRenderer to perform default behavior.
/// Once bid is win we want to resolve the best PluginRenderer candidate to render the ad.
public func getPluginForPreferredRenderer(bid: Bid) -> PrebidMobilePluginRenderer {
guard let preferredRendererName = bid.pluginRendererName,
let preferredPlugin = getPluginRenderer(for: preferredRendererName),
preferredPlugin.version == bid.pluginRendererVersion,
preferredPlugin.isSupportRendering(for: bid.adFormat)
preferredPlugin.version == bid.pluginRendererVersion
else {
return defaultRenderer
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ public protocol PrebidMobilePluginRenderer: AnyObject {
/// The version of the plugin renderer.
@objc var version: String { get }

/// The version of the plugin renderer.
/// Custom data to be included in the ORTB request.
@objc var data: [String: Any]? { get }

/// Returns true only if the given ad unit could be renderer by the plugin.
@objc func isSupportRendering(for format: AdFormat?) -> Bool

/// Register a listener related to a specific ad unit config fingerprint in order to dispatch specific ad events.
@objc optional func registerEventDelegate(
pluginEventDelegate: PluginEventDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ - (void)createPrebidAdWithBid:(Bid *)bid
adUnitConfig:(AdUnitConfig *)adUnitConfig
adObjectSaver:(void (^)(id))adObjectSaver
loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker {
@weakify(self);
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
if (!self) { return; }

UIView <PrebidMobileDisplayViewProtocol> * displayView = [self createBannerViewWithBid:bid
adUnitConfig:adUnitConfig];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ - (void)createPrebidAdWithBid:(Bid *)bid
adUnitConfig:(AdUnitConfig *)adUnitConfig
adObjectSaver:(void (^)(id))adObjectSaver
loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker {
@weakify(self);
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
if (!self) { return; }

id<PrebidMobileInterstitialControllerProtocol> controller = [self createInterstitialControllerWithBid:bid
adUnitConfig:adUnitConfig];
adObjectSaver(controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public class PrebidRenderer: NSObject, PrebidMobilePluginRenderer {
public let version = Prebid.shared.version
public var data: [String: Any]?

public func isSupportRendering(for format: AdFormat?) -> Bool {
[AdFormat.banner, AdFormat.video].contains(format)
}

public func createBannerView(
with frame: CGRect,
bid: Bid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ class MockPrebidMobilePluginRenderer: PrebidMobilePluginRenderer {
self.data = data
}

func isSupportRendering(for format: AdFormat?) -> Bool {
guard !formats.isEmpty else { return true }

if let format {
return formats.contains(format)
} else {
return true
}
}

func jsonDictionary() -> [String: Any] {
var json: [String: Any] = ["name": name, "version": version]
json["data"] = data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,4 @@ class PluginRegisterTest: XCTestCase {
XCTAssertEqual(pluginRenderer.name, plugin.name)
XCTAssertEqual(pluginRenderer.version, plugin.version)
}

func testGetRTBListOfRenderersFor() {
plugin.formats = [.banner, .video]

let adUnitConfigBanner = AdUnitConfig(
configId: "configID",
size: CGSize(width: 300, height: 250)
)

var renderers = prebidMobilePluginRegister
.getRTBListOfRenderersFor(for: adUnitConfigBanner)
XCTAssertEqual(1, renderers.count)

let adUnitConfigError = AdUnitConfig(configId: "configID")
adUnitConfigError.adFormats = [.native]

renderers = prebidMobilePluginRegister
.getRTBListOfRenderersFor(for: adUnitConfigError)
XCTAssertEqual(0, renderers.count)
}
}

0 comments on commit 3f2d806

Please sign in to comment.