From 2d621eb233af83e82b550f1d8f0305b308fe0d4d Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Mon, 31 Mar 2025 09:42:39 +0200 Subject: [PATCH 1/8] optidigital adapter --- adapters/optidigital/optidigital.go | 79 +++++++++++++ adapters/optidigital/optidigital_test.go | 21 ++++ .../optidigitaltest/exemplary/banner.json | 107 ++++++++++++++++++ .../supplemental/bad_request.json | 63 +++++++++++ .../supplemental/no_response.json | 57 ++++++++++ .../supplemental/other_error.json | 63 +++++++++++ exchange/adapter_builders.go | 2 + openrtb_ext/bidders.go | 2 + openrtb_ext/imp_optidigital.go | 7 ++ static/bidder-info/optidigital.yaml | 23 ++++ static/bidder-params/optidigital.json | 26 +++++ 11 files changed, 450 insertions(+) create mode 100644 adapters/optidigital/optidigital.go create mode 100644 adapters/optidigital/optidigital_test.go create mode 100644 adapters/optidigital/optidigitaltest/exemplary/banner.json create mode 100644 adapters/optidigital/optidigitaltest/supplemental/bad_request.json create mode 100644 adapters/optidigital/optidigitaltest/supplemental/no_response.json create mode 100644 adapters/optidigital/optidigitaltest/supplemental/other_error.json create mode 100644 openrtb_ext/imp_optidigital.go create mode 100644 static/bidder-info/optidigital.yaml create mode 100644 static/bidder-params/optidigital.json diff --git a/adapters/optidigital/optidigital.go b/adapters/optidigital/optidigital.go new file mode 100644 index 00000000000..f152cec9e56 --- /dev/null +++ b/adapters/optidigital/optidigital.go @@ -0,0 +1,79 @@ +package optidigital + +import ( + "fmt" + "net/http" + + "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v3/adapters" + "github.com/prebid/prebid-server/v3/config" + "github.com/prebid/prebid-server/v3/errortypes" + "github.com/prebid/prebid-server/v3/openrtb_ext" + "github.com/prebid/prebid-server/v3/util/jsonutil" +) + +type adapter struct { + endpoint string +} + +// Builder builds a new instance of the {bidder} adapter for the given bidder with the given config. +func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { + bidder := &adapter{ + endpoint: config.Endpoint, + } + return bidder, nil +} + +func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + requestJSON, err := jsonutil.Marshal(request) + if err != nil { + return nil, []error{err} + } + + requestData := &adapters.RequestData{ + Method: "POST", + Uri: a.endpoint, + Body: requestJSON, + ImpIDs: openrtb_ext.GetImpIDs(request.Imp), + } + + return []*adapters.RequestData{requestData}, nil +} + +func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if responseData.StatusCode == http.StatusNoContent { + return nil, nil + } + + if responseData.StatusCode == http.StatusBadRequest { + err := &errortypes.BadInput{ + Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + } + return nil, []error{err} + } + + if responseData.StatusCode != http.StatusOK { + err := &errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), + } + return nil, []error{err} + } + + var response openrtb2.BidResponse + if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil { + return nil, []error{err} + } + + bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) + bidResponse.Currency = response.Cur + var errors []error + for _, seatBid := range response.SeatBid { + for i := range seatBid.Bid { + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ + Bid: &seatBid.Bid[i], + BidType: openrtb_ext.BidTypeBanner, + }) + } + } + return bidResponse, errors +} diff --git a/adapters/optidigital/optidigital_test.go b/adapters/optidigital/optidigital_test.go new file mode 100644 index 00000000000..dda8b09b549 --- /dev/null +++ b/adapters/optidigital/optidigital_test.go @@ -0,0 +1,21 @@ +package optidigital + +import ( + "testing" + + "github.com/prebid/prebid-server/v3/adapters/adapterstest" + "github.com/prebid/prebid-server/v3/config" + "github.com/prebid/prebid-server/v3/openrtb_ext" +) + +func TestJsonSamples(t *testing.T) { + bidder, buildErr := Builder(openrtb_ext.BidderOptidigital, config.Adapter{ + Endpoint: "https://pbs.optidigital.com/bidder/openrtb2", + }, config.Server{}) + + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } + + adapterstest.RunJSONBidderTest(t, "optidigitaltest", bidder) +} diff --git a/adapters/optidigital/optidigitaltest/exemplary/banner.json b/adapters/optidigital/optidigitaltest/exemplary/banner.json new file mode 100644 index 00000000000..fa6c90fe378 --- /dev/null +++ b/adapters/optidigital/optidigitaltest/exemplary/banner.json @@ -0,0 +1,107 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://pbs.optidigital.com/bidder/openrtb2", + "body": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "impIDs": ["imp-id"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "request-id", + "seatbid": [ + { + "seat": "958", + "bid": [ + { + "id": "bid-id", + "impid": "imp-id", + "price": 0.5, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": [ + "foo.com" + ], + "crid": "29681110", + "h": 250, + "w": 300, + "dealid": "test deal" + } + ] + } + ], + "bidid": "request-id", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "bid-id", + "impid": "imp-id", + "price": 0.5, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": [ + "foo.com" + ], + "crid": "29681110", + "w": 300, + "h": 250, + "dealid": "test deal" + }, + "type": "banner" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/optidigital/optidigitaltest/supplemental/bad_request.json b/adapters/optidigital/optidigitaltest/supplemental/bad_request.json new file mode 100644 index 00000000000..9bc9fab1fc4 --- /dev/null +++ b/adapters/optidigital/optidigitaltest/supplemental/bad_request.json @@ -0,0 +1,63 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://pbs.optidigital.com/bidder/openrtb2", + "body": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "impIDs": ["imp-id"] + }, + "mockResponse": { + "status": 400 + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/adapters/optidigital/optidigitaltest/supplemental/no_response.json b/adapters/optidigital/optidigitaltest/supplemental/no_response.json new file mode 100644 index 00000000000..84de5fb48ce --- /dev/null +++ b/adapters/optidigital/optidigitaltest/supplemental/no_response.json @@ -0,0 +1,57 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://pbs.optidigital.com/bidder/openrtb2", + "body": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "impIDs": ["imp-id"] + }, + "mockResponse": { + "status": 204 + } + } + ] +} \ No newline at end of file diff --git a/adapters/optidigital/optidigitaltest/supplemental/other_error.json b/adapters/optidigital/optidigitaltest/supplemental/other_error.json new file mode 100644 index 00000000000..d14defbe962 --- /dev/null +++ b/adapters/optidigital/optidigitaltest/supplemental/other_error.json @@ -0,0 +1,63 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://pbs.optidigital.com/bidder/openrtb2", + "body": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "impIDs": ["imp-id"] + }, + "mockResponse": { + "status": 500 + } + } + ], + "expectedMakeBidsErrors": [ + { + "value": "Unexpected status code: 500. Run with request.debug = 1 for more info.", + "comparison": "literal" + } + ] +} \ No newline at end of file diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index 7647de71786..b1a40cb3726 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -163,6 +163,7 @@ import ( "github.com/prebid/prebid-server/v3/adapters/openweb" "github.com/prebid/prebid-server/v3/adapters/openx" "github.com/prebid/prebid-server/v3/adapters/operaads" + "github.com/prebid/prebid-server/v3/adapters/optidigital" "github.com/prebid/prebid-server/v3/adapters/oraki" "github.com/prebid/prebid-server/v3/adapters/orbidder" "github.com/prebid/prebid-server/v3/adapters/outbrain" @@ -413,6 +414,7 @@ func newAdapterBuilders() map[openrtb_ext.BidderName]adapters.Builder { openrtb_ext.BidderOpenWeb: openweb.Builder, openrtb_ext.BidderOpenx: openx.Builder, openrtb_ext.BidderOperaads: operaads.Builder, + openrtb_ext.BidderOptidigital: optidigital.Builder, openrtb_ext.BidderOraki: oraki.Builder, openrtb_ext.BidderOrbidder: orbidder.Builder, openrtb_ext.BidderOutbrain: outbrain.Builder, diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 10755dfd7fd..1c30c22b486 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -181,6 +181,7 @@ var coreBidderNames []BidderName = []BidderName{ BidderOpenWeb, BidderOpenx, BidderOperaads, + BidderOptidigital, BidderOraki, BidderOrbidder, BidderOutbrain, @@ -535,6 +536,7 @@ const ( BidderOpenWeb BidderName = "openweb" BidderOpenx BidderName = "openx" BidderOperaads BidderName = "operaads" + BidderOptidigital BidderName = "optidigital" BidderOraki BidderName = "oraki" BidderOrbidder BidderName = "orbidder" BidderOutbrain BidderName = "outbrain" diff --git a/openrtb_ext/imp_optidigital.go b/openrtb_ext/imp_optidigital.go new file mode 100644 index 00000000000..c473726dea9 --- /dev/null +++ b/openrtb_ext/imp_optidigital.go @@ -0,0 +1,7 @@ +package openrtb_ext + +type ImpExtOptidigital struct { + PublisherID string `json:"publisherId"` + PageTemplate string `json:"pageTemplate"` + PlacementID string `json:"placementId"` +} diff --git a/static/bidder-info/optidigital.yaml b/static/bidder-info/optidigital.yaml new file mode 100644 index 00000000000..4490bf70d03 --- /dev/null +++ b/static/bidder-info/optidigital.yaml @@ -0,0 +1,23 @@ +endpoint: "https://pbs.optidigital.com/bidder/openrtb2" +endpointCompression: gzip +maintainer: + email: prebid@optidigital.com +gvlVendorID: 915 +openrtb: + version: 2.6 +capabilities: + app: + mediaTypes: + - banner + site: + mediaTypes: + - banner + dooh: + mediaTypes: + - banner +userSync: + supports: + - iframe + iframe: + url: https://scripts.opti-digital.com/js/presyncs2s.html?endpoint=optidigital&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir={{.RedirectURL}} + userMacro: $UID \ No newline at end of file diff --git a/static/bidder-params/optidigital.json b/static/bidder-params/optidigital.json new file mode 100644 index 00000000000..75e12323df3 --- /dev/null +++ b/static/bidder-params/optidigital.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Optidigital Adapter Params", + "description": "A schema which validates params accepted by the Optidigital adapter", + "type": "object", + + "properties": { + "publisherId": { + "type": "string", + "description": "Publisher ID" + }, + "placementId": { + "type": "string", + "description": "Placement ID" + }, + "pageTemplate": { + "type": "string", + "description": "Page Template" + } + }, + + "required":[ + "publisherId", + "placementId" + ] + } \ No newline at end of file From 397502772ec4784fff683739d27c974f213b562b Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Tue, 1 Apr 2025 16:39:34 +0200 Subject: [PATCH 2/8] add `divId` parameter as optional --- openrtb_ext/imp_optidigital.go | 3 ++- static/bidder-params/optidigital.json | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/openrtb_ext/imp_optidigital.go b/openrtb_ext/imp_optidigital.go index c473726dea9..e34280c588b 100644 --- a/openrtb_ext/imp_optidigital.go +++ b/openrtb_ext/imp_optidigital.go @@ -2,6 +2,7 @@ package openrtb_ext type ImpExtOptidigital struct { PublisherID string `json:"publisherId"` - PageTemplate string `json:"pageTemplate"` PlacementID string `json:"placementId"` + PageTemplate string `json:"pageTemplate,omitempty"` + DivID string `json:"divId,omitempty"` } diff --git a/static/bidder-params/optidigital.json b/static/bidder-params/optidigital.json index 75e12323df3..27ab4f29ca4 100644 --- a/static/bidder-params/optidigital.json +++ b/static/bidder-params/optidigital.json @@ -13,6 +13,10 @@ "type": "string", "description": "Placement ID" }, + "divId": { + "type": "string", + "description": "Div ID" + }, "pageTemplate": { "type": "string", "description": "Page Template" From 90b249d4b3564f9e13d0d1ca63ac3190e50fe99c Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Tue, 1 Apr 2025 17:16:00 +0200 Subject: [PATCH 3/8] protect strings in yaml just-in-case --- static/bidder-info/optidigital.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/bidder-info/optidigital.yaml b/static/bidder-info/optidigital.yaml index 4490bf70d03..b0df8a5ef85 100644 --- a/static/bidder-info/optidigital.yaml +++ b/static/bidder-info/optidigital.yaml @@ -1,7 +1,7 @@ endpoint: "https://pbs.optidigital.com/bidder/openrtb2" endpointCompression: gzip maintainer: - email: prebid@optidigital.com + email: "prebid@optidigital.com" gvlVendorID: 915 openrtb: version: 2.6 @@ -19,5 +19,5 @@ userSync: supports: - iframe iframe: - url: https://scripts.opti-digital.com/js/presyncs2s.html?endpoint=optidigital&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir={{.RedirectURL}} - userMacro: $UID \ No newline at end of file + url: "https://scripts.opti-digital.com/js/presyncs2s.html?endpoint=optidigital&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redir={{.RedirectURL}}" + userMacro: "$UID" \ No newline at end of file From 67d0194a3f851caff417808235f4813bcc26770b Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Tue, 1 Apr 2025 17:20:26 +0200 Subject: [PATCH 4/8] remove un-used errors slide --- adapters/optidigital/optidigital.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapters/optidigital/optidigital.go b/adapters/optidigital/optidigital.go index f152cec9e56..f8abbfba34a 100644 --- a/adapters/optidigital/optidigital.go +++ b/adapters/optidigital/optidigital.go @@ -66,7 +66,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) bidResponse.Currency = response.Cur - var errors []error + for _, seatBid := range response.SeatBid { for i := range seatBid.Bid { bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ @@ -75,5 +75,5 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R }) } } - return bidResponse, errors + return bidResponse, nil } From 46598d0990624df93d4bc690551d6defabaaf5e0 Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Wed, 2 Apr 2025 15:20:31 +0200 Subject: [PATCH 5/8] validate params --- adapters/optidigital/params_test.go | 62 +++++++++++++++++++++++++++ static/bidder-params/optidigital.json | 2 + 2 files changed, 64 insertions(+) create mode 100644 adapters/optidigital/params_test.go diff --git a/adapters/optidigital/params_test.go b/adapters/optidigital/params_test.go new file mode 100644 index 00000000000..5c29d9796dd --- /dev/null +++ b/adapters/optidigital/params_test.go @@ -0,0 +1,62 @@ +package optidigital + +import ( + "encoding/json" + "testing" + + "github.com/prebid/prebid-server/v3/openrtb_ext" +) + +// This file actually intends to test static/bidder-params/optidigital.json +// +// These also validate the format of the external API: request.imp[i].ext.prebid.bidder.optidigital + +// TestValidParams makes sure that the optidigital schema accepts all imp.ext fields which we intend to support. +func TestValidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, validParam := range validParams { + if err := validator.Validate(openrtb_ext.BidderOptidigital, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected optidigital params: %s \n Error: %s", validParam, err) + } + } +} + +// TestInvalidParams makes sure that the optidigital schema rejects all the imp.ext fields we don't support. +func TestInvalidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, invalidParam := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderOptidigital, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema allowed unexpected params: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"publisherId":"p123","placementId":"foo-placement"}`, + `{"publisherId":"p123","placementId":"foo-placement","divId":""}`, + `{"publisherId":"p123","placementId":"foo-placement","divId":"foo-div"}`, + `{"publisherId":"p123","placementId":"foo-placement","divId":"foo-div","pageTemplate":""}`, + `{"publisherId":"p123","placementId":"foo-placement","divId":"foo-div","pageTemplate":"foo-page-template"}`, +} + +var invalidParams = []string{ + ``, + `null`, + `true`, + `5`, + `4.2`, + `[]`, + `{}`, + `{"publisherId":""}`, + `{"publisherId":"p123","placementId":""}`, + `{"publisherId":"","placementId":"foo-placement"}`, + `{"publisherId":"p","placementId":"foo-placement"}`, +} diff --git a/static/bidder-params/optidigital.json b/static/bidder-params/optidigital.json index 27ab4f29ca4..6d4a04b3502 100644 --- a/static/bidder-params/optidigital.json +++ b/static/bidder-params/optidigital.json @@ -7,10 +7,12 @@ "properties": { "publisherId": { "type": "string", + "minLength": 2, "description": "Publisher ID" }, "placementId": { "type": "string", + "minLength": 1, "description": "Placement ID" }, "divId": { From 5f665898fec86d6151010c7fca713b12ebb9b164 Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Wed, 2 Apr 2025 15:45:40 +0200 Subject: [PATCH 6/8] [skip ci] fix comment --- adapters/optidigital/optidigital.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/optidigital/optidigital.go b/adapters/optidigital/optidigital.go index f8abbfba34a..575ddf237f1 100644 --- a/adapters/optidigital/optidigital.go +++ b/adapters/optidigital/optidigital.go @@ -16,7 +16,7 @@ type adapter struct { endpoint string } -// Builder builds a new instance of the {bidder} adapter for the given bidder with the given config. +// Builder builds a new instance of the optidigital adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { bidder := &adapter{ endpoint: config.Endpoint, From cee3787d25a5e88cd99c1d8eb7f2195331fb8310 Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Mon, 14 Apr 2025 08:38:37 +0200 Subject: [PATCH 7/8] normalize checks --- adapters/optidigital/optidigital.go | 22 ++++++------------- .../supplemental/bad_request.json | 4 ++-- .../supplemental/other_error.json | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/adapters/optidigital/optidigital.go b/adapters/optidigital/optidigital.go index 575ddf237f1..89e2474d977 100644 --- a/adapters/optidigital/optidigital.go +++ b/adapters/optidigital/optidigital.go @@ -1,7 +1,6 @@ package optidigital import ( - "fmt" "net/http" "github.com/prebid/openrtb/v20/openrtb2" @@ -31,7 +30,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte } requestData := &adapters.RequestData{ - Method: "POST", + Method: http.MethodPost, Uri: a.endpoint, Body: requestJSON, ImpIDs: openrtb_ext.GetImpIDs(request.Imp), @@ -41,27 +40,20 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte } func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { - if responseData.StatusCode == http.StatusNoContent { - return nil, nil - } - if responseData.StatusCode == http.StatusBadRequest { - err := &errortypes.BadInput{ - Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", - } - return nil, []error{err} + if adapters.IsResponseStatusCodeNoContent(responseData) { + return nil, nil } - if responseData.StatusCode != http.StatusOK { - err := &errortypes.BadServerResponse{ - Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), - } + if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { return nil, []error{err} } var response openrtb2.BidResponse if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil { - return nil, []error{err} + return nil, []error{&errortypes.BadServerResponse{ + Message: "Bad Server Response", + }} } bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) diff --git a/adapters/optidigital/optidigitaltest/supplemental/bad_request.json b/adapters/optidigital/optidigitaltest/supplemental/bad_request.json index 9bc9fab1fc4..9ac0c5f4f7e 100644 --- a/adapters/optidigital/optidigitaltest/supplemental/bad_request.json +++ b/adapters/optidigital/optidigitaltest/supplemental/bad_request.json @@ -56,8 +56,8 @@ ], "expectedMakeBidsErrors": [ { - "value": "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", - "comparison": "literal" + "value": "Unexpected status code: 400", + "comparison": "startswith" } ] } \ No newline at end of file diff --git a/adapters/optidigital/optidigitaltest/supplemental/other_error.json b/adapters/optidigital/optidigitaltest/supplemental/other_error.json index d14defbe962..3cc17d63d36 100644 --- a/adapters/optidigital/optidigitaltest/supplemental/other_error.json +++ b/adapters/optidigital/optidigitaltest/supplemental/other_error.json @@ -56,8 +56,8 @@ ], "expectedMakeBidsErrors": [ { - "value": "Unexpected status code: 500. Run with request.debug = 1 for more info.", - "comparison": "literal" + "value": "Unexpected status code: 500", + "comparison": "startswith" } ] } \ No newline at end of file From 05463ca311a42e52248173d583418ab1cbfdaf41 Mon Sep 17 00:00:00 2001 From: Victor Gonzalez Date: Mon, 14 Apr 2025 08:38:57 +0200 Subject: [PATCH 8/8] add bad_response test case --- .../supplemental/bad_response.json | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 adapters/optidigital/optidigitaltest/supplemental/bad_response.json diff --git a/adapters/optidigital/optidigitaltest/supplemental/bad_response.json b/adapters/optidigital/optidigitaltest/supplemental/bad_response.json new file mode 100644 index 00000000000..c60d0e3b00d --- /dev/null +++ b/adapters/optidigital/optidigitaltest/supplemental/bad_response.json @@ -0,0 +1,65 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://pbs.optidigital.com/bidder/openrtb2", + "body": { + "id": "request-id", + "imp": [ + { + "id": "imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "p123", + "placementId": "my-placement-id" + } + } + } + ] + }, + "impIDs": ["imp-id"] + }, + "mockResponse": { + "status": 200, + "body": "invalid response" + } + } + ], + + "expectedMakeBidsErrors": [ + { + "value": "Bad Server Response", + "comparison": "literal" + } + ] +} \ No newline at end of file