Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions adapters/optidigital/optidigital.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package optidigital

import (
"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 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,
}
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: http.MethodPost,
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 adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

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

var response openrtb2.BidResponse
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
Comment thread
ccorbo marked this conversation as resolved.
return nil, []error{&errortypes.BadServerResponse{
Message: "Bad Server Response",
}}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
bidResponse.Currency = response.Cur

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,
})
}
}
Comment on lines +62 to +69
Copy link
Copy Markdown
Collaborator

@przemkaczmarek przemkaczmarek May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's better to add code like this:

for _, seatBid := range response.SeatBid {
		for i, bid := range seatBid.Bid {
			bidType, err := getMediaTypeForBid(bid)
			if err != nil {
				return nil, []error{err}
			}

			b := &adapters.TypedBid{
				Bid:     &seatBid.Bid[i],
				BidType: bidType,
			}
			bidResponse.Bids = append(bidResponse.Bids, b)
		}
	}
	
	
func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
	switch bid.MType {
	case openrtb2.MarkupBanner:
		return openrtb_ext.BidTypeBanner, nil
	default:
		return "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID)
	}
} 

I know that right now you're only using "banner", but in the future You might want to change something, and this approach will make it easier.

return bidResponse, nil
}
21 changes: 21 additions & 0 deletions adapters/optidigital/optidigital_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
107 changes: 107 additions & 0 deletions adapters/optidigital/optidigitaltest/exemplary/banner.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
63 changes: 63 additions & 0 deletions adapters/optidigital/optidigitaltest/supplemental/bad_request.json
Original file line number Diff line number Diff line change
@@ -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",
"comparison": "startswith"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
57 changes: 57 additions & 0 deletions adapters/optidigital/optidigitaltest/supplemental/no_response.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
Loading
Loading