diff --git a/adapters/grid/grid.go b/adapters/grid/grid.go index 3e38edd4578..dd18d52d95a 100644 --- a/adapters/grid/grid.go +++ b/adapters/grid/grid.go @@ -15,11 +15,53 @@ type GridAdapter struct { endpoint string } +func processImp(imp *openrtb.Imp) error { + // get the grid extension + var ext adapters.ExtImpBidder + var gridExt openrtb_ext.ExtImpGrid + if err := json.Unmarshal(imp.Ext, &ext); err != nil { + return err + } + if err := json.Unmarshal(ext.Bidder, &gridExt); err != nil { + return err + } + + if gridExt.Uid == 0 { + err := &errortypes.BadInput{ + Message: "uid is empty", + } + return err + } + // no error + return nil +} + // MakeRequests makes the HTTP requests which should be made to fetch bids. func (a *GridAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var errors = make([]error, 0) - reqJSON, err := json.Marshal(request) + // copy the request, because we are going to mutate it + requestCopy := *request + // this will contain all the valid impressions + var validImps []openrtb.Imp + // pre-process the imps + for _, imp := range requestCopy.Imp { + if err := processImp(&imp); err == nil { + validImps = append(validImps, imp) + } else { + errors = append(errors, err) + } + } + if len(validImps) == 0 { + err := &errortypes.BadInput{ + Message: "No valid impressions for grid", + } + errors = append(errors, err) + return nil, errors + } + requestCopy.Imp = validImps + + reqJSON, err := json.Marshal(requestCopy) if err != nil { errors = append(errors, err) return nil, errors diff --git a/adapters/grid/gridtest/exemplary/simple-banner.json b/adapters/grid/gridtest/exemplary/simple-banner.json index b098a94f9ba..1a5ea014d0f 100644 --- a/adapters/grid/gridtest/exemplary/simple-banner.json +++ b/adapters/grid/gridtest/exemplary/simple-banner.json @@ -13,7 +13,9 @@ }] }, "ext": { - "bidder": {} + "bidder": { + "uid": 1 + } } }] }, @@ -35,7 +37,9 @@ }] }, "ext": { - "bidder": {} + "bidder": { + "uid": 1 + } } }] } diff --git a/adapters/grid/gridtest/exemplary/simple-video.json b/adapters/grid/gridtest/exemplary/simple-video.json index fcf783da2a4..12c3771d1b2 100644 --- a/adapters/grid/gridtest/exemplary/simple-video.json +++ b/adapters/grid/gridtest/exemplary/simple-video.json @@ -13,7 +13,9 @@ "h": 250 }, "ext": { - "bidder": {} + "bidder": { + "uid": 1 + } } }] }, @@ -35,7 +37,9 @@ "h": 250 }, "ext": { - "bidder": {} + "bidder": { + "uid": 1 + } } }] } diff --git a/adapters/grid/gridtest/params/race/banner.json b/adapters/grid/gridtest/params/race/banner.json index 0967ef424bc..7e347f11b45 100644 --- a/adapters/grid/gridtest/params/race/banner.json +++ b/adapters/grid/gridtest/params/race/banner.json @@ -1 +1,4 @@ -{} +{ + "uid": 1 +} + diff --git a/adapters/grid/gridtest/supplemental/bad_bidder_request.json b/adapters/grid/gridtest/supplemental/bad_bidder_request.json new file mode 100644 index 00000000000..347a3091a41 --- /dev/null +++ b/adapters/grid/gridtest/supplemental/bad_bidder_request.json @@ -0,0 +1,33 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": "some not exist" + } + } + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "json: cannot unmarshal string into Go value of type openrtb_ext.ExtImpGrid", + "comparison": "literal" + }, + { + "value": "No valid impressions for grid", + "comparison": "literal" + } + ], + "httpCalls":[], + "expectedBidResponses": [] +} diff --git a/adapters/grid/gridtest/supplemental/bad_ext_request.json b/adapters/grid/gridtest/supplemental/bad_ext_request.json new file mode 100644 index 00000000000..789db8504f8 --- /dev/null +++ b/adapters/grid/gridtest/supplemental/bad_ext_request.json @@ -0,0 +1,30 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": "any" + } + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "json: cannot unmarshal string into Go value of type adapters.ExtImpBidder", + "comparison": "literal" + }, + { + "value": "No valid impressions for grid", + "comparison": "literal" + } + ], + "httpCalls": [] +} diff --git a/adapters/grid/gridtest/supplemental/bad_response.json b/adapters/grid/gridtest/supplemental/bad_response.json index 4ad5c09cf37..87436da7fc1 100644 --- a/adapters/grid/gridtest/supplemental/bad_response.json +++ b/adapters/grid/gridtest/supplemental/bad_response.json @@ -14,6 +14,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } @@ -39,6 +40,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } diff --git a/adapters/grid/gridtest/supplemental/empty_uid_request.json b/adapters/grid/gridtest/supplemental/empty_uid_request.json new file mode 100644 index 00000000000..ff389899788 --- /dev/null +++ b/adapters/grid/gridtest/supplemental/empty_uid_request.json @@ -0,0 +1,33 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": {} + } + } + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "uid is empty", + "comparison": "literal" + }, + { + "value": "No valid impressions for grid", + "comparison": "literal" + } + ], + "httpCalls":[], + "expectedBidResponses": [] +} diff --git a/adapters/grid/gridtest/supplemental/no_imp_request.json b/adapters/grid/gridtest/supplemental/no_imp_request.json new file mode 100644 index 00000000000..5e261647fb5 --- /dev/null +++ b/adapters/grid/gridtest/supplemental/no_imp_request.json @@ -0,0 +1,13 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [] + }, + "expectedMakeRequestsErrors": [ + { + "value": "No valid impressions for grid", + "comparison": "literal" + } + ], + "httpCalls":[] +} diff --git a/adapters/grid/gridtest/supplemental/status_204.json b/adapters/grid/gridtest/supplemental/status_204.json index 906d8553bc6..f935cbe85ae 100644 --- a/adapters/grid/gridtest/supplemental/status_204.json +++ b/adapters/grid/gridtest/supplemental/status_204.json @@ -14,6 +14,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } @@ -39,6 +40,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } diff --git a/adapters/grid/gridtest/supplemental/status_400.json b/adapters/grid/gridtest/supplemental/status_400.json index dbf2a4d7b2b..629b1c07bd7 100644 --- a/adapters/grid/gridtest/supplemental/status_400.json +++ b/adapters/grid/gridtest/supplemental/status_400.json @@ -14,6 +14,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } @@ -39,6 +40,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } diff --git a/adapters/grid/gridtest/supplemental/status_418.json b/adapters/grid/gridtest/supplemental/status_418.json index 7619cd6aec1..0ca365c76ce 100644 --- a/adapters/grid/gridtest/supplemental/status_418.json +++ b/adapters/grid/gridtest/supplemental/status_418.json @@ -14,6 +14,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } @@ -39,6 +40,7 @@ }, "ext": { "bidder": { + "uid": 1 } } } diff --git a/openrtb_ext/imp_grid.go b/openrtb_ext/imp_grid.go new file mode 100644 index 00000000000..d38e610d7a5 --- /dev/null +++ b/openrtb_ext/imp_grid.go @@ -0,0 +1,6 @@ +package openrtb_ext + +// ExtImpGrid defines the contract for bidrequest.imp[i].ext.grid +type ExtImpGrid struct { + Uid int `json:"uid"` +} diff --git a/static/bidder-params/grid.json b/static/bidder-params/grid.json index 7a0cf3da8c5..67f9b12f115 100644 --- a/static/bidder-params/grid.json +++ b/static/bidder-params/grid.json @@ -3,6 +3,11 @@ "title": "TheMediaGrid Adapter Params", "description": "A schema which validates params accepted by TheMediaGrid adapter", "type": "object", - "properties": {}, + "properties": { + "uid": { + "type": "integer", + "description": "An ID which identifies this placement of the impression" + } + }, "required": [] }