Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
github-maxime-liege committed Sep 28, 2023
1 parent 0256b2a commit 664872b
Show file tree
Hide file tree
Showing 16 changed files with 1,048 additions and 37 deletions.
22 changes: 11 additions & 11 deletions adapters/teads/teads_types.go → adapters/teads/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ type adapter struct {
endpointTemplate *template.Template
}

type DefaultBidderImpExtension struct {
Bidder Bidder `json:"bidder"`
type defaultBidderImpExtension struct {
Bidder bidder `json:"bidder"`
}

type Bidder struct {
type bidder struct {
PlacementId int `json:"placementId"`
}

type TeadsImpExtension struct {
KV TeadsKV `json:"kv"`
type teadsImpExtension struct {
KV teadsKV `json:"kv"`
}

type TeadsKV struct {
type teadsKV struct {
PlacementId int `json:"placementId"`
}

type TeadsBidExt struct {
Prebid TeadsPrebidExt `json:"prebid"`
type teadsBidExt struct {
Prebid teadsPrebidExt `json:"prebid"`
}

type TeadsPrebidExt struct {
Meta TeadsPrebidMeta `json:"meta"`
type teadsPrebidExt struct {
Meta teadsPrebidMeta `json:"meta"`
}

type TeadsPrebidMeta struct {
type teadsPrebidMeta struct {
RendererName string `json:"rendererName"`
RendererVersion string `json:"rendererVersion"`
RendererData json.RawMessage `json:"rendererData"`
Expand Down
58 changes: 38 additions & 20 deletions adapters/teads/teads.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ func updateImpObject(imps []openrtb2.Imp) error {
}
}

var defaultImpExt DefaultBidderImpExtension
var defaultImpExt defaultBidderImpExtension
if err := json.Unmarshal(imp.Ext, &defaultImpExt); err != nil {
return &errortypes.BadInput{
Message: "Error parsing Imp.Ext object",
}
}
if defaultImpExt.Bidder.PlacementId == 0 {
return &errortypes.BadInput{
Message: "placementId should not be 0.",
}
}
imp.TagID = strconv.Itoa(defaultImpExt.Bidder.PlacementId)
teadsImpExt := &TeadsImpExtension{
KV: TeadsKV{
teadsImpExt := &teadsImpExtension{
KV: teadsKV{
PlacementId: defaultImpExt.Bidder.PlacementId,
},
}
Expand Down Expand Up @@ -120,34 +125,31 @@ func (a *adapter) buildEndpointURL() (string, error) {
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, _ *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
if adapters.IsResponseStatusCodeNoContent(response) {
return nil, nil
}
if response.StatusCode == http.StatusBadRequest {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}
if response.StatusCode != http.StatusOK {
return nil, []error{fmt.Errorf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode)}

err := adapters.CheckResponseStatusCodeForErrors(response)
if err != nil {
return nil, []error{err}
}

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

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid))
bidderResponse := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid))

for _, sb := range bidResp.SeatBid {
for i := 0; i < len(sb.Bid); i++ {
bid := sb.Bid[i]

var bidExtTeads TeadsBidExt
if err := json.Unmarshal(bid.Ext, &bidExtTeads); err != nil {
return nil, []error{err}
bidExtTeads, err := getTeadsRendererFromBidExt(bid.Ext)
if err != nil {
return nil, err
}
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidMeta: &openrtb_ext.ExtBidPrebidMeta{
RendererName: bidExtTeads.Prebid.Meta.RendererName,
Expand All @@ -158,18 +160,34 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, _ *adapters.Req
}
}
if bidResp.Cur != "" {
bidResponse.Currency = bidResp.Cur
bidderResponse.Currency = bidResp.Cur
}
return bidderResponse, nil
}

func getTeadsRendererFromBidExt(ext json.RawMessage) (*teadsBidExt, []error) {
var bidExtTeads teadsBidExt
if err := json.Unmarshal(ext, &bidExtTeads); err != nil {
return nil, []error{err}
}
if bidExtTeads.Prebid.Meta.RendererName == "" {
return nil, []error{&errortypes.BadInput{
Message: "RendererName should not be empty if present",
}}
}
if bidExtTeads.Prebid.Meta.RendererVersion == "" {
return nil, []error{&errortypes.BadInput{
Message: "RendererVersion should not be empty if present",
}}
}
return bidResponse, []error{}
return &bidExtTeads, nil
}

func getMediaTypeForImp(impID string, imps []openrtb2.Imp) openrtb_ext.BidType {
for _, imp := range imps {
if imp.ID == impID {
if imp.Video != nil {
return openrtb_ext.BidTypeVideo
} else if imp.Native != nil {
return openrtb_ext.BidTypeNative
}
return openrtb_ext.BidTypeBanner
}
Expand Down
4 changes: 2 additions & 2 deletions adapters/teads/teads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderTeads, config.Adapter{
Endpoint: "https://r.teads.tv/rich/"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
Endpoint: "https://a.teads.tv/prebid-server/bid-request"}, config.Server{ExternalUrl: "https://a.teads.tv/prebid-server/bid-request", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand All @@ -21,7 +21,7 @@ func TestJsonSamples(t *testing.T) {

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderTeads, config.Adapter{
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "https://a.teads.tv/prebid-server/bid-request", GvlID: 1, DataCenter: "2"})

assert.Error(t, buildErr)
}
168 changes: 168 additions & 0 deletions adapters/teads/teadstest/exemplary/simple-banner-with-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "b6321d41-3840-4cb3-baad-b6fc5b0c8553",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"placementId": 125
}
}
}
],
"ext": {
"prebid": {
"sdk": {
"renderers": [
{
"name": "teads",
"version": "5.0.25",
"data": {
"resize": true,
"sdkEngineVersion": "189"
}
}
]
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://a.teads.tv/prebid-server/bid-request",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "b6321d41-3840-4cb3-baad-b6fc5b0c8553",
"tagid": "125",
"banner": {
"w": 300,
"h": 250,
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"kv": {
"placementId": 125
}
}
}
],
"ext": {
"prebid": {
"sdk": {
"renderers": [
{
"name": "teads",
"version": "5.0.25",
"data": {
"resize": true,
"sdkEngineVersion": "189"
}
}
]
}
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "39312703-e970-4914-ae56-8e7d7d1fd16b",
"tagid": "125",
"seatbid": [
{
"seat": "teads",
"bid": [
{
"id": "695ac187-fb3f-4d1f-8d5d-099c5e4c4d28",
"impid": "b6321d41-3840-4cb3-baad-b6fc5b0c8553",
"price": 33,
"nurl": "https://localhost:8080/prebid-server/win-notice?data=base64&clearingPrice=${AUCTION_PRICE}",
"adm": "{\"settings\":{\"values\":{\"animations\":{\"expand\":0,\"collapse\":0.5},\"placementId\":2,\"adType\":\"video\",\"placementFormat\":\"inread\",\"allowedPlayer\":\"any\",\"pageId\":2},\"components\":{\"closeButton\":{\"display\":false,\"countdown\":0},\"credits\":{\"display\":false},\"soundButton\":{\"display\":true,\"countdown\":0,\"type\":\"equalizer\"},\"label\":{\"display\":false},\"slider\":{\"closeButtonDisplay\":false}},\"behaviors\":{\"smartPosition\":{\"top\":false,\"corner\":false,\"mustBypassWhitelist\":true},\"slider\":{\"enable\":false},\"friendly\":false,\"playerClick\":\"fullscreen\",\"soundStart\":{\"type\":\"mute\"},\"soundMute\":\"threshold\",\"soundOver\":\"over\",\"launch\":\"auto\",\"videoStart\":\"threshold\",\"videoPause\":\"threshold\",\"secure\":false}},\"ads\":[{\"settings\":{\"values\":{\"animations\":{\"expand\":0,\"collapse\":0.5},\"placementId\":2,\"adType\":\"video\",\"placementFormat\":\"inread\",\"allowedPlayer\":\"any\",\"pageId\":2},\"components\":{\"closeButton\":{\"display\":false,\"countdown\":0},\"credits\":{\"display\":false},\"soundButton\":{\"display\":true,\"countdown\":0,\"type\":\"equalizer\"},\"label\":{\"display\":false},\"slider\":{\"closeButtonDisplay\":false}},\"behaviors\":{\"smartPosition\":{\"top\":false,\"corner\":false,\"mustBypassWhitelist\":true},\"slider\":{\"enable\":false},\"friendly\":false,\"playerClick\":\"fullscreen\",\"soundStart\":{\"type\":\"mute\"},\"soundMute\":\"threshold\",\"soundOver\":\"over\",\"launch\":\"auto\",\"videoStart\":\"threshold\",\"videoPause\":\"threshold\",\"secure\":false}},\"type\":\"VastXml\",\"content\":\"<VAST version=\\\"3.0\\\"><Ad id=\\\"1\\\"><Wrapper><AdSystem>Teads Technology</AdSystem><VASTAdTagURI><![CDATA[http://vast.tv?auction_publisher_cost=LlBEcMjl2WSVYTIV0ZvZwFta&auction_publisher_cost_currency=USD&auction_ssb_provider_fee=&auction_ssb_provider_fee_currency=&auction_price=74Xz11zXoN9S_a18chCl1DB6&auction_currency=USD]]></VASTAdTagURI><Error><![CDATA[https://localhost:18281/track?action=error-vast&code=[ERRORCODE]&pid=2&vid=708ca808-ec55-4d97-ab81-9c4777e16058&pfid=971104812&mediaFileType=[MEDIAFILETYPE]&auctid=39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6&sid=0&scid=971105412&pscid=971105411&psid=971105457&hb_provider=prebid-server&hb_ad_unit_code=742d38c4-7994-4c2b-ac82-18d3a64ba3c7&dsp_campaign_id=1&dsp_creative_id=1&env=thirdparty-inapp&p=GmbtDz8E6SttqPqekGLm3vHN7muObx7-w6kGLgR8KMiWgUo78VfzNzYlcfjjRwTen7Oad6lYvgPUaiHwDV0lZcpu7lXO4Y7at1NIyIPxfcgdBw&cts=1685971107728&1685971107728]]></Error><Creatives></Creatives></Wrapper></Ad></VAST>\",\"scenario_id\":971105412,\"dsp_campaign_id\":\"1\",\"dsp_creative_id\":\"1\",\"insertion_id\":1,\"placement_id\":2,\"portfolio_item_id\":971104812}],\"wigoEnabled\":false,\"placementMetadata\":{\"2\":{\"adCallTrackingUrl\":\"https://localhost:18281/track?action=adCall&pid=2&pageId=2&auctid=39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6&vid=708ca808-ec55-4d97-ab81-9c4777e16058&hb_provider=prebid-server&hb_ad_unit_code=742d38c4-7994-4c2b-ac82-18d3a64ba3c7&env=thirdparty-inapp&gtc=1&gdpr_apply=false&gac=1&gap=1&ca=false&bsg=uncat&bsias=uncat&pfid=971104812&gid=1&brid=0&cid=1&rpm_reason=3&ut=1&p=5fwoPMJCquIB-txdmwQS0l79-hhHVnlTzyR9mmnBMtZRceP6-q31KzCfLpS8WTNaw_sXr-hkOFBxaxa-jyLblbVc&cts=1685971107773&cs=267268361555465193905\",\"auctionId\":\"39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6\"}},\"viewerId\":\"708ca808-ec55-4d97-ab81-9c4777e16058\"}",
"adid": "1",
"adomain": [
"teads.com"
],
"cid": "1",
"crid": "1",
"cat": [
"IAB1-6",
"IAB10-5"
],
"ext": {
"prebid": {
"meta": {
"rendererName": "teads",
"rendererVersion": "5.0.25",
"rendererData": {
"resize": true,
"sdkEngineVersion": "189"
}
}
}
}
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "695ac187-fb3f-4d1f-8d5d-099c5e4c4d28",
"impid": "b6321d41-3840-4cb3-baad-b6fc5b0c8553",
"price": 33,
"nurl": "https://localhost:8080/prebid-server/win-notice?data=base64&clearingPrice=${AUCTION_PRICE}",
"adm": "{\"settings\":{\"values\":{\"animations\":{\"expand\":0,\"collapse\":0.5},\"placementId\":2,\"adType\":\"video\",\"placementFormat\":\"inread\",\"allowedPlayer\":\"any\",\"pageId\":2},\"components\":{\"closeButton\":{\"display\":false,\"countdown\":0},\"credits\":{\"display\":false},\"soundButton\":{\"display\":true,\"countdown\":0,\"type\":\"equalizer\"},\"label\":{\"display\":false},\"slider\":{\"closeButtonDisplay\":false}},\"behaviors\":{\"smartPosition\":{\"top\":false,\"corner\":false,\"mustBypassWhitelist\":true},\"slider\":{\"enable\":false},\"friendly\":false,\"playerClick\":\"fullscreen\",\"soundStart\":{\"type\":\"mute\"},\"soundMute\":\"threshold\",\"soundOver\":\"over\",\"launch\":\"auto\",\"videoStart\":\"threshold\",\"videoPause\":\"threshold\",\"secure\":false}},\"ads\":[{\"settings\":{\"values\":{\"animations\":{\"expand\":0,\"collapse\":0.5},\"placementId\":2,\"adType\":\"video\",\"placementFormat\":\"inread\",\"allowedPlayer\":\"any\",\"pageId\":2},\"components\":{\"closeButton\":{\"display\":false,\"countdown\":0},\"credits\":{\"display\":false},\"soundButton\":{\"display\":true,\"countdown\":0,\"type\":\"equalizer\"},\"label\":{\"display\":false},\"slider\":{\"closeButtonDisplay\":false}},\"behaviors\":{\"smartPosition\":{\"top\":false,\"corner\":false,\"mustBypassWhitelist\":true},\"slider\":{\"enable\":false},\"friendly\":false,\"playerClick\":\"fullscreen\",\"soundStart\":{\"type\":\"mute\"},\"soundMute\":\"threshold\",\"soundOver\":\"over\",\"launch\":\"auto\",\"videoStart\":\"threshold\",\"videoPause\":\"threshold\",\"secure\":false}},\"type\":\"VastXml\",\"content\":\"<VAST version=\\\"3.0\\\"><Ad id=\\\"1\\\"><Wrapper><AdSystem>Teads Technology</AdSystem><VASTAdTagURI><![CDATA[http://vast.tv?auction_publisher_cost=LlBEcMjl2WSVYTIV0ZvZwFta&auction_publisher_cost_currency=USD&auction_ssb_provider_fee=&auction_ssb_provider_fee_currency=&auction_price=74Xz11zXoN9S_a18chCl1DB6&auction_currency=USD]]></VASTAdTagURI><Error><![CDATA[https://localhost:18281/track?action=error-vast&code=[ERRORCODE]&pid=2&vid=708ca808-ec55-4d97-ab81-9c4777e16058&pfid=971104812&mediaFileType=[MEDIAFILETYPE]&auctid=39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6&sid=0&scid=971105412&pscid=971105411&psid=971105457&hb_provider=prebid-server&hb_ad_unit_code=742d38c4-7994-4c2b-ac82-18d3a64ba3c7&dsp_campaign_id=1&dsp_creative_id=1&env=thirdparty-inapp&p=GmbtDz8E6SttqPqekGLm3vHN7muObx7-w6kGLgR8KMiWgUo78VfzNzYlcfjjRwTen7Oad6lYvgPUaiHwDV0lZcpu7lXO4Y7at1NIyIPxfcgdBw&cts=1685971107728&1685971107728]]></Error><Creatives></Creatives></Wrapper></Ad></VAST>\",\"scenario_id\":971105412,\"dsp_campaign_id\":\"1\",\"dsp_creative_id\":\"1\",\"insertion_id\":1,\"placement_id\":2,\"portfolio_item_id\":971104812}],\"wigoEnabled\":false,\"placementMetadata\":{\"2\":{\"adCallTrackingUrl\":\"https://localhost:18281/track?action=adCall&pid=2&pageId=2&auctid=39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6&vid=708ca808-ec55-4d97-ab81-9c4777e16058&hb_provider=prebid-server&hb_ad_unit_code=742d38c4-7994-4c2b-ac82-18d3a64ba3c7&env=thirdparty-inapp&gtc=1&gdpr_apply=false&gac=1&gap=1&ca=false&bsg=uncat&bsias=uncat&pfid=971104812&gid=1&brid=0&cid=1&rpm_reason=3&ut=1&p=5fwoPMJCquIB-txdmwQS0l79-hhHVnlTzyR9mmnBMtZRceP6-q31KzCfLpS8WTNaw_sXr-hkOFBxaxa-jyLblbVc&cts=1685971107773&cs=267268361555465193905\",\"auctionId\":\"39312703-e970-4914-ae56-8e7d7d1fd16b__b6321d41-3840-4cb3-baad-b6fc5b0c8553__c0f2e6ba-63d0-4e20-ab41-fe0822eb65a6\"}},\"viewerId\":\"708ca808-ec55-4d97-ab81-9c4777e16058\"}",
"adid": "1",
"adomain": [
"teads.com"
],
"cid": "1",
"crid": "1",
"cat": [
"IAB1-6",
"IAB10-5"
],
"ext": {
"prebid": {
"meta": {
"rendererName": "teads",
"rendererVersion": "5.0.25",
"rendererData": {
"resize": true,
"sdkEngineVersion": "189"
}
}
}
}
},
"type": "banner"
}
]
}
]
}
2 changes: 1 addition & 1 deletion adapters/teads/teadstest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://r.teads.tv/rich/",
"uri": "https://a.teads.tv/prebid-server/bid-request",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/teads/teadstest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://r.teads.tv/rich/",
"uri": "https://a.teads.tv/prebid-server/bid-request",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Loading

0 comments on commit 664872b

Please sign in to comment.