Skip to content

Commit f2eee35

Browse files
use new impl
1 parent bc2e94a commit f2eee35

File tree

5 files changed

+354
-220
lines changed

5 files changed

+354
-220
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ serde_json = { workspace = true }
4242
sha2 = { workspace = true }
4343
tokio = { workspace = true }
4444
trusted-server-js = { path = "../js" }
45+
trusted-server-openrtb = { path = "../openrtb" }
4546
url = { workspace = true }
4647
urlencoding = { workspace = true }
4748
uuid = { workspace = true }

crates/common/src/auction/formats.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::auction::types::OrchestratorExt;
1616
use crate::creative;
1717
use crate::error::TrustedServerError;
1818
use crate::geo::GeoInfo;
19-
use crate::openrtb::{OpenRtbBid, OpenRtbResponse, ResponseExt, SeatBid};
19+
use crate::openrtb::{
20+
build_openrtb_bid, build_openrtb_response, build_seat_bid, maybe_object_from_serializable,
21+
OpenRtbBidFields, ResponseExt,
22+
};
2023
use crate::settings::Settings;
2124
use crate::synthetic::{generate_synthetic_id, get_or_generate_synthetic_id};
2225

@@ -206,21 +209,18 @@ pub fn convert_to_openrtb_response(
206209
String::new()
207210
};
208211

209-
let openrtb_bid = OpenRtbBid {
212+
let openrtb_bid = build_openrtb_bid(OpenRtbBidFields {
210213
id: format!("{}-{}", bid.bidder, slot_id),
211214
impid: slot_id.to_string(),
212215
price,
213216
adm: Some(creative_html),
214217
crid: Some(format!("{}-creative", bid.bidder)),
215-
w: Some(bid.width),
216-
h: Some(bid.height),
218+
width: Some(bid.width),
219+
height: Some(bid.height),
217220
adomain: Some(bid.adomain.clone().unwrap_or_default()),
218-
};
219-
220-
seatbids.push(SeatBid {
221-
seat: Some(bid.bidder.clone()),
222-
bid: vec![openrtb_bid],
223221
});
222+
223+
seatbids.push(build_seat_bid(Some(bid.bidder.clone()), vec![openrtb_bid]));
224224
}
225225

226226
// Determine strategy name for response metadata
@@ -230,18 +230,18 @@ pub fn convert_to_openrtb_response(
230230
"parallel_only"
231231
};
232232

233-
let response_body = OpenRtbResponse {
234-
id: auction_request.id.to_string(),
235-
seatbid: seatbids,
236-
ext: Some(ResponseExt {
233+
let response_body = build_openrtb_response(
234+
auction_request.id.to_string(),
235+
seatbids,
236+
maybe_object_from_serializable(&ResponseExt {
237237
orchestrator: OrchestratorExt {
238238
strategy: strategy_name.to_string(),
239239
providers: result.provider_responses.len(),
240240
total_bids: result.total_bids(),
241241
time_ms: result.total_time_ms,
242242
},
243243
}),
244-
};
244+
);
245245

246246
let body_bytes =
247247
serde_json::to_vec(&response_body).change_context(TrustedServerError::Auction {

crates/common/src/integrations/prebid.rs

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use crate::integrations::{
2222
IntegrationEndpoint, IntegrationProxy, IntegrationRegistration,
2323
};
2424
use crate::openrtb::{
25-
Banner, Device, Format, Geo, Imp, ImpExt, OpenRtbRequest, PrebidExt, PrebidImpExt, Regs,
26-
RegsExt, RequestExt, Site, TrustedServerExt, User, UserExt,
25+
build_banner, build_device, build_format, build_geo, build_imp, build_openrtb_request,
26+
build_regs, build_site, build_user, maybe_object_from_serializable, ImpExt, OpenRtbRequest,
27+
PrebidExt, PrebidImpExt, RegsExt, RequestExt, TrustedServerExt, UserExt,
2728
};
2829
use crate::request_signing::RequestSigner;
2930
use crate::settings::{IntegrationConfig, Settings};
@@ -396,18 +397,15 @@ impl PrebidAuctionProvider {
396397
context: &AuctionContext<'_>,
397398
signer: Option<(&RequestSigner, String)>,
398399
) -> OpenRtbRequest {
399-
let imps: Vec<Imp> = request
400+
let imps = request
400401
.slots
401402
.iter()
402403
.map(|slot| {
403-
let formats: Vec<Format> = slot
404+
let formats = slot
404405
.formats
405406
.iter()
406407
.filter(|f| f.media_type == MediaType::Banner)
407-
.map(|f| Format {
408-
w: f.width,
409-
h: f.height,
410-
})
408+
.map(|f| build_format(f.width, f.height))
411409
.collect();
412410

413411
// Use bidder params from the slot (passed through from the request)
@@ -424,13 +422,13 @@ impl PrebidAuctionProvider {
424422
}
425423
}
426424

427-
Imp {
428-
id: slot.id.clone(),
429-
banner: Some(Banner { format: formats }),
430-
ext: Some(ImpExt {
425+
build_imp(
426+
slot.id.clone(),
427+
Some(build_banner(formats)),
428+
maybe_object_from_serializable(&ImpExt {
431429
prebid: PrebidImpExt { bidder },
432430
}),
433-
}
431+
)
434432
})
435433
.collect();
436434

@@ -444,31 +442,32 @@ impl PrebidAuctionProvider {
444442
});
445443

446444
// Build user object
447-
let user = Some(User {
448-
id: Some(request.user.id.clone()),
449-
ext: Some(UserExt {
445+
let user = Some(build_user(
446+
Some(request.user.id.clone()),
447+
maybe_object_from_serializable(&UserExt {
450448
synthetic_fresh: Some(request.user.fresh_id.clone()),
451449
}),
452-
});
450+
));
453451

454452
// Build device object with user-agent and geo if available
455-
let device = request.device.as_ref().map(|d| Device {
456-
ua: d.user_agent.clone(),
457-
geo: d.geo.as_ref().map(|geo| Geo {
458-
geo_type: 2, // IP address per OpenRTB spec
459-
country: Some(geo.country.clone()),
460-
city: Some(geo.city.clone()),
461-
region: geo.region.clone(),
462-
}),
453+
let device = request.device.as_ref().map(|d| {
454+
build_device(
455+
d.user_agent.clone(),
456+
d.geo.as_ref().map(|geo| {
457+
build_geo(
458+
Some(geo.country.clone()),
459+
Some(geo.city.clone()),
460+
geo.region.clone(),
461+
)
462+
}),
463+
)
463464
});
464465

465466
// Build regs object if Sec-GPC header is present
466467
let regs = if context.request.get_header("Sec-GPC").is_some() {
467-
Some(Regs {
468-
ext: Some(RegsExt {
469-
us_privacy: Some("1YYN".to_string()),
470-
}),
471-
})
468+
Some(build_regs(maybe_object_from_serializable(&RegsExt {
469+
us_privacy: Some("1YYN".to_string()),
470+
})))
472471
} else {
473472
None
474473
};
@@ -479,7 +478,7 @@ impl PrebidAuctionProvider {
479478
.map(|(s, sig)| (Some(sig), Some(s.kid.clone())))
480479
.unwrap_or((None, None));
481480

482-
let ext = Some(RequestExt {
481+
let ext = maybe_object_from_serializable(&RequestExt {
483482
prebid: if self.config.debug {
484483
Some(PrebidExt { debug: Some(true) })
485484
} else {
@@ -493,18 +492,15 @@ impl PrebidAuctionProvider {
493492
}),
494493
});
495494

496-
OpenRtbRequest {
497-
id: request.id.clone(),
498-
imp: imps,
499-
site: Some(Site {
500-
domain: Some(request.publisher.domain.clone()),
501-
page: page_url,
502-
}),
495+
build_openrtb_request(
496+
request.id.clone(),
497+
imps,
498+
Some(build_site(Some(request.publisher.domain.clone()), page_url)),
503499
user,
504500
device,
505501
regs,
506502
ext,
507-
}
503+
)
508504
}
509505

510506
/// Parse `OpenRTB` response into auction response.

0 commit comments

Comments
 (0)