From 72d040b29703e868dc95a923f974bef652ae4e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=90=91=E5=86=9B?= <401154047@qq.com> Date: Thu, 23 May 2024 18:35:43 +0800 Subject: [PATCH] Yeahmobi: Fix video bug (#3680) Co-authored-by: @lxj15398019970 --- adapters/yeahmobi/yeahmobi.go | 34 ++++++++++----- .../yeahmobitest/exemplary/simple-video.json | 41 +++++++++++++------ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/adapters/yeahmobi/yeahmobi.go b/adapters/yeahmobi/yeahmobi.go index 6d351d85ebc..b533e76b19a 100644 --- a/adapters/yeahmobi/yeahmobi.go +++ b/adapters/yeahmobi/yeahmobi.go @@ -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) { @@ -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 diff --git a/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json b/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json index cda8ebe460f..af07de8f8bb 100644 --- a/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json +++ b/adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json @@ -20,7 +20,6 @@ } ] }, - "httpCalls": [ { "expectedRequest": { @@ -29,7 +28,7 @@ "id": "test-request-id", "imp": [ { - "id":"test-imp-id", + "id": "test-imp-id", "video": { "w": 300, "h": 250, @@ -46,7 +45,9 @@ } ] }, - "impIDs":["test-imp-id"] + "impIDs": [ + "test-imp-id" + ] }, "mockResponse": { "status": 200, @@ -55,13 +56,20 @@ "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" @@ -69,7 +77,6 @@ } } ], - "expectedBidResponses": [ { "currency": "USD", @@ -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 + } } ] }