Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Adapter: AIDEM #2824

Merged
merged 10 commits into from
Jul 5, 2023
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
102 changes: 102 additions & 0 deletions adapters/aidem/aidem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package aidem

import (
"encoding/json"
"fmt"
"net/http"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

type adapter struct {
endpoint string
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {

reqJson, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")

return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Body: reqJson,
Headers: headers,
}}, nil
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var errs []error

if adapters.IsResponseStatusCodeNoContent(response) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(response); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}

var bidResp openrtb2.BidResponse
if err := json.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("JSON parsing error: %v", err),
}}
}

if len(bidResp.SeatBid) == 0 {
return nil, []error{&errortypes.BadServerResponse{
Message: "Empty SeatBid array",
}}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid[0].Bid))
gsollazzo marked this conversation as resolved.
Show resolved Hide resolved

for _, seatBid := range bidResp.SeatBid {
for i := range seatBid.Bid {
bidType, err := getMediaTypeForBid(seatBid.Bid[i])
if err != nil {
errs = append(errs, err)
} else {
b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
BidType: bidType,
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
}
}
return bidResponse, errs
}

// Builder builds a new instance of the AIDEM adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
return &adapter{
endpoint: config.Endpoint,
}, nil
}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
default:
return "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID)
}
gargcreation1992 marked this conversation as resolved.
Show resolved Hide resolved
}
30 changes: 30 additions & 0 deletions adapters/aidem/aidem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package aidem

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAidem, config.Adapter{
Endpoint: "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "aidemtest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAidem, config.Adapter{
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

assert.Nil(t, buildErr)
}
119 changes: 119 additions & 0 deletions adapters/aidem/aidemtest/exemplary/multi-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 320,
"h": 50
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 320,
"h": 480
},
"ext": {
"bidder": {
"siteId": "TCID",
"publisherId": "1234"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 320,
"h": 50
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 320,
"h": 480
},
"ext": {
"bidder": {
"siteId": "TCID",
"publisherId": "1234"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "aax",
"bid": [
{
"id": "test-bid-id",
"impid": "1",
"price": 1.50,
"adm": "some-test-ad",
"crid": "test-crid",
"h": 50,
"w": 320,
"mtype": 1
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "1",
"price": 1.50,
"adm": "some-test-ad",
"crid": "test-crid",
"w": 320,
"h": 50,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Loading
Loading