Skip to content

Commit

Permalink
prebid#8 Some initial correct-looking impl and test for MakeBids
Browse files Browse the repository at this point in the history
  • Loading branch information
Neale Upstone authored and nealeu committed Feb 12, 2019
1 parent 0831344 commit f98e84f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
56 changes: 39 additions & 17 deletions adapters/consumable/consumable.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ type user struct {
Key string `json:"key,omitempty"`
}

type bidResponse struct {
Decisions map[string]decision `json:"decisions"` // map by bidId
}

type decision struct {
Pricing *pricing `json:"pricing"`
AdID *string `json:"adId"`
}

type pricing struct {
ClearPrice *float64 `json:"clearPrice"`
}

func (a *ConsumableAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
headers := http.Header{
"Content-Type": {"application/json"},
Expand Down Expand Up @@ -135,7 +148,7 @@ func (a *ConsumableAdapter) MakeBids(
}}
}

var serverResponse openrtb.BidResponse // response from Consumable
var serverResponse bidResponse // response from Consumable
if err := json.Unmarshal(response.Body, &serverResponse); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("error while decoding response, err: %s", err),
Expand All @@ -145,23 +158,32 @@ func (a *ConsumableAdapter) MakeBids(
bidderResponse := adapters.NewBidderResponse()
var errors []error

for _, sb := range serverResponse.SeatBid {
for _, bid := range sb.Bid {

imp := getImp(bid.ImpID, internalRequest.Imp)
if imp == nil {
errors = append(errors, &errortypes.BadServerResponse{
Message: fmt.Sprintf("ignoring bid id=%s, request doesn't contain any impression with id=%s", bid.ID, bid.ImpID),
})
continue
}
for impID, decision := range serverResponse.Decisions { // TODO: I don't think this is by impId impID
println("ImpID: ", impID, " Decision: ", *decision.Pricing.ClearPrice)
imp := getImp(impID, internalRequest.Imp)
if imp == nil {
errors = append(errors, &errortypes.BadServerResponse{
Message: fmt.Sprintf("ignoring bid id=%s, request doesn't contain any impression with id=%s", "TODO: bid.ID", impID),
})
fmt.Printf("%s", errors[0])
continue
}

if bid.Price != 0 {
bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: getMediaTypeForImp(getImp(bid.ImpID, internalRequest.Imp)),
})
}
if decision.Pricing != nil && decision.Pricing.ClearPrice != nil {

bid := openrtb.Bid{}
bid.ImpID = impID
bid.Price = *decision.Pricing.ClearPrice
bid.AdM = "the ad markup"
bid.W = imp.Banner.Format[0].W // TODO: Review to check if this is correct behaviour
bid.H = imp.Banner.Format[0].H
bid.CrID = *decision.AdID // creative id ... to assist with quality checking
bid.Exp = 30 // TODO: Check this is intention of TTL

bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: getMediaTypeForImp(getImp(bid.ImpID, internalRequest.Imp)),
})
}
}

Expand Down
13 changes: 11 additions & 2 deletions adapters/consumable/consumable/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"mockResponse": {
"status": 200,
"body": {
"decisions": {
"test-imp-id": {
"adId": "crid-consumable",
"pricing": {
"clearPrice": 0.5
}
}
}
}
}
}
Expand All @@ -41,8 +49,9 @@
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"crid": "crid_10",
"adm": "the ad markup",
"crid": "crid-consumable",
"exp": 30,
"w": 728,
"h": 90
},
Expand Down

0 comments on commit f98e84f

Please sign in to comment.