Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanivplaydigo committed Apr 25, 2024
1 parent 36dae66 commit b7b5e64
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
34 changes: 15 additions & 19 deletions adapters/playdigo/playdigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
continue
}

if adapterReq != nil {
adapterRequests = append(adapterRequests, adapterReq)
}
adapterRequests = append(adapterRequests, adapterReq)
}

if len(adapterRequests) == 0 {
Expand Down Expand Up @@ -129,7 +127,8 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R

for _, seatBid := range response.SeatBid {
for i := range seatBid.Bid {
bidType, err := getBidMediaType(&seatBid.Bid[i])
bid := seatBid.Bid[i]
bidType, err := getBidType(bid)
if err != nil {
return nil, []error{err}
}
Expand All @@ -144,21 +143,18 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
return bidResponse, nil
}

func getBidMediaType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) {
var extBid openrtb_ext.ExtBid
err := json.Unmarshal(bid.Ext, &extBid)
if err != nil {
return "", fmt.Errorf("unable to deserialize imp %v bid.ext, error: %v", bid.ImpID, err)
func getBidType(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
// determinate media type by bid response field mtype
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
}

if extBid.Prebid == nil {
return "", fmt.Errorf("imp %v with unknown media type", bid.ImpID)
}

switch extBid.Prebid.Type {
case openrtb_ext.BidTypeBanner, openrtb_ext.BidTypeVideo, openrtb_ext.BidTypeNative:
return extBid.Prebid.Type, nil
default:
return "", fmt.Errorf("invalid BidType: %s", extBid.Prebid.Type)
}
return "", fmt.Errorf("could not define media type for impression: %s", bid.ImpID)
}
2 changes: 2 additions & 0 deletions adapters/playdigo/playdigotest/exemplary/endpointId.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -118,6 +119,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down
4 changes: 4 additions & 0 deletions adapters/playdigo/playdigotest/exemplary/multi-imp.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -181,6 +182,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -210,6 +212,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand All @@ -233,6 +236,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down
2 changes: 2 additions & 0 deletions adapters/playdigo/playdigotest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -118,6 +119,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 300,
"h": 250,
"ext": {
Expand Down
2 changes: 2 additions & 0 deletions adapters/playdigo/playdigotest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 4,
"w": 300,
"h": 250,
"ext": {
Expand Down Expand Up @@ -102,6 +103,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 4,
"w": 300,
"h": 250,
"ext": {
Expand Down
2 changes: 2 additions & 0 deletions adapters/playdigo/playdigotest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 2,
"ext": {
"prebid": {
"type": "video"
Expand Down Expand Up @@ -115,6 +116,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 2,
"ext": {
"prebid": {
"type": "video"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 468,
"h": 60,
"ext": {
Expand Down Expand Up @@ -118,6 +119,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 1,
"w": 468,
"h": 60,
"ext": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}],
"expectedMakeBidsErrors": [
{
"value": "imp test-imp-id with unknown media type",
"value": "could not define media type for impression: test-imp-id",
"comparison": "literal"
}
]
Expand Down

0 comments on commit b7b5e64

Please sign in to comment.