Skip to content

Commit

Permalink
Yeahmobi: Fix video bug (prebid#3680)
Browse files Browse the repository at this point in the history
Co-authored-by: @lxj15398019970
  • Loading branch information
lxj15398019970 authored May 23, 2024
1 parent 93bf651 commit 72d040b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
34 changes: 24 additions & 10 deletions adapters/yeahmobi/yeahmobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
type adapter struct {
EndpointTemplate *template.Template
}
type yeahmobiBidExt struct {
VideoCreativeInfo *yeahmobiBidExtVideo `json:"video,omitempty"`
}
type yeahmobiBidExtVideo struct {
Duration *int `json:"duration,omitempty"`
}

// Builder builds a new instance of the Yeahmobi adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
Expand Down Expand Up @@ -134,34 +140,42 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest
if response.StatusCode == http.StatusNoContent {
return nil, nil
}

if response.StatusCode == http.StatusBadRequest {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}

if response.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}

var bidResp openrtb2.BidResponse

if err := json.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
var mediaType = getBidType(sb.Bid[i].ImpID, internalRequest.Imp)
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: mediaType,
})
bid := sb.Bid[i]
typedBid := &adapters.TypedBid{
Bid: &bid,
BidType: mediaType,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
}
if bid.Ext != nil {
var bidExt *yeahmobiBidExt
err := json.Unmarshal(bid.Ext, &bidExt)
if err != nil {
return nil, []error{fmt.Errorf("bid.ext json unmarshal error")}
} else if bidExt != nil {
if bidExt.VideoCreativeInfo != nil && bidExt.VideoCreativeInfo.Duration != nil {
typedBid.BidVideo.Duration = *bidExt.VideoCreativeInfo.Duration
}
}
}
bidResponse.Bids = append(bidResponse.Bids, typedBid)
}
}
return bidResponse, nil
Expand Down
41 changes: 28 additions & 13 deletions adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
}
]
},

"httpCalls": [
{
"expectedRequest": {
Expand All @@ -29,7 +28,7 @@
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"id": "test-imp-id",
"video": {
"w": 300,
"h": 250,
Expand All @@ -46,7 +45,9 @@
}
]
},
"impIDs":["test-imp-id"]
"impIDs": [
"test-imp-id"
]
},
"mockResponse": {
"status": 200,
Expand All @@ -55,21 +56,27 @@
"seatbid": [
{
"seat": "ttx",
"bid": [{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 1.2,
"adm": "some-ads",
"crid": "crid_testid"
}]
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 1.2,
"adm": "some-ads",
"crid": "crid_testid",
"ext": {
"video": {
"duration": 300
}
}
}
]
}
],
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
Expand All @@ -80,9 +87,17 @@
"impid": "test-imp-id",
"price": 1.2,
"adm": "some-ads",
"crid": "crid_testid"
"crid": "crid_testid",
"ext": {
"video": {
"duration": 300
}
}
},
"type": "video"
"type": "video",
"video": {
"duration": 300
}
}
]
}
Expand Down

0 comments on commit 72d040b

Please sign in to comment.