Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Update required params for TheMediaGrid adapter (prebid#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMediaGrid authored Mar 9, 2020
1 parent fd2cdab commit 1c5504b
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 7 deletions.
44 changes: 43 additions & 1 deletion adapters/grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions adapters/grid/gridtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
}]
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
},
Expand All @@ -35,7 +37,9 @@
}]
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
}
Expand Down
8 changes: 6 additions & 2 deletions adapters/grid/gridtest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"h": 250
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
},
Expand All @@ -35,7 +37,9 @@
"h": 250
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
}
Expand Down
5 changes: 4 additions & 1 deletion adapters/grid/gridtest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{}
{
"uid": 1
}

33 changes: 33 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_bidder_request.json
Original file line number Diff line number Diff line change
@@ -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": []
}
30 changes: 30 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_ext_request.json
Original file line number Diff line number Diff line change
@@ -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": []
}
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions adapters/grid/gridtest/supplemental/empty_uid_request.json
Original file line number Diff line number Diff line change
@@ -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": []
}
13 changes: 13 additions & 0 deletions adapters/grid/gridtest/supplemental/no_imp_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": []
},
"expectedMakeRequestsErrors": [
{
"value": "No valid impressions for grid",
"comparison": "literal"
}
],
"httpCalls":[]
}
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_204.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_400.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_418.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions openrtb_ext/imp_grid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package openrtb_ext

// ExtImpGrid defines the contract for bidrequest.imp[i].ext.grid
type ExtImpGrid struct {
Uid int `json:"uid"`
}
7 changes: 6 additions & 1 deletion static/bidder-params/grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}

0 comments on commit 1c5504b

Please sign in to comment.