Skip to content

Commit

Permalink
Factor out price parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ricealexanderb committed Jan 26, 2024
1 parent ad753ef commit 9a2b83f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 8 additions & 1 deletion Source/BidMachineAdapterAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ class BidMachineAdapterAd: NSObject {

/// The completion for the ongoing show operation.
var showCompletion: ((Result<PartnerEventDetails, Error>) -> Void)?


/// Waterfall item price
var price: Double? {
let setting = self.request.partnerSettings["price"]
let priceNSNum = setting as? NSNumber
return priceNSNum?.doubleValue
}

init(adapter: PartnerAdapter, request: PartnerAdLoadRequest, delegate: PartnerAdDelegate) {
self.adapter = adapter
self.request = request
Expand Down
4 changes: 1 addition & 3 deletions Source/BidMachineAdapterBannerAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class BidMachineAdapterBannerAd: BidMachineAdapterAd, PartnerAd {
config.populate { $0.withPayload(adm) }
} else {
config.populate {
let setting = self.request.partnerSettings["price"]
let priceNSNum = setting as? NSNumber
guard let price = priceNSNum?.doubleValue else {
guard let price else {
let error = error(.loadFailureInvalidAdRequest)
self.log(.loadFailed(error))
completion(.failure(error))
Expand Down
4 changes: 1 addition & 3 deletions Source/BidMachineAdapterInterstitialAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ final class BidMachineAdapterInterstitialAd: BidMachineAdapterAd, PartnerAd {
config.populate { $0.withPayload(adm) }
} else {
config.populate {
let setting = self.request.partnerSettings["price"]
let priceNSNum = setting as? NSNumber
guard let price = priceNSNum?.doubleValue else {
guard let price else {
let error = error(.loadFailureInvalidAdRequest)
self.log(.loadFailed(error))
completion(.failure(error))
Expand Down
4 changes: 1 addition & 3 deletions Source/BidMachineAdapterRewardedAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ final class BidMachineAdapterRewardedAd: BidMachineAdapterAd, PartnerAd {
config.populate { $0.withPayload(adm) }
} else {
config.populate {
let setting = self.request.partnerSettings["price"]
let priceNSNum = setting as? NSNumber
guard let price = priceNSNum?.doubleValue else {
guard let price else {
let error = error(.loadFailureInvalidAdRequest)
self.log(.loadFailed(error))
completion(.failure(error))
Expand Down

0 comments on commit 9a2b83f

Please sign in to comment.